Full Transaction Lifecycle Example

Step 1: Gather The Digital Wallet Data with Collect.js

This example code snippet prepares a request that indicates the customer will be charged $10 per month starting on October 31, 2025:

<script
        src="https://secure.nmi.com/token/Collect.js"
        data-tokenization-key="000000-000000-000000-000000"
        data-variant="inline"
        data-field-apple-pay-selector=".apple-pay-button"
        data-field-apple-pay-line-items='[{"label":"Monthly Subscription","amount":"10.00"}]'
        data-field-apple-pay-total-label="Our Fine Products"
        data-field-apple-pay-type="buy"
        data-country="US"
        data-currency="USD"
        data-price="0.00"
        data-field-apple-pay-is-recurring-transaction="true"
        data-field-apple-pay-recurring-payment-description="Recurring payment description"
        data-field-apple-pay-recurring-billing-agreement="Recurring billing agreement"
        data-field-apple-pay-recurring-management-url="https://mymanagementurl.com"
        data-field-apple-pay-recurring-token-notification-url="https://mynotificationurl.com"
        data-field-apple-pay-recurring-label="Recurring"
        data-field-apple-pay-recurring-amount='10.00'
        data-field-apple-pay-recurring-payment-timing="recurring"
        data-field-apple-pay-recurring-payment-start-date='2025-10-31T00:00:00Z'
        data-field-apple-pay-recurring-payment-interval-unit='month'
        data-field-apple-pay-recurring-payment-interval-count='1'
        data-field-apple-pay-recurring-payment-end-date=''
        ></script>
<form action="/myProcessingScript" method="POST">
<div id="apple-pay-button"></div>
</form>

In the customer's browser, it will show a "Pay with Apple Pay" button like this:

A screenshot of Safari showing a page with a single black "Pay with Apple Pay" button


and when they press the button, they'll see:

A screenshot of Safari showing an Apple Pay recurring payment sheet, indicating $0.00 up front and $10 per month starting October 30th.

Note: This example is minimal to focus on the Apple Pay requirements. Merchants may need wish to add other fields to support direct card number entry if you also want to accept non-Apple Pay transactions through this form, or additional customer and order details.

Step 2: Perform the initial vault request

When the customer finishes interacting with the Apple Pay payment sheet, the form is automatically submitted to a script on a server you control. In this example, it's called /myProcessingScript.

In addition to any other fields the form contains, /myProcessingScript will receive a field named payment_token. This is used in place of conventional card data when adding a customer's information to the vault. For example, you could perform a request like this:

curl --request POST \
     --url https://secure.nmi.com/api/transact.php \
     --header 'accept: application/x-www-form-urlencoded' \
     --header 'content-type: application/x-www-form-urlencoded'
     
     --data customer_vault=add_customer \
     --data customer_vault_id=MyVaultId1 \
     --data payment_token=00000000-000000-000000-000000000000\ 
     
     --data first_name=John \
     --data last_name=Doe \
     --data 'address1=123 Main Street' \
     --data 'address2=Apt E' \
     --data city=Wichita \
     --data state=KS \
     --data zip=12345 \
     --data country=US \
     --data phone=8005551212 \
     --data [email protected] \
     --data stored_credential_indicator=stored \
     --data initiated_by=customer

     --data security_key=XXXXXXXXXXXXXXXXXXXXXXXXXX

When this step is performed, we performed a $0 authorization to ensure that the digital wallet data is correctly cued up.. You'll get a response including these fields:

response=1&transactionid=281474976710716&customer_vault_id=MyVaultId1...

The response=1 lets you know the request was successful, and you should save the transactionidalongside the customer_vault_id for future usage.

Step 3: Perform a sale using the vault ID

When October 31 rolls around (or any other billing conditions you've discussed with the customer), you can proceed to use the data you placed in the vault to charge them. If you use the customer_vault_id you registered in step 2, it will access the payment info the customer provided through Apple Pay. You should make sure to send stored_credential_indicator, initiated_by, and initial_transaction_id (set to the transactionid you saw in step 2) to provide the card networks with most accurate details about how this transaction is being managed for the best chance a of successful transaction. For example

curl --request POST \
     --url https://secure.nmi.com/api/transact.php \
     --header 'accept: application/x-www-form-urlencoded' \
     --header 'content-type: application/x-www-form-urlencoded'
     
     --data type=sale \
     --data amount=10.00 \
     --data customer_vault_id=MyVaultId1 \
     --data stored_credential_indicator=used \
     --data initiated_by=merchant \
     --data initial_transaction_id=281474976710716 \
        
     --data security_key=XXXXXXXXXXXXXXXXXXXXXXXXXXX

And you'll get a successful result similar to a non-vault-based sale:

response=1&responsetext=Approved&authcode=TAS536&transactionid=28147497671995...