Programmatically start the SDK

In case your app doesn't automatically start the SDK

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


If you use a custom UI to launch the PayPal Checkout experience, you need to programmatically start the Native Checkout SDK.

Instead of invoking the payment sheet by adding a button with callbacks, provide the callbacks directly to the SDK through PayPalCheckout.start().

Sample Native Checkout SDK code for Android

This sample code creates an order of a single item for $10.00 USD.

PayPalCheckout.start(
    CreateOrder { createOrderActions ->
        val order = Order(
            intent = OrderIntent.CAPTURE,
            appContext = AppContext(
                userAction = UserAction.PAY_NOW
            ),
            purchaseUnitList = listOf(
                PurchaseUnit(
                    amount = Amount(
                        currencyCode = CurrencyCode.USD,
                        value = "10.00"
                    )
                )
            )
        )

        createOrderActions.create(order)
    },
    OnApprove { approval ->
        approval.orderActions.capture { captureOrderResult ->
            Log.i("CaptureOrder", "Order successfully captured: $captureOrderResult")
        }
    },
    OnCancel {
        // Optional callback for when a buyer cancels the paysheet
    },
    OnError { errorInfo ->
        // Optional error callback
    }
)
PayPalCheckout.start(
    createOrderActions -> {
        ArrayList purchaseUnits = new ArrayList<>();
        purchaseUnits.add(
            new PurchaseUnit.Builder()
                .amount(
                    new Amount.Builder()
                        .currencyCode(CurrencyCode.USD)
                        .value("10.00")
                        .build()
                )
                .build()
        );
        Order order = new Order(
            OrderIntent.CAPTURE,
            new AppContext.Builder()
                .userAction(UserAction.PAY_NOW)
                .build(),
            purchaseUnits
        );
        createOrderActions.create(order, orderId -> {

        });
    },
    approval -> {
        approval.getOrderActions().capture(result -> {
            // Order successfully captured
        });
    },
    null,
    () -> {
        // Optional callback for when a buyer cancels the paysheet
    },
    errorInfo -> {
        // Optional error callback
    }
);