Use SDK with server-side integration

SDKCurrentLast updated: June 7th 2021, @ 11:35:12 am


Overview

You can integrate the Native Checkout SDK for iOS with your existing server-side PayPal integration. This enables greater level control so you can ensure compatibility with your other integrations. It also enables you to generate your own tokens.

Know before you code

Complete steps one through three in Set up iOS SDK.

1. 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.

2. 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)
}

Next steps

Customize payment buttons