Programmatically start the SDK



If your integration or UI doesn't easily create an order, you can programmatically start the Native Checkout SDK for iOS.

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