Server-side integration

Use the Native Checkout SDK with your server-side integration

SDKCurrentLast updated: October 5th 2021, @ 1:45:59 pm


You can integrate the Native Checkout SDK for Android 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 the setup function or your PaymentButton. The only difference is that instead of creating an Order, you generate the order ID from your own server-side integration and then provide the order ID through the provided set function.

    payPalButton.setup(
        createOrder = CreateOrder { createOrderActions ->
            val orderId: String // Retrieve your order ID from your server-side integration
            createOrderActions.set(orderId)
        }
    )
    paymentButton.setup(
        new CreateOrder() {
            @Override
            public void create(@NotNull CreateOrderActions createOrderActions) {
                String orderId; // Retrieve your order ID from your 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 Android SDK supports supports capturing and authorizing orders created through both client-side or server-side integrations using PayPal-generated tokens. However, if you create an order through a server-side integration, you must capture or authorize the order using your own server-side integration.

Sample code

This sample code uses yourAppsCheckoutRepository as an example. To capture or authorize through a server-side integration, use the following to register the OnApprove callback from the setup function of the PaymentButton:

    payPalButton.setup(
        onApprove = OnApprove { approval ->
            // 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)
        }
    )
     paymentButton.setup(
        new OnApprove() {
            @Override
            public void onApprove(@NotNull Approval approval) {
                // Optional -- retrieve order details first
                yourAppsCheckoutRepository.getEC(approval.getData().getOrderId());

                // Send the order ID to your own endpoint to capture or authorize the order
                yourAppsCheckoutRepository.captureOrder(approval.getData().getOrderId());
            }
        }
    );

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