Skip to main content

Apple Pay

Apple Pay is a mobile and online purchasing experience for customers with supported iOS and macOS devices. This guide explains how to create Apple Pay transactions and vault Apple Pay card with Braintree GraphQL APIs.

Creating transactions

For the purpose of making transactions, an Apple Pay card is treated just like other credit cards with a few noted differences.

Using chargePaymentMethod mutation and supply just an amount and paymentMethodId (which is called payment method nonce on the client-side) you can create an Apple Pay card transaction.

mutation

mutation ChargePaymentMethod($input: ChargePaymentMethodInput!) {
chargePaymentMethod(input: $input) {
transaction {
id
createdAt
status
amount {
value
currencyCode
}
merchantAccountId
paymentMethodSnapshot {
... on CreditCardDetails {
brand
brandCode
last4
expirationMonth
expirationYear
cardholderName
origin {
type
details {
... on ApplePayOriginDetails {
bin
paymentInstrumentName
}
}
}
}
}
processorResponse {
legacyCode
message
avsPostalCodeResponse
avsStreetAddressResponse
cvvResponse
}
}
}
}

variables

{
"A": {
"paymentMethodId": "fake-apple-pay-visa-nonce",
"transaction": {
"amount": "1.00"
}
}
}

response

{
"data": {
"chargePaymentMethod": {
"transaction": {
"id": "dHJhbnNhY3Rpb25fZHgwMTNlcXc",
"createdAt": "2022-08-31T04:42:53.000000Z",
"status": "SUBMITTED_FOR_SETTLEMENT",
"amount": {
"value": "1.00",
"currencyIsoCode": "USD",
"currencyCode": "USD"
},
"merchantAccountId": "z9td4ytkj98jmqbz",
"paymentMethodSnapshot": {
"brand": "Visa",
"brandCode": "VISA",
"last4": "8886",
"expirationMonth": "12",
"expirationYear": "2023",
"cardholderName": "Visa Apple Pay Cardholder",
"origin": {
"type": "APPLE_PAY",
"details": {
"bin": "401288",
"paymentInstrumentName": "Visa 8886"
}
}
},
"processorResponse": {
"legacyCode": "1000",
"message": "Approved",
"avsPostalCodeResponse": "NOT_PROVIDED",
"avsStreetAddressResponse": "NOT_PROVIDED",
"cvvResponse": "NOT_PROVIDED"
}
}
}
},
"extensions": {
"requestId": "012a125a-0ce9-4194-b4f6-24402b285615"
}
}

Now, let's go over the differences. Sharp eyes would notice the origin bits in the response. First, the type clearly spells out that it's an Apple Pay transaction. Next, the bin which the first 6 digits of the device-specific account number (DPAN), known as the Bank Identification Number. This BIN will differ from the BIN of the underlying card. And the paymentInstrumentName which is a description of the payment method intended for display to the user, typically card type and last 4 digits of the physical card number stored by Wallet (formerly Passbook). We receive this description alongside the DPAN when processing an Apple Pay transaction.

Note: If you need to pass billing address, tokenized CVV, 3D Secure authentication or other fraud tool options, you should use chargeCreditCard instead.

Vaulting Apple Pay cards

Apple Pay cards can be vaulted and used for recurring billing and split shipment transactions.

Vaulting Apple Pay cards should only be used when the customer consents to future merchant-initiated transactions during checkout. It should not be used for future transactions where the customer is present and available to authorize payments during the time of transaction; doing so will result in declines and is not recommended. Please refer to our Developer Guide for more information.

Now, let's actually do it.

mutation

mutation VaultPaymentMethod($input: VaultPaymentMethodInput!) {
vaultPaymentMethod(input: $input) {
paymentMethod {
id
legacyId
customer {
id
firstName
lastName
defaultPaymentMethod {
id
}
}
}
}
}

variables

{
"input":{
"paymentMethodId":"fake-apple-pay-amex-nonce"
}
}

response

{
"data": {
"vaultPaymentMethod": {
"paymentMethod": {
"id": "cGF5bWVudG1ldGhvZF9hcHBsZV9ienY2OHdi",
"legacyId": "bzv68wb",
"customer": {
"id": "Y3VzdG9tZXJfMjgzMTc4Mjg3",
"firstName": null,
"lastName": null,
"defaultPaymentMethod": {
"id": "cGF5bWVudG1ldGhvZF9hcHBsZV9ienY2OHdi"
}
}
}
}
},
"extensions": {
"requestId": "e8a33ddb-5431-49de-8e63-65552ed47f80"
}
}

Now you may wonder how this is different than vaulting a regular credit card. Well, no difference. Simple as that.