Before a purchase is initiated, your users must either save a card on file with them, or give them stablecoins in a crypto wallet. This guide explains how to do each of those flows.

Pay with a user’s credit or debit card

Use this option if you want the agent to pay with a user’s card just in time.
Tokenize and securely store the user’s card so the agent can use it in future payments compliantly, without ever touching sensitive card data.Start testing today by creating a Crossmint project and test API key:

Crossmint Project

Create a project in the Crossmint Console (staging environment)

Server-side API Key

Obtain a server-side API key from the Overview page and save it for later use

Integration Steps

Crossmint and Basis Theory are closely collaborating to enable this solution.
These APIs are under development and subject to change.
1

Retrieve Credentials

In order to tokenize a user’s card, obtain the necessary keys from Basis Theory by calling the following Crossmint route with your Crossmint API key:
GET https://staging.crossmint.com/api/unstable/setupTokenizeCard
The response looks as follows:
{
  "basisTheoryAPIKey": "key_test_us_pub_LyApUWWyCJ4PqiTEgrSmeK",
  "jwt": "eyJhbG...",
  "basisTheoryProjectId": "6f1ab30..."
}
2

Tokenize Card

Tokenizing a user’s card enables the agent to handle payments without getting access to sensitive card information.Render a card input form using Basis Theory’s SDK and the basisTheoryAPIKey obtained above to tokenize and save the user’s card.You can choose between generating an agentic token or a normal card token.
The “Agentic Token” option only works in staging and is subject to change.
Here is an example of how the above card form can look. Its design can be easily customized by the developer.Payment checkout example
3

Register Token with Crossmint

This step is only needed when using non-agentic Card Tokens.
Call the following Crossmint API with the obtained API key from the Crossmint Console where the TODO comment is above, in order to register the token with Crossmint:

POST https://staging.crossmint.com/api/unstable/setupTokenizeCard/registerToken

{
  "token": "9f243106-d4a4-4327-a7cb-e3ec22031ed2" // Obtained from Step 2
}
No response body is expected from this call, simply a 200 response.
4

Create Order

Call Crossmint’s Create Order API and specify card-token as the payment method (with the same Crossmint API key used above):
POST https://staging.crossmint.com/api/2022-06-09/orders

{
  "recipient": {
    "email": "john.d@example.com",
    "physicalAddress": {
      "name": "John D",
      "line1": "123 ABC Street",
      "city": "New York City",
      "state": "NY",
      "postalCode": "10007",
      "country": "US"
    }
  },
  "locale": "en-US",
  "payment": {
    "receiptEmail": "john.d@example.com",
    "method": "card-token"
  },
  "lineItems": [
    {
      "productLocator": "url:https://www.nike.com/t/maverick-valor-course-tint-sunglasses-1TrBw8KB/IF0969X-021"
    }
  ]
}
Notes on productLocator:General Websites
  • Use url: prefix for any website with guest checkout on the internet
  • Specify product variants by adding a suffix in natural language, as shown below:
url:https://www.nike.com/t/downshifter-13-mens-road-running-shoes-extra-wide-4M0LNf:9
url:https://www.nike.com/t/downshifter-13-mens-road-running-shoes-extra-wide-4M0LNf:size-9
url:https://www.nike.com/t/downshifter-13-mens-road-running-shoes-extra-wide-4M0LNf:size should be 9
url:https://www.nike.com/t/downshifter-13-mens-road-running-shoes-extra-wide-4M0LNf:{"size":9}
Shopify
  • Use shopify: prefix for Crossmint to pay on your behalf & act as Merchant of Record
  • Specify product variants by ID, fetching them using the route found in Step 3 here
url:https://www.nike.com/t/downshifter-13-mens-road-running-shoes-extra-wide-4M0LNf:<
Amazon
  • Use amazon: prefix instead of url: for Amazon products
  • Crossmint will complete the transaction on your behalf
  • No variants are needed as Amazon URLs are unique
5

Complete Payment with Card Token

Obtain the orderId from Step 4’s response and call the following Crossmint API:
POST https://staging.crossmint.com/api/unstable/orders/{{orderId}}/payment

{
  "token": "9f243106-d4a4-4327-a7cb-e3ec22031ed2" // Obtained from Step 2
}
The response will show that the payment is successful. Check the recipient’s email for a purchase receipt.

See it in action

1

Clone and Setup

git clone https://github.com/Crossmint/crossmint-checkout-tokenized-cc-demo
cd crossmint-checkout-tokenized-cc-demo
npm install
2

Configure Environment

Add your Crossmint API key to the src/app/consts.ts file.
3

Start the Application

npm run dev 
4

Setup HTTPS Tunnel

Note that due to security reasons, the card verification process cannot happen in an HTTP environment. Use ngrok to create an HTTPS tunnel:
  ngrok http 3000 (or the port shown in your terminal) 
5

Open your browser

Navigate to the HTTPS URL provided by ngrok (e.g., https://abc123.ngrok.io) instead of the local HTTP URL