PayPal
See example of integrating Paypal.
Introduction
The integration with PayPal supports both in-checkout and post-checkout payment approaches. To learn about the details, see the PayPal Commerce Platform Gateway Guide documentation.
In-checkout flow
Payment done during the checkout requires an https://api.emporix.io/checkout/{TENANT}/checkouts/orders
POST
request, with the paymentMethods
field including the following information:
provider
- Should always be set to payment-gateway.method
- Reflects one of the payment mode codes, depending on the method that you want to choose. You can see the list of available modes after sending theGET
request:https://api.emporix.io/payment-gateway/{TENANT}/paymentmodes/frontend
.customAttributes
- It's a set of attributes specific for the particular payment mode.token
- Credit card token for a tokenized approach.modeId
- Payment mode identifier, the ID should reflect the payment mode ID that you receive fromGET
:https://api.emporix.io/payment-gateway/{TENANT}/paymentmodes/frontend
.customer
- Identifier of a customer that does the checkout and payment.
With this flow, the payment authorization is done during the checkout process. The response to the checkout request contains the paymentDetails
object:
The externalPaymentRedirectURL
field is populated only in case when a redirect is required. The URL is used to navigate the user in order to finish the payment process.
When the user finishes the whole flow on the PayPal side, the Emporix payment gateway is notified about the result of the operation by a callback. It may take around one minute as this is an asynchronous operation.
The diagram shows how PayPal sequence looks like when it's integrated with Emporix for the in-checkout flow:
Post-checkout flow
The post-checkout approach assumes that a customer does a checkout without pointing to any payment methods. This stage happens after the checkout, when an actual order is already created.
Payment done after the checkout requires an https://api.emporix.io/checkout/{TENANT}/checkouts/orders
POST
request, with the paymentMethods
field including the following information:
provider
- Should always be set to payment-gateway.customAttributes
- It's a set of attributes specific for the particular payment mode.customer
- Identifier of the customer that does the checkout and payment.deferred
- Should be set totrue
.
For this flow the payment authorization is NOT done automatically during the checkout process. Therefore, as a response of the checkout request you can receive the following response with missing paymentDetails
fields:
When an order is placed, the storefront should display all the available payment options and allow the user to choose the relevant one, in this case PayPal.
Having the payment option chosen and all payment details provided, storefront should invoke the following payment-gateway endpoint: https://api.emporix.io/payment-gateway/{TENANT}/payment/frontend/authorize
POST
:
Order id
- A mandatory field, it needs to be an order created by a customer that invokes the authorization endpoint. Otherwise, a validation error is returned.paymentModeId
- payment mode identifier - Reflect the payment mode ID that you received fromGET
:https://api.emporix.io/payment-gateway/{TENANT}/paymentmodes/frontend
.creditCardToken
- The field should contain the token received by the Spreedly library.
Response:
Pay attention to the paymentDetails.externalPaymentRedirectURL
value. To finish the payment, you should redirect the user to the relevant URL, payment flow on the PayPal website.
When the user finishes the whole flow on the PayPal side, the Emporix payment gateway is notified about the result of the operation by a callback. It may take around one minute as this is an asynchronous operation.
The diagram shows how PayPal sequence looks like when it's integrated with Emporix for the post-checkout flow:
Gateway configuration
To start with the gateway configuration, execute the following request:
SPREEDLY_TOKEN
- Is a result of the base64 ofenvironment_key:access_secret
.client_id
andsecret
can be fetched directly from your PayPal account. For more information, see PayPal Gateway Credentials documentation.
Result:
Store the token value for the next steps in the configuration. If you lose the token value at any point, use the following request to get it:
To configure the Emporix Payment Gateway service, execute the following request:
SPREEDLY_GATEWAY_KEY - Spreedly gateway token that was returned when you configured the payment gateway on the Spreedly side.
SPREEDLY_ENVIRONMENT_KEY - Spreedly environment key that you got from the Emporix support team.
SPREEDLY_ACCESS_SECRET - Spreedly secret key that you got from the Emporix support team.
REDIRECT_URL - The URL to your storefront where the user is redirected when the payment is done.
SPREEDLY_SIGNATURE_SECRET - Spreedly signature secret that you got from the Emporix support team.
Storefront implementation
To use Paypal payment, you have to generate a token in Spreedly. You can do this in two ways:
Display a button that does the form submission - as described in PayPal Commerce Platform Offsite Payments.
Execute the following (an example in react):
The payment information is stored because it's needed during the checkout call. The payment object during the checkout request should look like:
Result:
Last updated
Was this helpful?