← All projects

js

  • TypeScript 100%
git@gitlab.com:aice-lab/payment/js.git

Latest commit

391fb132 ·

README

@aice-lab/payment-js

Browser TypeScript client SDK for the AiCE-Lab payment service.

Install

npm install @aice-lab/payment-js

Usage

import { HttpPaymentClient } from '@aice-lab/payment-js';

const client = new HttpPaymentClient({
  baseUrl: 'https://payment.aice-lab.org',
  apiKey: 'your-api-key',
});

// Create a checkout session
const checkout = await client.createCheckout({
  orderRef: 'ORD-001',
  gateway: 'bkash',
  amountMinor: 50000,   // 500.00 BDT in paisa
  currency: 'BDT',
  returnUrls: { success: 'https://app.example/ok', cancel: 'https://app.example/cancel' },
});
// Redirect the user to checkout.redirectUrl

// Retrieve a transaction
const tx = await client.getTransaction(checkout.transactionId);
if (tx.isSucceeded()) {
  // fulfil the order
}

// Refund
const refunded = await client.refund(tx.transactionId);

Testing

Import MockPaymentClient in your tests — no network required:

import { MockPaymentClient } from '@aice-lab/payment-js';

const mock = new MockPaymentClient();
// Optionally override behaviour:
mock.onCreateCheckout = () => ({ transactionId: 'test-tx', redirectUrl: 'https://mock' });

Errors

All errors extend PaymentError. Specific subclasses:

ClassTrigger
UnauthorizedError401
NotFoundError404
ConflictError409
AmountMismatchError400 + amount_mismatch
BadRequestError400
GatewayUnavailableError503 — check .retryAfterSeconds
TransportErrorNetwork failure before a response

License

FSL-1.1-Apache-2.0 — see LICENSE.

This is a snapshot generated from GitLab. For the live README, see the project page.