Programmatically start the SDK

In case your app doesn't automatically start the SDK

SDKBetaLast updated: April 18th 2022, @ 9:40:08 am


If you use a custom UI to launch the PayPal Checkout experience, you need to programmatically start the PayPal Mobile 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 PayPal Mobile Checkout SDK code for iOS

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

func triggerPayPalCheckout() {
    Checkout.start(
        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

        }
    )
}