JavaScript API
For order pages that send the order with fetch or AJAX instead of submitting a form.
Check an order before sending it#
Call Antiro.decide() when the shopper presses the order button, and send its token with the order. The script may not have loaded, so check for it first and send the order anyway: your server check still runs.
async function placeOrder(order) {
const check = window.Antiro
? await window.Antiro.decide({
phone: order.phone,
name: order.name,
address: order.address,
})
: { act: 'allow', token: '' };
// notice or block: the shopper saw a message
if (check.act !== 'allow') return;
await fetch('/api/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
...order,
session_token: check.token,
}),
});
} What decide returns#
Antiro.decide() resolves to { act, token }:
act | Meaning | What to do |
|---|---|---|
allow | The order can go. Also returned on any failure. | Send the order, with token as session_token. |
notice | The shopper was asked to change something on their side. | Do not send. Call decide() again at the next press. |
block | The shopper saw the refusal message. | Do not send. |
Reference#
- Antiro.decide(contact) Promise
Checks the order.
contactholdsphone,nameandaddress, all optional. Each call runs one check, and a call made while a check is running shares its answer.- Antiro.token() string
The current order reference, to send as
session_token.- Antiro.ready() Promise
Settles once the script has tried to start its session.
- Antiro.verdict() string
botwhen Antiro judged this tab automated,okwhen it answered, otherwiseunknown.- Antiro.version string
The script’s version.