node
git@gitlab.com:aice-lab/payment/node.git
Latest commit
706b8432 ·
README
@aice-lab/payment
Node.js / TypeScript client SDK for the AiCE-Lab payment service.
Installation
npm install @aice-lab/payment
Usage
import { PaymentClient } from '@aice-lab/payment';
const client = new PaymentClient({
baseUrl: 'https://payment.aice-lab.org',
apiKey: process.env.PAYMENT_API_KEY!,
});
// Create a checkout
const checkout = await client.createCheckout({
orderRef: 'ORD-001',
gateway: 'bkash',
amountMinor: 50000, // 500.00 BDT in paisa
currency: 'BDT',
returnUrls: {
success: 'https://myapp.com/payment/success',
cancel: 'https://myapp.com/payment/cancel',
},
});
// Redirect the user to checkout.redirectUrl
// Later: fetch the transaction
const tx = await client.getTransaction(checkout.transactionId);
if (tx.isSucceeded()) {
// fulfil the order
}
// Refund
const refunded = await client.refund(checkout.transactionId);
Testing
Use MockPaymentClient (exported from @aice-lab/payment/mock) in your own tests:
import { MockPaymentClient } from '@aice-lab/payment/mock';
const mock = new MockPaymentClient();
// Override behavior:
mock.onGetTransaction = async (id) => ({ ... });
// Assert recorded calls:
expect(mock.lastCheckout?.orderRef).toBe('ORD-001');
Error handling
All errors extend PaymentError (with code and message). Specific subclasses:
| Class | Status |
|---|---|
UnauthorizedError | 401 |
NotFoundError | 404 |
ConflictError | 409 |
AmountMismatchError | 400, code=amount_mismatch |
BadRequestError | 400 |
GatewayUnavailableError | 503 (has retryAfterSeconds) |
TransportError | network failure |
License
FSL-1.1-Apache-2.0. See LICENSE and LICENSE.FAQ.md.
This is a snapshot generated from GitLab. For the live README, see the project page.