Implement Apple Pay and Cybersource

This guide will walk you through setting up the Apple Pay demo provided by Apple. Then using the Apple Pay payment data to execute an authorization through Cybersource.

Apple Pay

Setting Up Apple Pay

If you already are executing Apple Pay payments, you and skip these steps and go directly to making an authorization through Cybersource.

To setup Apple Pay you must be enrolled in the Apple Developer Program, have a sandbox test user with its own Apple ID, and have a test device logged into the sandbox users Apple ID.

Create a Merchant Identifier

The first step is creating a merchant identifier. This identifies you as an Apple Pay merchant and is used to create the Cybersource Certificate Signing request. This identifier remains behind the scenes and is not seen by customers.

Create the Sandbox Apple ID

Next, a sandbox user has to be created. Make sure the user has permissions to use Apple Pay. This is an actual Apple ID and can be used to log in to devices and services.

Signing the user into a dedicated device is recommended. Having a designated test device makes this easier so you don't have to log in and out of your personal Apple ID. Loggin in as an App Store sandbox user, which is normally used for testing in-app purchases, will not work.

Add a Test Card to the Sandbox User's Wallet

After the user is logged into the device, add a test card to the user's wallet. Note that you won't be able to add a test card during device setup. Some cards throw an error when adding them to the wallet. If you receive an error, try a different card.

Setup the Sample

Download and open the Apple Pay Sample. As usual, let Xcode manage as much of the signing and device registration as possible.

  1. For each target, select your team.
  2. For each target, change "com.example.apple-sample" in the bundle identifier to your preferred prefix.
  3. For each target, remove the "${SAMPLE_CODE_DISAMBIGUATOR}" placeholder. It seems to have no effect.
  4. For each target, under the "Build Settings" tab, change "OFFERING_APPLE_PAY_BUNDLE_PREFIX" to the value used in step 2.
  5. For each target, under the Apple Pay capability, check your merchant identifier.
  6. Within the Configuration.swift file, change the identifier property to your merchant identifier
  7. Within the PaymentHandler.swift file, add print(payment.token.paymentData.base64EncodedString()) to the success case the paymentAuthorizationController didAuthorizePayment function. This will print the base64 encoded data required for a Cybersource authorization.

Cybersource Authorization

Apple Pay Enablement

In order to use Apple Pay at Cybersource, it must be enabled by a Cybersource representative. Contact Cybersource to have Apple Pay enabled.

Generate Apple Pay Certificate Signing Request

After Apple Pay is enabled for your Cybersource MID, log into the Business Center. Navigate to Payment Configuration > Digital Payment Solutions and then click the "Configure" button in the Apple Pay row.

Provide your Apple Merchant ID. This value should match the id you set up with Apple including the "merchant" prefix. Click "Generate new certificate signing request" then download the Certificate Signing Request.

Generate Cybs CSR

Upload the Certificate Signing Request to Apple

Upload the Certificate Signing Request to Apple. Skip step 5 and choose to upload the Cybersource Certificate Signing request you just created.

Send Apple Pay Authorization through Cybersource

Install the the demo application to your test device using Xcode. Provide shipping information and execute the payment. The base64 encoded payment data should show up in the Xcode console. Copy the value.

Then, reference your processors Cybersoruce Apple Pay implementation guide. Reference a "Authorizing Using Cybersource Decryption" section in the guide. A card type that matches the test card you setup must be used.

Follow the instructions to create a request. For example, this is a Visa FDC Nashville Global sample request.


{
  "clientReferenceInformation": {
    "code": "1234567890"
  },
  "processingInformation": {
    "paymentSolution": "001"
  },
  "paymentInformation": {
    "fluidData": {
      "value": "eyJ2ZXJzaW9uIjoiRUNfdjEiLCJkYXRhIjoiOUZnSG82akhKMFRWUitJbVRpQXU4S292TnA1KzRQcUZZUXBsaFJVYnpBclgyakV2RnNtR01jdEhlcEVWbENxaEg2Uk94eWlmbGM2L0VaRVpZOThLZG1FbTFxRGRVSkVaZG45eWNLYmNZQ21naXNxM25RY25uZ1R3blQ2QVhWRU5CQ0tJdWcxTE5pMy90NFl3d202OVZFUXFDUEorRkZKczJhWkNmanUzMzRzallMVXk2Tkk0MVFVbVc1ZG1ta1d4UFhGWUtiQ1BzWG9hVEJSSlo2WHJQUnlvRDJLdE43MFNTTUE5bDhFRDJvTWZrcCs2SllvZ1Y3OWU4RkZONGNLK0JsbUtCSXA3MEpqaDNkZHljNGFIaTBJd0U5Wk5WM2dEYzBuSHdib2d0dk83Y1RGRmZDMDMyVEJWU3lGdm5KOEFKdk00TG9vbHBObitpNmxha2FaZmRsNTVQbXNFbTVRdXpWNnE3elBVNklHYUpxQW9BQXhUR2owS2hKVUpjcFlVbEtuNGZaRkN5K3JOMGJPb1BFdkVmcVFnSHplYVY1SGRrZGgzLzFQYzJnUT0iLCJz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zNmE1eHVFWmZCSldxdERudy9mNjhyNXdlR2RXYUdIK0pFK2pQZjg9IiwidHJhbnNhY3Rpb25JZCI6ImNiNjUyMjI5ZWNiYzFhNDYzMTVlZWEzYzljZTQ0Yzk4ZWY1ZGVhZmI3MzRhYzMyMDhlYzFlODU2NmRjMDVkOGQifX0=",
      "descriptor": "RklEPUNPTU1PTi5BUFBMRS5JTkFQUC5QQVlNRU5U",
      "encoding": "Base64"
    },
    "tokenizedCard": {
      "type": "001",
      "transactionType": "1"
    }
  },
  "orderInformation": {
    "amountDetails": {
      "totalAmount": "100.00",
      "currency": "USD"
    },
    "billTo": {
      "firstName": "Ryan",
      "lastName": "Klein",
      "address1": "123 Main St",
      "locality": "SomeCity",
      "administrativeArea": "CA",
      "postalCode": "94404",
      "country": "US",
      "email": "ryan@ryanklein.dev"
    }
  }
}

Conclusion

This guide walks through the basics of getting Apple Pay to work through Cybersource. It should provide a foundation for building your own applications and executing payment flows specific to your needs.