We still use checkout.js to implement the Paypal express checkout. The steps there are:
Now we want to migrate to the JavaScript SDK. According to this: https://developer.paypal.com/docs/checkout/standard/upgrade-integration/ the steps are now:
For legal reasons, we need Paypal to redirect the user back to the shop where he can click "buy now", like it's done with checkout.js. How can we implement these 6 steps with the Paypal JavaScript SDK instead of 4? I couldn't find any examples doing so.
Executing is v1/payments and checkout.js terminology; with the current JS SDK and v2/checkout/orders it's called "capturing" instead.
The user clicking "Pay now" does not immediately capture the payment on PayPal's end, rather, it calls the onApprove
function you provide to do the capture. That function can first show any message you need it to show, including updating the DOM of the page with the final confirmation information -- or, if you must, using JS to redirect away to a new confirmation page.
When the final Pay confirmation is given, what you need to do is capture the payment, using actions.order.capture (client-side) or a server-side API call.
[A server-side integration is always recommended, and in that case the createOrder
function should also be calling a server route...see the code demo]
Finally, a verbiage change is necessary to show the correct button text when there is going to be a confirmation step. By default with the JS SDK the final button within the PayPal approval flow says "Pay now". If you are going to have a confirmation message and required user action before capturing, that button needs to change to say "Continue" to indicate you're requiring an additional step. To change it, include the query string parameter &commit=false
on the SDK line. In addition to the query string, any server-side API call to create an order must set "user_action": "CONTINUE"
in the application_context
object. (note that this object belongs in the top hierarchy of the create order request JSON, not inside a purchase_unit)