How to add Paypal Classic as a payment provider
PayPal is a digital payments platform that enables users to make online payments.
Prerequisites
- Add PayPal as a payment provider through the Admin tool.
Checkout flow
Unlike other payment providers, such as Stripe Intents, PayPal requires the user to be redirected to the PayPal page, where they must confirm the payment. The PayPal checkout workflow follows the steps defined on Checkout to purchase a subscription. The code provided below is explained according to the regular checkout flow.
Regardless of the payment provider, Steps 1
to 5
(Authenticate, Get products and prices, Add item(s) to cart, Create order and Get payment options) are exactly the same as described on Checkout to purchase a subscription. See How to add Stripe Intents as a payment provider for implementation details.
-
Authenticate
. -
Get products and prices
. -
Add item(s) to cart
. -
Create order
. -
Get payment options
. -
Initialize payment
: On the previous step, you can identify payment methods set up for PayPal by checking if they have paymentMethodType: 10. For each element returned, you will see a paymentMethodID, this value, together with the orden number are required when callingSales.initializePayment()
.If successful,
Sales.initializePayment()
will return a URL in parameter1. The end user needs to be redirect to that page.const orderNumber = Sales.currentOrder.orderNumber;const paymentProvider = chosenPaymentOption; // chosen by the user with paymentMethodType: 10,...const payment = await Sales.initializePayment(orderNumber, paymentProvider.paymentMethodID);window.location.href = payment["parameter1"];Once the user is logged into their PayPal account and agrees to the payment, if the payment is confirmed on the PayPal side, the user will be redirected to the Return URL defined on settings, along with a token (e.g.
{returnURL}?token=EC-6UK47484PR908XXXX
). -
Finalize payment
: Since the end user is redirected to an external site, you need to make sure you store the reCAPTCHA token (if this features is enabled for checkout) and the orderNumber in the user’s browser. This information should be grabbed to be passed along with the token when callingSales.finalizePayment()