# Apple Pay
source: https://developer.mastercard.com/mastercard-gateway/documentation/integrations-types/mobile-integration/apple-pay/index.md

You can use [Apple Pay](https://developer.mastercard.com/mastercard-gateway/documentation/payment-methods/digital-wallets/apple-pay/index.md) to collect payment details as a token representing a payment card that the payer has added to their Apple Pay wallet.

To obtain the Apple Pay token from the payer's wallet:

1. To accept payments with Apple Pay, configure your app for Apple Pay. For instructions, see [Configuring your Environment](https://developer.apple.com/library/archive/ApplePay_Guide/Configuration.html) in Apple's developer documentation.

Warning: When creating an Apple Pay Payment Processing Certificate, use the Certificate Signing Request (CSR) provided to you by the gateway. For instructions on how to generate the CSR, see [Configuring your Environment](https://developer.apple.com/library/archive/ApplePay_Guide/Configuration.html).

2. When the payer's order process reaches your checkout page, determine whether the device supports Apple Pay by using the `canMakePayments()` function on `PKPaymentAuthorizationController`. If Apple Pay is supported, display the Apple Pay button as a payment option, using the PKPaymentButton provided by Apple.

3. Construct and use a `PKPaymentRequest`. For instructions, see [Creating Payment Requests](https://developer.apple.com/library/archive/ApplePay_Guide/CreateRequest.html) in Apple's developer documentation.

4. After a user has authorized Apple Pay, update the gateway session with the payment token, `PKPAYMENTTOKEN`:

* Get the payment token as a string to send to the gateway.

```swift
let tokenString = String(data: payment.token.paymentData, encoding: .utf8)
```

* Populate the token string into the GatewayMap as the `devicePayment` and specify that the token came from Apple Pay by setting the `walletProvider`.

```swift
var request = GatewayMap()
request.sourceOfFunds.provided.card.devicePayment.paymentToken = tokenString
request.order.walletProvider = "APPLE_PAY"
```

* Send the `GatewayMap` for your request to the gateway using the `updateSession()` function on the GatewayAPI object.

```swift
GatewayAPI.shared.updateSession("<session id>", apiVersion: "<Gateway API Version>", payload: request) { result in
    switch result {
    case .success(let response):
        print(response.description)
    case .error(let error):
        print(error)
    }
}
```

5. Complete an Apple Pay transaction from your server just as any other payment, using the PAY or AUTHORIZE transaction. For more details see, [Making a Server API Request](https://developer.mastercard.com/mastercard-gateway/documentation/getting-started/make-server-api-req/index.md). When completing a payment on a session that is using Apple Pay, set the order.`walletProvider` field to APPLE_PAY and include the session ID in the request.
