# Apple Pay iOS SDK

This page contains information about the available methods and parameters of the Apple Pay iOS SDK.

:::info
For detailed instructions on how to install and integrate the SDK, see: [Accept payments via Revolut Merchant Card Form SDK - iOS](/docs/guides/merchant/accept-payments/online-payments/apple-pay-google-pay/mobile/ios).
:::

## Methods and parameters

### `RevolutPaymentsSDK.configure` method

The `RevolutPaymentsSDK.configure` method is used to set up the SDK with necessary configurations, such as the merchant's public API key and the environment in which the SDK will operate. Configuring the SDK needs to happen before any SDK usage, can be done on app launch by adding this to `AppDelegate`.

```swift
RevolutPaymentsSDK.configure(
    with: .init(
        merchantPublicKey: "<yourPublicAPIKey>",
        environment: .production
    )
)
```

| Parameter           | Description                                                                                                                                                                                                                                | Format        | Required |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- | -------- |
| `merchantPublicKey` | The merchant's public API key used for authorization.                                                                                                                                                                                      | String        | Yes      |
| `environment`       | This parameter specifies the environment in which the SDK operates. If omitted it defaults to `.production`. <br/><br/>_Currently, only the **production environment** is available._ Possible values are: <ul><li>`.production`</li></ul> | `Environment` | Yes      |

### `RevolutApplePayKit.isApplePaySupported` method

Determines whether the user's devices can process payment requests.

```swift
RevolutApplePayKit.isApplePaySupported() -> Bool
```

### `RevolutApplePayKit.makePaymentRequest` method

Creates the Apple Pay payment request with some required properties pre-populated according to your Revolut merchant account configuration and the parameters passed, as required for the payment processing.

```swift
RevolutApplePayKit.makePaymentRequest(
    merchantId: String,
    totalAmount: Int64,
    currencyCode: String,
    completion: @escaping (Result<PKPaymentRequest, Error>) -> Void
)
```

| Parameter      | Description                                                                                                                                 | Format  | Required |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
| `merchantId`   | The Apple Pay Merchant ID registered on the Apple Developer portal (e.g., `merchant.com.yourapp`).                                          | String  | Yes      |
| `totalAmount`  | The payment amount in minor units (e.g., cents for USD).                                                                                    | Int64   | Yes      |
| `currencyCode` | The 3-letter [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, used by the payment request.                                 | String  | Yes      |
| `completion`   | The closure called upon payment request creation completion. This method is asynchronous, so you should handle the UI during its execution. | Closure | Yes      |

#### Notes

- Pre-populated properties: `supportedNetworks`, `merchantCapabilities`, `merchantIdentifier`, `countryCode`, `currencyCode`, `requiredBillingContactFields`, `requiredShippingContactFields`.
- You must set the rest of the properties according to your needs (e.g., `paymentSummaryItems`).
- If you omit the billing or contact fields required by the SDK, they will be re-added by the SDK on flow start (e.g., `emailAddress` from `requiredShippingContactFields`).

### `RevolutApplePayKit.presentApplePay` method

Presents the Apple Pay sheet configured according to the payment request. The payment is processed through Revolut.

```swift
RevolutApplePayKit.presentApplePay(
    for paymentRequest: PKPaymentRequest,
    onAuthorize: @escaping AuthorizePaymentCallback,
    onSelectShippingMethod: UpdateShippingMethodCallback? = nil,
    onSelectShippingContact: UpdateShippingContactCallback? = nil,
    completion: @escaping CompletionCallback
)
```

| Parameter                 | Description                                                                                                                                                                                                                                                                                                       | Format  | Required |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
| `paymentRequest`          | A [`PKPaymentRequest`](https://developer.apple.com/documentation/passkit_apple_pay_and_wallet/pkpaymentrequest) object configured with payment details obtained from the payment request made by the [`makePaymentRequest`](#revolutapplepaykitmakepaymentrequest-method) helper method.                          | Object  | Yes      |
| `onAuthorize`             | A callback triggered when the user authorises the payment to [create an order](/docs/api/merchant#create-order) via a backend request. Retrieve the order's `token`, and pass it to the SDK, using the `set(orderToken:)` method of the closure's `RevolutApplePayKit.AuthorizePaymentCallbackHandler` parameter. | Closure | Yes      |
| `onSelectShippingMethod`  | A callback triggered when the user selects a shipping method. Allows you to validate it and update the sheet accordingly.                                                                                                                                                                                         | Closure | No       |
| `onSelectShippingContact` | A callback triggered when the user selects a shipping contact. Allows you to validate it and update the sheet accordingly.                                                                                                                                                                                        | Closure | No       |
| `completion`              | A callback triggered with the final result of the payment process (`.success`, `.failure`, `.userAbandonedPayment`).                                                                                                                                                                                              | Closure | Yes      |

:::info
The callbacks correspond to `PassKit.PKPaymentAuthorizationControllerDelegate` methods. You may also consult [Apple's documentation](https://developer.apple.com/documentation/passkit_apple_pay_and_wallet/pkpaymentauthorizationcontrollerdelegate) for a deeper understanding of how Apple Pay and the callbacks work.
:::

## Errors

### `RevolutApplePayKit.Error` enumeration

Error types returned by the Revolut Apple Pay SDK. The `Error` enumeration defines a set of error types that can occur during the payment process, returned by the `.failure` case of the `completion` closure.

```swift
RevolutApplePayKit.Error(
    case `internal`(Swift.Error)
    case kitAlreadyInUse
    case paymentFailed(PaymentError)
    case presentationFailed
)
```

| Case                          | Description                                                                                                                                                       |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `internal(Swift.Error)`       | Returned when an internal error occurs within the SDK.                                                                                                            |
| `kitAlreadyInUse`             | Returned when the `RevolutApplePayKit` instance is already being used by a flow (e.g., when trying to present the Apple Pay sheet while it is already displayed). |
| `paymentFailed(PaymentError)` | Returned when the payment fails. The associated `PaymentError` provides detailed information about the specific reason for the failure.                           |
| `presentationFailed`          | Returned when presenting the Apple Pay sheet fails.                                                                                                               |

### `RevolutApplePayKit.Error.PaymentError` enumeration

The `PaymentError` enumeration is returned by the `paymentFailed` case of the `RevolutApplePayKit.Error` enumeration. These errors provide detailed information about what went wrong, and help developers handle various failure scenarios appropriately.

```swift
RevolutApplePayKit.Error.PaymentError(
    case highRisk
    case insufficientFunds
    case invalidCVV
    case invalidEmail
    case invalidTransaction
    case issuerDecline
    case orderCreationFailure
    case other
    case paymentAttemptBlocked
    case restrictedCard
    case suspectedFraud
    case unknownCard
)
```

:::info
Errors not found on the list are mapped to the `other` case. For more information about the error cases, see: [Decline reasons](/docs/guides/merchant/reference/error-codes/decline-reasons).
:::