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.
You need the following.
These pages explain the product and how a payment flows.
What the product does and how a payment flows from payer to settlement.
What each status means and which one lets you deliver.
Follow these steps in order.
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.
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.
{
"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.
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.
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.
| Field | Required | Notes |
|---|---|---|
type | Yes | widget returns a payment form to embed in your page. |
merchant_key | Yes | Identifies your merchant account. You receive it when you sign up. |
order_currency, order_amount | Yes | The price, with a 3-character ISO 4217 currency code. |
payer_id | Recommended | A 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_id | Optional | Your own reference, up to 255 characters. |
notify_url, notify_secret | Optional | Where 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. |
sandbox | For testing | true 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.
The following is an example response. The highlighted line is the hosted_url of the form, which you load in the next step.
{
"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.
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.
<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.
| Parameter | Effect |
|---|---|
lang=fr | Shows the form in another language. It supports 13 languages and defaults to the customer’s browser language. |
order_details=hide | Hides the order details. |
open_wallet_button=hide | Hides 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.
| Event | When it fires |
|---|---|
triplea.frameResized | The form changed height. The new height in pixels follows the event name. |
triplea.paymentSuccess | The customer completed the payment. |
triplea.paymentTooLittle | The customer paid less than requested. They can top up before the timer runs out. |
triplea.formExpired | The form’s timer ran out, or its token is invalid. |
triplea.badTransaction | The 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.
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.
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.
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.
Triplea-Signature header with your notify_secret. See Verify the signature.payment_reference and status from the body.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.
{
"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.
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.
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.
{
"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.
payment_reference.Reconcile on payment_currency and payment_amount, not on order_currency. They hold the guaranteed amount in your settlement currency.
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.
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.
Live payments use the same host and the same calls as the sandbox. To switch, follow these steps.
"sandbox": true from your payment requests, or call Make a payment request (specific account) with your Live API ID.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.triplea.paymentSuccess ships orders that aren’t confirmed yet. Wait for a good status.These pages are the best places to go next.
The same payment, with the customer redirected to a Triple-A page.
Every webhook field, retries, and a signature verification example.