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 the event closures set on the Checkout type, provide the closures directly to the SDK through Checkout.start.

Sample Native Checkout SDK code for iOS

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

func triggerPayPalCheckout() {
        createOrder: { createOrderAction in

            let amount = PurchaseUnit.Amount(currencyCode: .usd, value: "10.00")
            let purchaseUnit = PurchaseUnit(amount: amount)
            let order = OrderRequest(intent: .capture, purchaseUnits: [purchaseUnit])

            createOrderAction.create(order: order)

        }, onApprove: { approval in

            approval.actions.capture { (response, error) in
                print("Order successfully captured: \(response?.data)")

        }, onCancel: {

            // Optionally use this closure to respond to the user canceling the paysheet

        }, onError: { error in

            // Optionally use this closure to respond to the user experiencing an error in
            // the payment experience