Server-side integration

Use the Native Checkout SDK with your server-side integration

SDKCurrentLast updated: October 1st 2021, @ 12:45:16 pm


You can integrate the Native Checkout SDK for iOS 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 first five steps in a Client-side integration.

Launch the payment sheet

Similar to the client-side integration, you can 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.

Checkout.setCreateOrderCallback { createOrderAction in
    // Retrieve order ID from server-side integration
    createOrderActions.set(orderId)
}

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

The iOS SDK supports capturing and authorizing orders created through both client-side or server-side integrations using either PayPal-generated tokens or your own generated tokens.

To capture or authorize through a server-side integration, use the following to register the OnApprove callback through Checkout.setOnApproveCallback:

Checkout.setOnApproveCallback { approval in
    // Optional -- retrieve order details first
    yourAppsCheckoutRepository.getEC(approval.data.orderId);

    // Send the order ID to your own endpoint to capture or authorize the order
    yourAppsCheckoutRepository.captureOrder(approval.data.orderId)
}

Test and go live

Use your client ID when adding the Native Checkout SDK to your app. Use your sandbox accounts when testing the SDK.

Next steps