Accept a payment in an embedded payment form

The embedded payment form keeps the customer on your site. Your server creates a payment, your page loads the Triple-A form in an iframe, and a signed webhook tells you when to deliver. This blueprint takes you from your first access token to going live.

Before you start

You need the following.

  • Sandbox credentials, which are your Client ID, Client Secret, and merchant key. New accounts go through a manual review first. See Get your API credentials.
  • A checkout page on your site where the payment form can load in an iframe.
  • A publicly reachable URL for your webhook endpoint. We recommend HTTPS.
  • A testnet wallet with testBTC to pay test payments. See Sandbox and test mode.

These pages explain the product and how a payment flows.

Step by step

Follow these steps in order.

Get an access token

Get an access token

POST

POST /oauth/token

Every call needs an OAuth access token. To get one, call POST /oauth/token from your server with your Client ID and Client Secret. The highlighted line sets grant_type, which must be client_credentials.

Request
curl --request POST \
  --url https://api.triple-a.io/api/v2/oauth/token \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'client_id=YOUR_CLIENT_ID' \
  --data-urlencode 'client_secret=YOUR_CLIENT_SECRET' \
  --data-urlencode 'grant_type=client_credentials'

The response holds the token and its lifetime in seconds. The highlighted line is the access_token to send as Authorization: Bearer YOUR_ACCESS_TOKEN in every later request.

Response
{
  "access_token": "1ba8...",
  "token_type": "bearer",
  "expires_in": 3600
}

Cache the token and refresh it shortly before expires_in runs out, rather than requesting a new one for every call. Never put the Client Secret in client-side code.

Create the payment

Make a payment request

POST

POST /payment

Call POST /payment from your server with type set to widget. The highlighted lines are what this flow depends on. type asks for the embeddable form, and payer_id identifies your customer.

Request
curl --request POST \
  --url https://api.triple-a.io/api/v2/payment \
  --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "type": "widget",
    "merchant_key": "YOUR_MERCHANT_KEY",
    "order_currency": "USD",
    "order_amount": 10,
    "order_id": "ORDER-1001",
    "payer_id": "TRE1787238200",
    "notify_url": "https://your-server.example.com/webhook",
    "notify_secret": "a-long-random-secret",
    "sandbox": true
  }'

The table below describes the fields in this request.

FieldRequiredNotes
typeYeswidget returns a payment form to embed in your page.
merchant_keyYesIdentifies your merchant account. You receive it when you sign up.
order_currency, order_amountYesThe price, with a 3-character ISO 4217 currency code.
payer_idRecommendedA unique ID for your customer, or their email address if you have no ID. Triple-A uses it to track each payer’s total spend for KYC.
order_idOptionalYour own reference, up to 255 characters.
notify_url, notify_secretOptionalWhere Triple-A sends the webhook and the secret that signs it. Without them, Triple-A uses your account’s webhook URL and generates a secret for this payment.
sandboxFor testingtrue marks a test payment.

The request has no success_url or cancel_url, because the customer stays on your page and you follow the outcome through the form’s events in the next step. Save the payment_reference and hosted_url from the response.

Example response #

The following is an example response. The highlighted line is the hosted_url of the form, which you load in the next step.

Response
{
  "payment_reference": "PLG-571830-PMT",
  "order_currency": "USD",
  "order_amount": 10,
  "expiry_date": "2022-01-26T10:25:58.234Z",
  "access_token": "b8188fa9...",
  "token_type": "Bearer",
  "expires_in": 1499,
  "hosted_url": "https://cdn.triple-a.io/widgets/triplea-ecommerce-payment-v1.1/?access_token=b8188fa9...&payment_reference=PLG-571830-PMT&select=1"
}

The access_token in this response belongs to the payment form. It isn’t your API access token.

Embed the payment form

Use hosted_url as the src of an iframe on your checkout page. The form is responsive and fits the width you give it. The highlighted line is where the URL goes.

checkout.html
<iframe
  id="triplea-payment-form"
  src="HOSTED_URL_FROM_THE_RESPONSE"
  style="width: 500px; height: 700px; border: 0;"
  scrolling="no"
></iframe>

You can add the following optional parameters to the end of the src URL to adjust the form.

ParameterEffect
lang=frShows the form in another language. It supports 13 languages and defaults to the customer’s browser language.
order_details=hideHides the order details.
open_wallet_button=hideHides the Open in Wallet button on desktop. Use hide-all to hide it on mobile too.

The form tells your page what happens through browser postMessage events. The table below lists the events a checkout needs.

EventWhen it fires
triplea.frameResizedThe form changed height. The new height in pixels follows the event name.
triplea.paymentSuccessThe customer completed the payment.
triplea.paymentTooLittleThe customer paid less than requested. They can top up before the timer runs out.
triplea.formExpiredThe form’s timer ran out, or its token is invalid.
triplea.badTransactionThe payment was detected as invalid.

