JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 50
  • Score
    100M100P100Q57563F
  • License ISC

Payment SDK pour l'API Ariary

Package Exports

  • @ariary/pay

Readme

@ariary/pay

Payment and product SDK for the Ariary API.

Install

yarn add @ariary/pay

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()

// delete
await Ariari.products.delete(product.id)

Create a Payment

Ariari.create() returns a Payment object with the generated payment URL.

// with amount
const payment = await Ariari.create({ amount: 5000 })

// with product
const payment = await Ariari.create({ productId: product.id })

// with hooks and metadata
const payment = await Ariari.create({
  amount: 10000,
  name: 'T-shirt bleu',
  imgUrl: 'https://example.com/img.png',
  hooks: {
    success: 'https://example.com/success',
    failure: 'https://example.com/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: pending | incomplete | paid | 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().

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).