13

I am trying to build a very simple paypal-backed shopping cart so users can purchase multiple items. I want paypal to handle all the payment details. I don't even want an order confirmation. I will manually check for order confirmation on paypal.

At first I wanted to use "Website Payments Standard" because it seemed easy to create a form that will post to paypal and let paypal handle it from there. But no, this did not work because the "Website Payments Standard" buttons/form do not support submitting multiple items. I tried all sorts of key/value in my form, and it never worked.

Then I tried Express Checkout using the instructions found here. It largely worked, but as I understand it, after sending a SetExpressCheckout, you have to listen for a request from paypal and do a DoExpressCheckoutPayment to complete the transaction. SO reference.

I find this a bit troublesome, because what if my server fails to receive the request from paypal and I never send a DoExpressCheckoutPayment? So a customer THINKS they have finished submitting an order, but the order was never received.

Does anyone know of a way to skip this "confirmation" step? I find it unnecessary, and not sure why paypal requires it.

Community
  • 1
  • 1
vinhboy
  • 8,542
  • 7
  • 34
  • 44
  • Technically `DoExpressCheckoutPayment` is only required (or even available) for the Express Checkout and Website Payments Pro API. – Kenny Evitt Jul 19 '12 at 16:14

2 Answers2

44

That's because Express Checkout and Website Payments Standard are fundamentally different products.

To use Express Checkout, you would call the SetExpressCheckout API. In the API call, you specify the details of the products, amounts, and the RETURNURL.
Once you post this data to PayPal's API endpoint, you receive a token in return. You would then redirect the buyer, and append the token to the following URL: https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-XXXXXXX

Once the buyer has agreed to your purchase, he is redirected back to the URL you specified in the RETURNURL.
You should now show the order confirmation, and call the GetExpressCheckoutDetails API**.
When calling GetExpressCheckoutDetails, supply the token. In the GetExpressCheckoutDetails API response you'll find a PayerID.

Now you're ready to call DoExpressCheckoutPayment, and charge the buyer. Remember to include both the token and the payerID when calling DoExpressCheckoutPayment.

Note: If you want to charge the buyer immediately by calling GetExpressCheckoutDetails and DoExpressCheckoutPayment immediately, redirect the buyer to https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-XXXXXXX&useraction=commit. The useraction=commit will change the "Continue" button on the PayPal 'Review your payment' page to a "Pay now" button.

--

The reason there's such a significant difference between Express Checkout and Website Payments Standard, is that Website Payments Standard is intended to be a drop-in working solution where PayPal handles the whole transaction flow. Express Checkout is a more flexible solution which allows you to integrate it deeply with an existing checkout flow of a website / shopping cart.

For your use case; lookat using PayPal 'cart upload' buttons. See for an example https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_cart_upload

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="seller@designerfotos.com">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="submit" value="PayPal">
</form> 

Note however, that this is insecure by default, as the amounts you're going to charge will be plainly visible in the HTML.

** The PayerID is appended in the GET of your RETURNURL as well. So you could skip calling GetExpressCheckoutDetails if you wanted to.

Robert
  • 19,326
  • 3
  • 58
  • 59
  • Thank you for the detailed response. However, I never equated Website Payments Standard to Express Checkout. If I did, it would be a mistake. My main question is why does paypal require DoExpressCheckoutPayment, it seems unnecessary and misleading since a user has already completed payment. However, your example Website Payments Standard form for multiple items worked, which is all I really wanted to begin with (however it still does not answer this question). Once again. Thank you! – vinhboy Nov 02 '11 at 20:04
  • 3
    I know you didn't; but it answers your question why DoExpressCheckoutPayment is required. :-) It's the nature of the beast. Express Checkout is intended as an inbetween payment solution, sitting between your cart and an order confirmation page. Hence why DoExpressCheckoutPayment is required to finalize the payment; this allows a merchant greater flexibility on when, how and where to charge a buyer rather than the buyer being charged immediately on the PayPal website itself. The actual payment isn't completed once the buyer has *agreed to the payment*. It's only finalized after DoEC is called. – Robert Nov 02 '11 at 20:06
  • 1
    Is there any official documentation on `useraction=commit`? – panzi Oct 17 '13 at 17:59
  • 2
    Got it: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing#id0864860D0YK – panzi Oct 17 '13 at 18:56
  • @panzi interested if you got there? I am searching for hours... Thanks! – user492238 Jul 25 '14 at 18:29
  • @user492238 I don't know anymore how I've found that back in October. (That was what you asked, or was it?) – panzi Jul 25 '14 at 19:13
  • @panzi yes, more of a rhetoric question. I find the pp docs somehow hard to get the overview from. thanks again – user492238 Jul 26 '14 at 09:40
3

For the purposes of this site, the DoExpressCheckoutPayment operation simply is required by the PayPal Express Checkout API.

You're correct that it's not required for PayPal to process a payment, but there are scenarios that would require a second operation. An example of such a scenario would be one where the user (your site's customer) is choosing a shipping address during the PayPal payment confirmation. Depending on your shipping provider(s), you may need to calculate actual shipping amounts after the user has chosen a shipping address on the PayPal confirmation pages.

Kenny Evitt
  • 9,291
  • 5
  • 65
  • 93