Server-Side Implementation

This page describes the server-side steps for processing Apple Pay transactions, verifying and vaulting Apple Pay cards, and handling Apple Pay card verification using the Braintree SDK.

Create a transactionAnchorIcon

Like all Braintree SDK integrations, you will receive a payment method nonce when your user successfully authorizes payment. Pass this nonce to your server, and create a transaction.

Collect device data from the client and include it in device_data_from_the_client in the transaction.

  1. Ruby
result = gateway.transaction.sale(
    :amount => "10.00",
    :payment_method_nonce => nonce_from_the_client,
    :device_data => device_data_from_the_client,
    :options => {
        :submit_for_settlement => true
    },
    :billing => {
        :postal_code => postal_code_from_the_client
    }
);
The amount that you specify in your client-side payment request object should reflect the actual amount that you authorize and submit for settlement. Transactions will still process in cases where the amount changes during order fulfillment.

If you've already integrated Braintree SDKs to handle payment method nonces for other payment methods, reuse your existing implementation. The preceding example works with a payment method nonce that is associated with any new payment methods that you choose to accept in the future.

For information about enabling verification for cards in Apple Pay transactions, see Enabling Apple Pay card verification.

For certain account setups, PayPal recommends that merchants collect and pass billing address information when they store payment methods or create transactions. Passing the billing address details (minimally, the postal code) helps prevent authorization failures. To learn more about recommendations for your specific account setup, contact us.

Vault Apple Pay cardsAnchorIcon

Apple Pay cards can only be saved to your Vault for specific use cases. For more information, see this support article.

If your use case is supported, you can store a customer's Apple Pay card in your Vault in a few different ways:

Enable Apple Pay card verificationAnchorIcon

There are 2 ways to enable $0 authorization verifications for Apple Pay:

Verify all Apple Pay cards by defaultAnchorIcon

To verify all Apple Pay cards before vaulting by default:

  1. Log into the Control Panel.
  2. Select the gear icon in the top-right corner.
  3. Select Processing from the drop-down menu.
  4. Scroll to the Vaulting section.
  5. Next to Apple Pay Card Verification, select the toggle to enable it.

When the toggle is enabled, the gateway verifies that Apple Pay cards are valid. It does not store invalid cards in the Vault. For information about the way that this default setting interacts with one-time verification requests, see Verification behavior.

Run a one-time verification requestAnchorIcon

If you don't want to verify all Apple Pay cards by default, you can run a one-time request that passes verify_card = true as a parameter on options.verify_card when you perform the following actions:

Creating a payment method

The following example shows how you can use PaymentMethod.create with payment method nonces for one-time verification.

result = gateway.payment_method.create(
  customer_id: "11111111111",
  payment_method_nonce: "9fffffff-aaaa-4444-etce-therestoftheowl",
  options: {
    verify_card: true, # Takes precedence over Control Panel toggle
    verification_merchant_account_id: "a_MAID" # Optional, choose a non-default merchant account if desired
  }
)

For more information, see Card verification.

Creating a customer

The following example shows how you can use Customer.create with payment method nonces for one-time verification.

result = gateway.customer.create(
  first_name: "Jane",
  last_name: "Wallets",
  payment_method_nonce: "9fffffff-aaaa-4444-etce-therestoftheowl",
  apple_pay_card: {
    options: {
      verify_card: true, # Takes precedence over Control Panel toggle
      verification_merchant_account_id: "a_MAID" # Optional, choose a non-default merchant account if desired
    }
  }
)

For more information, see Card verification.

Updating a customer

The following example shows how you can use Customer.update with payment method nonces for one-time verification.

result = gateway.customer.update(
  last_name: "Wallets Sr.",
  payment_method_nonce: "fake-apple-pay-mastercard-nonce",
  apple_pay_card: {
    options: {
      verify_card: true, # Takes precedence over Control Panel toggle
    }
  }
)

For more information, see Card verification.


To understand how one-time verification settings interact with default verification settings, see Verification behavior.

Verification behaviorAnchorIcon

An API parameter takes priority over the toggle in all cases. In other words, if you use the toggle in the Control Panel to activate Apple Pay Card Verification by default, and you also pass verify_card: false, no verification occurs. The following table describes how the verify_card parameter values and toggle settings affect verification behavior.

verify_card parameterControl Panel toggleResult
trueOnVerification created
trueOffVerification created
Not includedOnVerification created
falseOnNo verification
falseOffNo verification
Not includedOffNo verification

Receive verification resultsAnchorIcon

The response objects for customer.create, customer.update, and payment_method.create contain a verification object. If verification fails, the gateway does not vault the card.

Using Customer.create

This example shows a response for customer.create.

result = gateway.customer.create(
  first_name: "Jane",
  last_name: "Wallets",
  email: "wallets@example.com",
  payment_method_nonce: "9fffffff-aaaa-4444-etce-therestoftheowl",
  apple_pay_card: {
    options: {
      verify_card: true, # Takes precedence over Control Panel toggle
      verification_merchant_account_id: "a_MAID" # Optional, choose a non-default merchant account if desired
    }
  }
)

if result.success?
  # result.customer.payment_methods.first.verification
else
  # Verification failed, card not vaulted
end

The verification object has the same parameters for Apple Pay cards as it does for credit cards.

Using PaymentMethod.create

This example shows a response for paymentmethod.create.

result = gateway.payment_method.create(
  first_name: "Jane",
  last_name: "Wallets",
  email: "wallets@example.com",
  payment_method_nonce: "9fffffff-aaaa-4444-etce-therestoftheowl",
  options: {
    verify_card: true, # Takes precedence over Control Panel toggle
    verification_merchant_account_id: "a_MAID" # Optional, choose a non-default merchant account if desired
  }
)

if result.success?
  # result.payment_method.verification
else
  # Verification failed, card not vaulted
end

Create transactions on verified Apple Pay cardsAnchorIcon

When you create transactions on a vaulted Apple Pay card, submit them as merchant-initiated transactions by passing the appropriate merchant-initiated transaction_source flag in the transaction.sale call:

result = gateway.transaction.sale(
  amount: "3.50",
  payment_method_token: "apple-pay-pmt",
  transaction_source: "unscheduled" # recurring, unscheduled, or installment
)