The following listener keeps the iframe at the form’s height and shows where to react to a payment. The highlighted line splits each message into the event name and its value.

checkout.js
window.addEventListener('message', (event) => {
  if (event.origin !== 'https://cdn.triple-a.io') return;
  if (typeof event.data !== 'string') return;
  const [name, value] = event.data.split('|');

  if (name === 'triplea.frameResized') {
    document.getElementById('triplea-payment-form').style.height = `${value}px`;
  }
  if (name === 'triplea.paymentSuccess') {
    // Show a confirmation. Deliver only after the webhook reports good.
  }
});

Checking event.origin is good practice, so your page ignores messages from other frames.

Form events are not proof of payment#

The events run in the customer’s browser. Use them to update your page, and wait for the webhook and a good status before you deliver.

To embed the form without an iframe, you can use the triplea-ecommerce-payment-v1 HTML tag with the payment_reference and access_token from the response.

Receive the payment webhook

Triple-A sends an HTTP POST to your notify_url each time the payment status changes. Your endpoint verifies the signature and responds with a 2xx status. Follow these steps in your handler.

  1. Read the raw request body, before any JSON parsing.
  2. Verify the Triplea-Signature header with your notify_secret. See Verify the signature.
  3. Read payment_reference and status from the body.
  4. Respond with a 2xx status.

The following body is a shortened example of a payment notification. The highlighted lines are the payment_reference that matches your order and the status you act on.

Webhook body
{
  "event": "payment",
  "api_id": "HA123456789012_t",
  "payment_reference": "AQH-100306-PMT",
  "order_currency": "USD",
  "order_amount": 10,
  "crypto_currency": "testBTC",
  "payment_currency": "USD",
  "payment_amount": 10,
  "status": "good"
}

If you don’t respond with a 2xx status, Triple-A retries up to five times. The same notification can then arrive more than once, so make your handler safe to run twice for the same payment.

Confirm the payment and fulfil the order

Payment details

GET

GET /payment/{payment_reference}

Webhooks are the recommended way to learn about status changes. You can also read the payment directly, for example when a webhook never arrives. The highlighted line is the payment_reference you saved when you created the payment.

Request
curl --request GET \
  --url https://api.triple-a.io/api/v2/payment/AQH-100306-PMT \
  --header 'Authorization: Bearer YOUR_ACCESS_TOKEN'

The response describes the payment and its current status. The following is a shortened example response. The highlighted line is the status to act on.

Response
{
  "payment_reference": "AQH-100306-PMT",
  "order_currency": "USD",
  "order_amount": 10,
  "crypto_currency": "testBTC",
  "payment_currency": "USD",
  "payment_amount": 10,
  "status": "good"
}

Deliver only when the status is good. Any other status means you wait or don’t deliver, as described in Payment statuses. When the status is good, follow these steps.

  1. Find your order by payment_reference.
  2. Check that you haven’t already fulfilled it, because retries can repeat a notification.
  3. Mark the order paid and deliver.

Reconcile on payment_currency and payment_amount, not on order_currency. They hold the guaranteed amount in your settlement currency.

Test in the sandbox

Sandbox payments use testnet Bitcoin (testBTC) and move no real funds. They use the same host as live payments, and "sandbox": true in the payment request marks a payment as a test. In a sandbox payment, crypto_currency shows testBTC.

To pay a sandbox payment, follow these steps.

  1. Install a testnet-capable wallet, such as Unisat, and switch it to the Bitcoin test network.
  2. Request testBTC from a faucet.
  3. Send testBTC to the crypto_address shown on the payment form, for the amount shown.

Test a payment you pay in full and a payment you leave unpaid until the form expires. Check that your integration handles the webhook and the status of each one.

Go live

Live payments use the same host and the same calls as the sandbox. To switch, follow these steps.

  1. Remove "sandbox": true from your payment requests, or call Make a payment request (specific account) with your Live API ID.
  2. Complete your bank account details under Manage your profile in the dashboard, so Triple-A can settle in local currency.
  3. Request production access from your account manager or through Contact Us. No turnaround time is stated, so start early.

Common errors

These are the problems you’re most likely to meet in this flow.

  • 401 with unauthorized means the access token is missing, invalid, or expired. Request a new token, and check that the header reads Authorization: Bearer YOUR_ACCESS_TOKEN.
  • 409 with cannot_process means the payment has unfulfilled requirements, such as KYC.
  • 409 with no_select means the payer hasn’t selected a digital currency. Send the customer back to the payment form.
  • Delivering on triplea.paymentSuccess ships orders that aren’t confirmed yet. Wait for a good status.

Next steps

These pages are the best places to go next.