Integrate with your server
Use Orders created server-side and enable billing agreements during checkout.
SDKLast updated: September 6th 2023, @ 12:43:42 pm
- Create order server-side
- Billing Agreements
Server provided Order ID
You can integrate the PayPal Mobile Checkout SDK with your existing server-side PayPal integration. Server-side integrations offer greater flexibility and control than client-side integrations, enabling you to better ensure compatibility with your other integrations. A server-side integration also enables you to generate your own tokens.
Know before you code
Before integrating, determine which of the following server-side integrations you want to use:
Note: If you're integrating for the first time, we recommend using the REST v2 server-side integration.
You must complete the Initialize SDK instructions.
Launch the payment sheet
Launch the payment sheet by passing a CreateOrder
callback into your Checkout.setCreateOrderCallback
function.
The only difference is that instead of creating an Order
, you provide the order ID through the provided set
function.
- Swift
- Obj-C
1Checkout.setCreateOrderCallback { createOrderAction in2 // Retrieve order ID or EC-token from server-side integration3 createOrderAction.set(orderId: "EC-XXXXXXXXXXXXXXXXX")4}
Ensure the payment sheet launches as soon as the buyer selects the PaymentButton
by making your server-side request from within the CreateOrder
callback.
Note: The
CreateOrder
callback invokes from the main thread. Ensure all server-side requests execute from a background thread.
Capture or authorize an order
If you create an order through a server-side integration, you must capture or authorize the order using your own server-side integration.
This sample code uses yourAppsCheckoutRepository
as an example. To capture or authorize an order, register the OnApprove
callback through Checkout.setOnApproveCallback
:
- Swift
- Obj-C
1Checkout.setOnApproveCallback { approval in2 // Optional -- retrieve order details first3 yourAppsCheckoutRepository.getEC(approval.data.orderId);4 // Send the order ID to your own endpoint to capture or authorize the order5 yourAppsCheckoutRepository.captureOrder(approval.data.orderId)6}
Test and go live
Use your client ID when adding the PayPal Mobile Checkout SDK to your app. Use your sandbox accounts when testing the SDK.