js
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:
| Class | Trigger |
|---|---|
UnauthorizedError | 401 |
NotFoundError | 404 |
ConflictError | 409 |
AmountMismatchError | 400 + amount_mismatch |
BadRequestError | 400 |
GatewayUnavailableError | 503 — check .retryAfterSeconds |
TransportError | Network 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.