Skip to content

Accept a payment

A vPOS payment has three steps: you register it, the payer pays on the bank’s page, and you verify the result.

create-payment.ts
import { ameria } from "./client.js";
const payment = await ameria.initPayment({
orderId: 2350301, // in test, use an ID from the range the bank gave you
amount: 10, // the test environment only accepts 10 AMD
currency: "AMD",
description: "Order #1042",
backUrl: "https://shop.example/payment/back",
opaque: "order-1042",
lang: "en",
});
if (payment.url) {
// Send the payer to the bank's card page.
console.log("Redirect to", payment.url);
} else {
console.error("Bank refused:", payment.ResponseMessage);
}

ResponseCode is 1 when the bank accepted the request; only then is url set. Store the returned PaymentID with your order.

Option Notes
orderId Unique per payment. In the test environment it must be in your assigned range.
amount In the payment currency.
currency "AMD" (default), "USD", "EUR", "RUB" or the ISO numeric code.
backUrl Where the payer returns to.
opaque Free text you get back with the payment details.
lang Payment page language: "en", "am" (or "hy"), "ru".
timeout Seconds the payment page stays valid.
cardHolderId Saves the card for later — see Saved cards.

Send the payer to url. The bank’s page collects the card details and runs 3-D Secure.

The payer returns to your backUrl with orderID, paymentID, opaque and a response code in the query string. That redirect is not signed — anyone can open your backUrl with a success code. Always ask the bank:

verify-payment.ts
import { ameria } from "./client.js";
/**
* Handle the payer coming back to your backUrl.
* The query string is not signed: never trust it, ask the bank instead.
*/
export async function handleBackUrl(
url: URL,
order: { id: number; total: number },
) {
const paymentId = url.searchParams.get("paymentID");
if (!paymentId) return false;
const { paid, reason } = await ameria.verifyPayment(paymentId, {
amount: order.total,
currency: "AMD",
orderId: order.id,
});
if (!paid) console.warn(`Order ${order.id} not paid: ${reason}`);
return paid;
}

verifyPayment returns paid: true only when all of these hold:

  • the bank approved the payment (ResponseCode is "00");
  • the amount, currency and order ID match what you passed;
  • the money was deposited (for two-step payments, pass twoStep: true to accept an approved payment);
  • nothing has been refunded.

Otherwise reason says which check failed, and details holds the bank’s full answer.