Package Exports
- @ariary/pay
Readme
@ariary/pay
Payment and product SDK for the Ariary API.
Install
yarn add @ariary/payGet your credentials
- Sign in at ariari.mg
- Create a project
- You'll receive a
projectIdand asecret
Setup
import Ariari from '@ariary/pay'
Ariari.config({
projectId: 'your-project-id',
secret: 'your-secret',
})Products
Manage products linked to your project.
// create
const product = await Ariari.products.create({ name: 'Forfait Premium', price: 5000, imgUrl: 'https://example.com/img.png' })
// list all
const products = await Ariari.products.list()
// update
const updated = await Ariari.products.update(product.id, { name: 'Forfait Gold', price: 8000 })
// delete
await Ariari.products.delete(product.id)Create a Payment
Ariari.create() returns a Payment object with id and url.
| Field | Type | Required | Description |
|---|---|---|---|
productId |
string | No | Product ID — resolves amount, name, imgUrl automatically |
amount |
number | Yes (without productId) |
Payment amount in Ariary |
name |
string | No | Payment label |
imgUrl |
string | No | Image URL for the payment page |
hooks.redirectSuccess |
string | No | Redirect URL on payment success |
hooks.redirectFailure |
string | No | Redirect URL on payment failure |
hooks.silentSuccess |
string | No | Webhook called when payment is fully completed |
hooks.silentProgress |
string | No | Webhook called on each partial payment |
hooks.silentFailure |
string | No | Webhook called on payment failure |
Important: silent* hooks are server-to-server webhooks called from the Ariary backend. They must be publicly accessible URLs with a valid domain name (e.g. https://yoursite.com/api/webhook). localhost or local IPs will not work — use a tunneling service like ngrok for development. redirect* hooks are client-side redirects and have no such restriction.
// with amount only
const payment = await Ariari.create({ amount: 5000 })
console.log(payment.url) // https://pay.ariari.mg/abc123encrypted
// with product (amount, name, imgUrl resolved automatically)
const payment = await Ariari.create({ productId: product.id })
// with product + override
const payment = await Ariari.create({ productId: product.id, amount: 3000 })
// with hooks
const payment = await Ariari.create({
amount: 10000,
name: 'T-shirt bleu',
imgUrl: 'https://example.com/img.png',
hooks: {
redirectSuccess: 'https://yoursite.com/payment/success',
redirectFailure: 'https://yoursite.com/payment/failure',
silentSuccess: 'https://yoursite.com/api/webhook/payment-success',
silentProgress: 'https://yoursite.com/api/webhook/payment-progress',
silentFailure: 'https://yoursite.com/api/webhook/payment-failure',
},
})Track a Payment
const payment = await Ariari.create({ amount: 5000 })
// check status
const info = await payment.status()
// { id, amount, rest, status, parts, url, ... }
// apply a ticket code
const result = await payment.pay('Y-1234')Payment statuses: Status.PENDING | Status.INCOMPLETE | Status.PAID | Status.FAILED
A Status enum is also exported:
import { Status } from '@ariary/pay'
if (info.status === Status.PAID) { ... }Retrieve an existing Payment
Store payment.id to retrieve it later with .getPayment(). Calling .status() returns the full payment details:
| Field | Type | Description |
|---|---|---|
id |
string | Payment ID |
amount |
number | Total amount in Ariary |
rest |
number | Remaining amount to pay |
productId |
string? | Linked product ID |
name |
string? | Payment label |
imgUrl |
string? | Image URL |
status |
Status | PENDING | INCOMPLETE | PAID | FAILED |
parts |
PaymentPart[] | List of partial payments |
createdAt |
string | Creation date |
updatedAt |
string | Last update date |
url |
string | Payment page URL |
const payment = await Ariari.create({ amount: 5000 })
const paymentId = payment.id // save this
// later
const payment = Ariari.getPayment(paymentId)
const info = await payment.status()Multiple instances
Use name to manage separate Ariari instances with different credentials. Ariari.config() returns the instance directly.
const shop = Ariari.config({
name: 'shop',
projectId: 'project-a',
secret: 'secret-a',
})
const billing = Ariari.config({
name: 'billing',
projectId: 'project-b',
secret: 'secret-b',
})
await shop.create({ amount: 5000 })
await billing.create({ productId: 'prod-123' })You can also retrieve a named instance later with Ariari.get().
const shop = Ariari.get('shop')Without name, the instance defaults to "main" and is used by static methods (Ariari.create, Ariari.products, Ariari.getPayment).