PayPal Widget

The MobileSDK provides a PayPal Widget that integrates with PayPal using a WebView component. This handles the communication between PayPal and the SDK. Once completed, the WebView component returns the charge result.

Interface

Here is the interface:

PayPalButton(
    requestShipping: Bool,
    token: (_ walletChargeToken: (String) -> Void) -> Void,
    completion: (Result<ChargeResponse, Error>) -> Void
) -> View

And here is an example of it in use:

PayPalButton(requestShipping: false) { walletChargeToken in
    // Fetch Wallet Charge Token
    walletChargeToken("some-wallet-charge-token")
} completion: { result in
    switch result {
    case .success(let chargeResponse):
        // Record payment success
    case .failure(let error):
        // Handle error
    }
}

Definitions

ChargeResponse

public struct ChargeResponse: Codable {
	public let id: String
	public let status: String
  	public let amount: Decimal
  	public let currency: String
}

Table example

Name Error message Type
initFailedInitialisation of PayPal has failedPayPalError
paymentFailedProcessing the payment has failed.PayPalError