rn
git@gitlab.com:aice-lab/payment/rn.git
Latest commit
e4e5b0ce ·
README
@aice-lab/payment-rn
React Native (TypeScript) client SDK for the AiCE-Lab payment service.
Installation
npm install @aice-lab/payment-rn
Usage
import { HttpPaymentClient } from '@aice-lab/payment-rn';
const client = new HttpPaymentClient({
baseUrl: 'https://pay.example.com',
apiKey: 'your-api-key',
});
// Create a checkout
const { transactionId, redirectUrl } = await client.createCheckout({
orderRef: 'ORD-001',
gateway: 'bkash',
amountMinor: 50000, // 500 BDT in poisha
currency: 'BDT',
returnUrls: { success: 'myapp://payment/success', cancel: 'myapp://payment/cancel' },
});
// Poll a transaction
const tx = await client.getTransaction(transactionId);
if (tx.isSucceeded()) { /* ... */ }
// Refund
const refunded = await client.refund(transactionId);
Testing
Use MockPaymentClient to stub the client in consumer tests without network calls:
import { MockPaymentClient } from '@aice-lab/payment-rn';
const mock = new MockPaymentClient();
mock.onCreateCheckout = async (req) => ({ transactionId: 'tx-test', redirectUrl: 'https://mock' });
Errors
All methods throw a PaymentError subclass on failure:
| Class | Status |
|---|---|
UnauthorizedError | 401 |
NotFoundError | 404 |
ConflictError | 409 |
AmountMismatchError | 400 + amount_mismatch |
BadRequestError | 400 |
GatewayUnavailableError | 503 (has retryAfterSeconds) |
TransportError | network failure |
License
FSL-1.1-Apache-2.0 — see LICENSE.
This is a snapshot generated from GitLab. For the live README, see the project page.