@fastaar/nextjs 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -10
- package/dist/client.cjs +38 -4
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +15 -4
- package/dist/client.d.ts +15 -4
- package/dist/client.js +38 -4
- package/dist/client.js.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +65 -48
- package/dist/types.d.ts +65 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ export default function CheckoutPage() {
|
|
|
52
52
|
<CheckoutButton
|
|
53
53
|
paymentParams={{
|
|
54
54
|
amount: 1250,
|
|
55
|
-
|
|
55
|
+
invoice_number: 'ORDER-42',
|
|
56
56
|
success_url: 'https://your-site.com/thanks',
|
|
57
57
|
cancel_url: 'https://your-site.com/cart',
|
|
58
58
|
metadata: { userId: 'usr_1001' },
|
|
@@ -85,7 +85,7 @@ export default function CheckoutPage() {
|
|
|
85
85
|
const fastaar = getFastaarClient();
|
|
86
86
|
const payment = await fastaar.createPayment({
|
|
87
87
|
amount: 1250,
|
|
88
|
-
|
|
88
|
+
invoice_number: 'ORDER-42',
|
|
89
89
|
success_url: 'https://your-site.com/thanks',
|
|
90
90
|
cancel_url: 'https://your-site.com/cart',
|
|
91
91
|
});
|
|
@@ -122,13 +122,13 @@ export async function POST(req: Request) {
|
|
|
122
122
|
// Handle the webhook event
|
|
123
123
|
if (event.event === 'payment.completed') {
|
|
124
124
|
const payment = event.data;
|
|
125
|
-
const
|
|
126
|
-
const trxId = payment.
|
|
127
|
-
|
|
125
|
+
const invoiceNumber = payment.invoice_number; // your order reference, e.g. 'ORDER-42'
|
|
126
|
+
const trxId = payment.customer_trx_id; // operator transaction ID
|
|
127
|
+
|
|
128
128
|
// Mark order as paid in database idempotently
|
|
129
|
-
// await db.order.update({ where: { id:
|
|
129
|
+
// await db.order.update({ where: { id: invoiceNumber }, data: { paid: true, trxId } });
|
|
130
130
|
|
|
131
|
-
console.log(`Payment completed for invoice ${
|
|
131
|
+
console.log(`Payment completed for invoice ${invoiceNumber}`);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
return new NextResponse('OK', { status: 200 });
|
|
@@ -137,7 +137,7 @@ export async function POST(req: Request) {
|
|
|
137
137
|
|
|
138
138
|
### 4. Fetching Payment Details
|
|
139
139
|
|
|
140
|
-
To manually fetch details for a payment
|
|
140
|
+
To manually fetch details for a payment:
|
|
141
141
|
|
|
142
142
|
```typescript
|
|
143
143
|
import { getFastaarClient } from '@fastaar/nextjs';
|
|
@@ -147,13 +147,49 @@ const fastaar = getFastaarClient();
|
|
|
147
147
|
// Get by Fastaar payment ID
|
|
148
148
|
const payment = await fastaar.getPayment('01jxyz...');
|
|
149
149
|
|
|
150
|
-
// Look up by your own
|
|
151
|
-
const payment = await fastaar.
|
|
150
|
+
// Look up by your own order reference
|
|
151
|
+
const payment = await fastaar.findByInvoiceNumber('ORDER-42');
|
|
152
152
|
|
|
153
153
|
// List payments
|
|
154
154
|
const payments = await fastaar.listPayments({ status: 'completed', per_page: 10 });
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
+
### 5. Refund a Payment
|
|
158
|
+
|
|
159
|
+
Refund a completed payment. Only payments with status `completed` can be refunded. A `payment.refunded` webhook fires automatically.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { getFastaarClient } from '@fastaar/nextjs';
|
|
163
|
+
|
|
164
|
+
const fastaar = getFastaarClient();
|
|
165
|
+
const payment = await fastaar.refundPayment('01jxyz...');
|
|
166
|
+
// payment.status === 'refunded'
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 6. Customers
|
|
170
|
+
|
|
171
|
+
Store customer records to attach them to payments collected via payment links.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { getFastaarClient } from '@fastaar/nextjs';
|
|
175
|
+
|
|
176
|
+
const fastaar = getFastaarClient();
|
|
177
|
+
|
|
178
|
+
// Create a customer — name and phone are required
|
|
179
|
+
const customer = await fastaar.createCustomer({
|
|
180
|
+
name: 'Rahim Uddin',
|
|
181
|
+
phone: '01712345678',
|
|
182
|
+
email: 'rahim@example.com', // optional
|
|
183
|
+
address: 'Dhaka, Bangladesh', // optional
|
|
184
|
+
notes: 'VIP customer', // optional
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Retrieve, update, list
|
|
188
|
+
const fetched = await fastaar.getCustomer(customer.id);
|
|
189
|
+
const updated = await fastaar.updateCustomer(customer.id, { name: 'Rahim Ahmed' });
|
|
190
|
+
const customers = await fastaar.listCustomers({ email: 'rahim@example.com' });
|
|
191
|
+
```
|
|
192
|
+
|
|
157
193
|
## License
|
|
158
194
|
|
|
159
195
|
MIT
|
package/dist/client.cjs
CHANGED
|
@@ -54,11 +54,14 @@ class FastaarClient {
|
|
|
54
54
|
this.apiKey = apiKey;
|
|
55
55
|
this.timeoutMs = options.timeoutMs ?? 15e3;
|
|
56
56
|
}
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Payments
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
57
60
|
/**
|
|
58
61
|
* Create a payment intent. Returns the payment object including
|
|
59
62
|
* `id`, `status`, and `checkout_url`.
|
|
60
63
|
*
|
|
61
|
-
* Reusing the same `
|
|
64
|
+
* Reusing the same `invoice_number` returns the existing payment instead of
|
|
62
65
|
* creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
|
|
63
66
|
* to return the customer to your site after checkout.
|
|
64
67
|
*/
|
|
@@ -85,12 +88,43 @@ class FastaarClient {
|
|
|
85
88
|
return this.request("GET", `/api/v1/payments${query ? `?${query}` : ""}`);
|
|
86
89
|
}
|
|
87
90
|
/**
|
|
88
|
-
* Find the most recent payment for one of your invoice
|
|
91
|
+
* Find the most recent payment for one of your invoice numbers, or null if none exist.
|
|
89
92
|
*/
|
|
90
|
-
async
|
|
91
|
-
const payments = await this.listPayments({
|
|
93
|
+
async findByInvoiceNumber(invoiceNumber) {
|
|
94
|
+
const payments = await this.listPayments({ invoice_number: invoiceNumber });
|
|
92
95
|
return payments[0] ?? null;
|
|
93
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Refund a completed payment. Only payments with status `completed` can be refunded.
|
|
99
|
+
*
|
|
100
|
+
* @returns The updated payment object with status `refunded`.
|
|
101
|
+
* @throws FastaarError if the payment is not in a refundable state.
|
|
102
|
+
*/
|
|
103
|
+
async refundPayment(paymentId) {
|
|
104
|
+
return this.request("POST", `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`);
|
|
105
|
+
}
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Customers
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
async listCustomers(params = {}) {
|
|
110
|
+
const stringParams = {};
|
|
111
|
+
for (const [key, value] of Object.entries(params)) {
|
|
112
|
+
if (value !== void 0) {
|
|
113
|
+
stringParams[key] = String(value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const query = new URLSearchParams(stringParams).toString();
|
|
117
|
+
return this.request("GET", `/api/v1/customers${query ? `?${query}` : ""}`);
|
|
118
|
+
}
|
|
119
|
+
async createCustomer(params) {
|
|
120
|
+
return this.request("POST", "/api/v1/customers", params);
|
|
121
|
+
}
|
|
122
|
+
async getCustomer(customerId) {
|
|
123
|
+
return this.request("GET", `/api/v1/customers/${customerId}`);
|
|
124
|
+
}
|
|
125
|
+
async updateCustomer(customerId, params) {
|
|
126
|
+
return this.request("PATCH", `/api/v1/customers/${customerId}`, params);
|
|
127
|
+
}
|
|
94
128
|
/**
|
|
95
129
|
* Helper to perform HTTP request to Fastaar API.
|
|
96
130
|
*/
|
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {\n CreateCustomerParams,\n CreatePaymentParams,\n Customer,\n CustomerParams,\n FastaarClientOptions,\n ListCustomersParams,\n ListPaymentsParams,\n Payment,\n} from './types';\n\nconst API_BASE_URL = 'https://fastaar.com';\n\n/**\n * Custom error class for Fastaar API errors.\n */\nexport class FastaarError extends Error {\n /**\n * The type of the error returned by the API (e.g. 'authentication_error', 'validation_error').\n */\n errorType: string;\n\n /**\n * The HTTP status code returned by the API.\n */\n statusCode: number;\n\n constructor(message: string, errorType = 'api_error', statusCode = 0) {\n super(message);\n this.name = 'FastaarError';\n this.errorType = errorType;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Client for interacting with the Fastaar Payment Gateway API.\n */\nexport class FastaarClient {\n private apiKey: string;\n private timeoutMs: number;\n\n /**\n * @param apiKey Your Fastaar API Key (fk_live_... or fk_test_...)\n * @param options Client configuration options\n */\n constructor(apiKey: string, options: FastaarClientOptions = {}) {\n if (!apiKey) {\n throw new FastaarError('API key is required to initialize FastaarClient.', 'authentication_error');\n }\n this.apiKey = apiKey;\n this.timeoutMs = options.timeoutMs ?? 15000;\n }\n\n // ---------------------------------------------------------------------------\n // Payments\n // ---------------------------------------------------------------------------\n\n /**\n * Create a payment intent. Returns the payment object including\n * `id`, `status`, and `checkout_url`.\n *\n * Reusing the same `invoice_number` returns the existing payment instead of\n * creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`\n * to return the customer to your site after checkout.\n */\n async createPayment(params: CreatePaymentParams): Promise<Payment> {\n return this.request<Payment>('POST', '/api/v1/payments', params);\n }\n\n /**\n * Retrieve a payment by its reference ID.\n */\n async getPayment(paymentId: string): Promise<Payment> {\n return this.request<Payment>('GET', `/api/v1/payments/${encodeURIComponent(paymentId)}`);\n }\n\n /**\n * List payments, newest first.\n */\n async listPayments(params: ListPaymentsParams = {}): Promise<Payment[]> {\n const stringParams: Record<string, string> = {};\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n stringParams[key] = String(value);\n }\n }\n const query = new URLSearchParams(stringParams).toString();\n return this.request<Payment[]>('GET', `/api/v1/payments${query ? `?${query}` : ''}`);\n }\n\n /**\n * Find the most recent payment for one of your invoice numbers, or null if none exist.\n */\n async findByInvoiceNumber(invoiceNumber: string): Promise<Payment | null> {\n const payments = await this.listPayments({ invoice_number: invoiceNumber });\n return payments[0] ?? null;\n }\n\n /**\n * Refund a completed payment. Only payments with status `completed` can be refunded.\n *\n * @returns The updated payment object with status `refunded`.\n * @throws FastaarError if the payment is not in a refundable state.\n */\n async refundPayment(paymentId: string): Promise<Payment> {\n return this.request<Payment>('POST', `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`);\n }\n\n // ---------------------------------------------------------------------------\n // Customers\n // ---------------------------------------------------------------------------\n\n async listCustomers(params: ListCustomersParams = {}): Promise<Customer[]> {\n const stringParams: Record<string, string> = {};\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n stringParams[key] = String(value);\n }\n }\n const query = new URLSearchParams(stringParams).toString();\n return this.request<Customer[]>('GET', `/api/v1/customers${query ? `?${query}` : ''}`);\n }\n\n async createCustomer(params: CreateCustomerParams): Promise<Customer> {\n return this.request<Customer>('POST', '/api/v1/customers', params);\n }\n\n async getCustomer(customerId: number): Promise<Customer> {\n return this.request<Customer>('GET', `/api/v1/customers/${customerId}`);\n }\n\n async updateCustomer(customerId: number, params: CustomerParams): Promise<Customer> {\n return this.request<Customer>('PATCH', `/api/v1/customers/${customerId}`, params);\n }\n\n /**\n * Helper to perform HTTP request to Fastaar API.\n */\n private async request<T>(method: string, path: string, body?: any): Promise<T> {\n let response: Response;\n\n try {\n response = await fetch(API_BASE_URL + path, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n Accept: 'application/json',\n ...(body ? { 'Content-Type': 'application/json' } : {}),\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n } catch (error: any) {\n throw new FastaarError(`Could not reach the Fastaar API: ${error.message}`, 'connection_error');\n }\n\n const payload = await response.json().catch(() => null);\n\n if (!response.ok || payload === null) {\n throw new FastaarError(\n payload?.error?.message ?? `Fastaar API returned HTTP ${response.status}.`,\n payload?.error?.type ?? 'api_error',\n response.status,\n );\n }\n\n return (payload.data ?? payload) as T;\n }\n}\n\n// Global caching pattern for Next.js hot-reloading\nconst globalForFastaar = globalThis as unknown as {\n fastaarClient?: FastaarClient;\n};\n\n/**\n * Retrieves a cached singleton instance of FastaarClient initialized with\n * environment variables (FASTAAR_API_KEY, FASTAAR_TIMEOUT_MS).\n * Useful in Next.js API route handlers, Server Actions, and Server Components.\n */\nexport function getFastaarClient(): FastaarClient {\n if (!globalForFastaar.fastaarClient) {\n const apiKey = process.env.FASTAAR_API_KEY;\n if (!apiKey) {\n throw new FastaarError(\n 'FASTAAR_API_KEY environment variable is not defined.',\n 'authentication_error'\n );\n }\n\n const timeoutMs = process.env.FASTAAR_TIMEOUT_MS\n ? parseInt(process.env.FASTAAR_TIMEOUT_MS, 10)\n : undefined;\n\n globalForFastaar.fastaarClient = new FastaarClient(apiKey, { timeoutMs });\n }\n\n return globalForFastaar.fastaarClient;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,eAAe;AAKd,MAAM,qBAAqB,MAAM;AAAA;AAAA;AAAA;AAAA,EAItC;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,YAAY,SAAiB,YAAY,aAAa,aAAa,GAAG;AACpE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,aAAa;AAAA,EACpB;AACF;AAKO,MAAM,cAAc;AAAA,EACjB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,YAAY,QAAgB,UAAgC,CAAC,GAAG;AAC9D,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,aAAa,oDAAoD,sBAAsB;AAAA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ACF;AAGA,MAAM,mBAAmB;AASlB,SAAS,mBAAkC;AAChD,MAAI,CAAC,iBAAiB,eAAe;AACnC,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,YAAY,QAAQ,IAAI,qBAC1B,SAAS,QAAQ,IAAI,oBAAoB,EAAE,IAC3C;AAEJ,qBAAiB,gBAAgB,IAAI,cAAc,QAAQ,EAAE,UAAU,CAAC;AAAA,EAC1E;AAEA,SAAO,iBAAiB;AAC1B;","names":[]}
|
package/dist/client.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams } from './types.cjs';
|
|
1
|
+
import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams, ListCustomersParams, Customer, CreateCustomerParams, CustomerParams } from './types.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Custom error class for Fastaar API errors.
|
|
@@ -29,7 +29,7 @@ declare class FastaarClient {
|
|
|
29
29
|
* Create a payment intent. Returns the payment object including
|
|
30
30
|
* `id`, `status`, and `checkout_url`.
|
|
31
31
|
*
|
|
32
|
-
* Reusing the same `
|
|
32
|
+
* Reusing the same `invoice_number` returns the existing payment instead of
|
|
33
33
|
* creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
|
|
34
34
|
* to return the customer to your site after checkout.
|
|
35
35
|
*/
|
|
@@ -43,9 +43,20 @@ declare class FastaarClient {
|
|
|
43
43
|
*/
|
|
44
44
|
listPayments(params?: ListPaymentsParams): Promise<Payment[]>;
|
|
45
45
|
/**
|
|
46
|
-
* Find the most recent payment for one of your invoice
|
|
46
|
+
* Find the most recent payment for one of your invoice numbers, or null if none exist.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
findByInvoiceNumber(invoiceNumber: string): Promise<Payment | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Refund a completed payment. Only payments with status `completed` can be refunded.
|
|
51
|
+
*
|
|
52
|
+
* @returns The updated payment object with status `refunded`.
|
|
53
|
+
* @throws FastaarError if the payment is not in a refundable state.
|
|
54
|
+
*/
|
|
55
|
+
refundPayment(paymentId: string): Promise<Payment>;
|
|
56
|
+
listCustomers(params?: ListCustomersParams): Promise<Customer[]>;
|
|
57
|
+
createCustomer(params: CreateCustomerParams): Promise<Customer>;
|
|
58
|
+
getCustomer(customerId: number): Promise<Customer>;
|
|
59
|
+
updateCustomer(customerId: number, params: CustomerParams): Promise<Customer>;
|
|
49
60
|
/**
|
|
50
61
|
* Helper to perform HTTP request to Fastaar API.
|
|
51
62
|
*/
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams } from './types.js';
|
|
1
|
+
import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams, ListCustomersParams, Customer, CreateCustomerParams, CustomerParams } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Custom error class for Fastaar API errors.
|
|
@@ -29,7 +29,7 @@ declare class FastaarClient {
|
|
|
29
29
|
* Create a payment intent. Returns the payment object including
|
|
30
30
|
* `id`, `status`, and `checkout_url`.
|
|
31
31
|
*
|
|
32
|
-
* Reusing the same `
|
|
32
|
+
* Reusing the same `invoice_number` returns the existing payment instead of
|
|
33
33
|
* creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
|
|
34
34
|
* to return the customer to your site after checkout.
|
|
35
35
|
*/
|
|
@@ -43,9 +43,20 @@ declare class FastaarClient {
|
|
|
43
43
|
*/
|
|
44
44
|
listPayments(params?: ListPaymentsParams): Promise<Payment[]>;
|
|
45
45
|
/**
|
|
46
|
-
* Find the most recent payment for one of your invoice
|
|
46
|
+
* Find the most recent payment for one of your invoice numbers, or null if none exist.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
findByInvoiceNumber(invoiceNumber: string): Promise<Payment | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Refund a completed payment. Only payments with status `completed` can be refunded.
|
|
51
|
+
*
|
|
52
|
+
* @returns The updated payment object with status `refunded`.
|
|
53
|
+
* @throws FastaarError if the payment is not in a refundable state.
|
|
54
|
+
*/
|
|
55
|
+
refundPayment(paymentId: string): Promise<Payment>;
|
|
56
|
+
listCustomers(params?: ListCustomersParams): Promise<Customer[]>;
|
|
57
|
+
createCustomer(params: CreateCustomerParams): Promise<Customer>;
|
|
58
|
+
getCustomer(customerId: number): Promise<Customer>;
|
|
59
|
+
updateCustomer(customerId: number, params: CustomerParams): Promise<Customer>;
|
|
49
60
|
/**
|
|
50
61
|
* Helper to perform HTTP request to Fastaar API.
|
|
51
62
|
*/
|
package/dist/client.js
CHANGED
|
@@ -29,11 +29,14 @@ class FastaarClient {
|
|
|
29
29
|
this.apiKey = apiKey;
|
|
30
30
|
this.timeoutMs = options.timeoutMs ?? 15e3;
|
|
31
31
|
}
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Payments
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
32
35
|
/**
|
|
33
36
|
* Create a payment intent. Returns the payment object including
|
|
34
37
|
* `id`, `status`, and `checkout_url`.
|
|
35
38
|
*
|
|
36
|
-
* Reusing the same `
|
|
39
|
+
* Reusing the same `invoice_number` returns the existing payment instead of
|
|
37
40
|
* creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
|
|
38
41
|
* to return the customer to your site after checkout.
|
|
39
42
|
*/
|
|
@@ -60,12 +63,43 @@ class FastaarClient {
|
|
|
60
63
|
return this.request("GET", `/api/v1/payments${query ? `?${query}` : ""}`);
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
|
-
* Find the most recent payment for one of your invoice
|
|
66
|
+
* Find the most recent payment for one of your invoice numbers, or null if none exist.
|
|
64
67
|
*/
|
|
65
|
-
async
|
|
66
|
-
const payments = await this.listPayments({
|
|
68
|
+
async findByInvoiceNumber(invoiceNumber) {
|
|
69
|
+
const payments = await this.listPayments({ invoice_number: invoiceNumber });
|
|
67
70
|
return payments[0] ?? null;
|
|
68
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Refund a completed payment. Only payments with status `completed` can be refunded.
|
|
74
|
+
*
|
|
75
|
+
* @returns The updated payment object with status `refunded`.
|
|
76
|
+
* @throws FastaarError if the payment is not in a refundable state.
|
|
77
|
+
*/
|
|
78
|
+
async refundPayment(paymentId) {
|
|
79
|
+
return this.request("POST", `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`);
|
|
80
|
+
}
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Customers
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
async listCustomers(params = {}) {
|
|
85
|
+
const stringParams = {};
|
|
86
|
+
for (const [key, value] of Object.entries(params)) {
|
|
87
|
+
if (value !== void 0) {
|
|
88
|
+
stringParams[key] = String(value);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const query = new URLSearchParams(stringParams).toString();
|
|
92
|
+
return this.request("GET", `/api/v1/customers${query ? `?${query}` : ""}`);
|
|
93
|
+
}
|
|
94
|
+
async createCustomer(params) {
|
|
95
|
+
return this.request("POST", "/api/v1/customers", params);
|
|
96
|
+
}
|
|
97
|
+
async getCustomer(customerId) {
|
|
98
|
+
return this.request("GET", `/api/v1/customers/${customerId}`);
|
|
99
|
+
}
|
|
100
|
+
async updateCustomer(customerId, params) {
|
|
101
|
+
return this.request("PATCH", `/api/v1/customers/${customerId}`, params);
|
|
102
|
+
}
|
|
69
103
|
/**
|
|
70
104
|
* Helper to perform HTTP request to Fastaar API.
|
|
71
105
|
*/
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {\n CreateCustomerParams,\n CreatePaymentParams,\n Customer,\n CustomerParams,\n FastaarClientOptions,\n ListCustomersParams,\n ListPaymentsParams,\n Payment,\n} from './types';\n\nconst API_BASE_URL = 'https://fastaar.com';\n\n/**\n * Custom error class for Fastaar API errors.\n */\nexport class FastaarError extends Error {\n /**\n * The type of the error returned by the API (e.g. 'authentication_error', 'validation_error').\n */\n errorType: string;\n\n /**\n * The HTTP status code returned by the API.\n */\n statusCode: number;\n\n constructor(message: string, errorType = 'api_error', statusCode = 0) {\n super(message);\n this.name = 'FastaarError';\n this.errorType = errorType;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Client for interacting with the Fastaar Payment Gateway API.\n */\nexport class FastaarClient {\n private apiKey: string;\n private timeoutMs: number;\n\n /**\n * @param apiKey Your Fastaar API Key (fk_live_... or fk_test_...)\n * @param options Client configuration options\n */\n constructor(apiKey: string, options: FastaarClientOptions = {}) {\n if (!apiKey) {\n throw new FastaarError('API key is required to initialize FastaarClient.', 'authentication_error');\n }\n this.apiKey = apiKey;\n this.timeoutMs = options.timeoutMs ?? 15000;\n }\n\n // ---------------------------------------------------------------------------\n // Payments\n // ---------------------------------------------------------------------------\n\n /**\n * Create a payment intent. Returns the payment object including\n * `id`, `status`, and `checkout_url`.\n *\n * Reusing the same `invoice_number` returns the existing payment instead of\n * creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`\n * to return the customer to your site after checkout.\n */\n async createPayment(params: CreatePaymentParams): Promise<Payment> {\n return this.request<Payment>('POST', '/api/v1/payments', params);\n }\n\n /**\n * Retrieve a payment by its reference ID.\n */\n async getPayment(paymentId: string): Promise<Payment> {\n return this.request<Payment>('GET', `/api/v1/payments/${encodeURIComponent(paymentId)}`);\n }\n\n /**\n * List payments, newest first.\n */\n async listPayments(params: ListPaymentsParams = {}): Promise<Payment[]> {\n const stringParams: Record<string, string> = {};\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n stringParams[key] = String(value);\n }\n }\n const query = new URLSearchParams(stringParams).toString();\n return this.request<Payment[]>('GET', `/api/v1/payments${query ? `?${query}` : ''}`);\n }\n\n /**\n * Find the most recent payment for one of your invoice numbers, or null if none exist.\n */\n async findByInvoiceNumber(invoiceNumber: string): Promise<Payment | null> {\n const payments = await this.listPayments({ invoice_number: invoiceNumber });\n return payments[0] ?? null;\n }\n\n /**\n * Refund a completed payment. Only payments with status `completed` can be refunded.\n *\n * @returns The updated payment object with status `refunded`.\n * @throws FastaarError if the payment is not in a refundable state.\n */\n async refundPayment(paymentId: string): Promise<Payment> {\n return this.request<Payment>('POST', `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`);\n }\n\n // ---------------------------------------------------------------------------\n // Customers\n // ---------------------------------------------------------------------------\n\n async listCustomers(params: ListCustomersParams = {}): Promise<Customer[]> {\n const stringParams: Record<string, string> = {};\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n stringParams[key] = String(value);\n }\n }\n const query = new URLSearchParams(stringParams).toString();\n return this.request<Customer[]>('GET', `/api/v1/customers${query ? `?${query}` : ''}`);\n }\n\n async createCustomer(params: CreateCustomerParams): Promise<Customer> {\n return this.request<Customer>('POST', '/api/v1/customers', params);\n }\n\n async getCustomer(customerId: number): Promise<Customer> {\n return this.request<Customer>('GET', `/api/v1/customers/${customerId}`);\n }\n\n async updateCustomer(customerId: number, params: CustomerParams): Promise<Customer> {\n return this.request<Customer>('PATCH', `/api/v1/customers/${customerId}`, params);\n }\n\n /**\n * Helper to perform HTTP request to Fastaar API.\n */\n private async request<T>(method: string, path: string, body?: any): Promise<T> {\n let response: Response;\n\n try {\n response = await fetch(API_BASE_URL + path, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n Accept: 'application/json',\n ...(body ? { 'Content-Type': 'application/json' } : {}),\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n } catch (error: any) {\n throw new FastaarError(`Could not reach the Fastaar API: ${error.message}`, 'connection_error');\n }\n\n const payload = await response.json().catch(() => null);\n\n if (!response.ok || payload === null) {\n throw new FastaarError(\n payload?.error?.message ?? `Fastaar API returned HTTP ${response.status}.`,\n payload?.error?.type ?? 'api_error',\n response.status,\n );\n }\n\n return (payload.data ?? payload) as T;\n }\n}\n\n// Global caching pattern for Next.js hot-reloading\nconst globalForFastaar = globalThis as unknown as {\n fastaarClient?: FastaarClient;\n};\n\n/**\n * Retrieves a cached singleton instance of FastaarClient initialized with\n * environment variables (FASTAAR_API_KEY, FASTAAR_TIMEOUT_MS).\n * Useful in Next.js API route handlers, Server Actions, and Server Components.\n */\nexport function getFastaarClient(): FastaarClient {\n if (!globalForFastaar.fastaarClient) {\n const apiKey = process.env.FASTAAR_API_KEY;\n if (!apiKey) {\n throw new FastaarError(\n 'FASTAAR_API_KEY environment variable is not defined.',\n 'authentication_error'\n );\n }\n\n const timeoutMs = process.env.FASTAAR_TIMEOUT_MS\n ? parseInt(process.env.FASTAAR_TIMEOUT_MS, 10)\n : undefined;\n\n globalForFastaar.fastaarClient = new FastaarClient(apiKey, { timeoutMs });\n }\n\n return globalForFastaar.fastaarClient;\n}\n"],"mappings":"AAWA,MAAM,eAAe;AAKd,MAAM,qBAAqB,MAAM;AAAA;AAAA;AAAA;AAAA,EAItC;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,YAAY,SAAiB,YAAY,aAAa,aAAa,GAAG;AACpE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,aAAa;AAAA,EACpB;AACF;AAKO,MAAM,cAAc;AAAA,EACjB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,YAAY,QAAgB,UAAgC,CAAC,GAAG;AAC9D,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,aAAa,oDAAoD,sBAAsB;AAAA,IACnG;AACA,SAAK,SAAS;AACd,SAAK,YAAY,QAAQ,aAAa;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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I;AAC3B,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,YAAY,QAAQ,IAAI,qBAC1B,SAAS,QAAQ,IAAI,oBAAoB,EAAE,IAC3C;AAEJ,qBAAiB,gBAAgB,IAAI,cAAc,QAAQ,EAAE,UAAU,CAAC;AAAA,EAC1E;AAEA,SAAO,iBAAiB;AAC1B;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent } from './types.cjs';
|
|
1
|
+
export { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent } from './types.cjs';
|
|
2
2
|
export { FastaarClient, FastaarError, getFastaarClient } from './client.cjs';
|
|
3
3
|
export { verifyNextWebhook, verifyWebhookSignature } from './webhook.cjs';
|
|
4
4
|
export { createCheckoutRedirect } from './actions.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent } from './types.js';
|
|
1
|
+
export { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent } from './types.js';
|
|
2
2
|
export { FastaarClient, FastaarError, getFastaarClient } from './client.js';
|
|
3
3
|
export { verifyNextWebhook, verifyWebhookSignature } from './webhook.js';
|
|
4
4
|
export { createCheckoutRedirect } from './actions.js';
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * Configuration options for the Fastaar client.\n */\nexport interface FastaarClientOptions {\n /**\n * Timeout in milliseconds for API requests. Defaults to 15000.\n */\n timeoutMs?: number;\n}\n\n/**\n * Parameters for creating a new payment.\n */\nexport interface CreatePaymentParams {\n /**\n * The amount to charge (can be a number or string representation of a decimal).\n */\n amount: number | string;\n\n /**\n * Your
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * Configuration options for the Fastaar client.\n */\nexport interface FastaarClientOptions {\n /**\n * Timeout in milliseconds for API requests. Defaults to 15000.\n */\n timeoutMs?: number;\n}\n\n/**\n * Parameters for creating a new payment.\n */\nexport interface CreatePaymentParams {\n /**\n * The amount to charge (can be a number or string representation of a decimal).\n */\n amount: number | string;\n\n /**\n * Your order reference / idempotency key.\n * Retrying with the same invoice_number returns the existing payment instead of creating a duplicate.\n */\n invoice_number: string;\n\n /**\n * The URL to redirect the customer to upon successful payment completion.\n */\n success_url?: string;\n\n /**\n * The URL to redirect the customer to if they cancel the checkout process.\n */\n cancel_url?: string;\n\n /**\n * Arbitrary key-value metadata to attach to the payment.\n */\n metadata?: Record<string, string>;\n}\n\n/**\n * Parameters for querying the list of payments.\n */\nexport interface ListPaymentsParams extends Record<string, string | number | undefined> {\n /**\n * Filter payments by status (e.g., 'completed', 'pending', 'cancelled').\n */\n status?: string;\n\n /**\n * Filter payments by your custom invoice/order reference.\n */\n invoice_number?: string;\n\n /**\n * Number of payments to return per page.\n */\n per_page?: number;\n\n /**\n * Page number to retrieve (for pagination).\n */\n page?: number;\n}\n\n/**\n * Representation of a payment object returned by the Fastaar API.\n */\nexport interface Payment {\n id: string;\n amount: string;\n amount_due: string;\n gateway_charge: string;\n gateway_charge_type: 'percentage' | 'fixed' | null;\n gateway_charge_value: string | null;\n currency: string;\n livemode: boolean;\n source: string;\n status: string;\n invoice_number: string;\n customer_id?: number;\n provider?: string;\n payment_method?: string;\n customer_trx_id?: string;\n customer_sender_number?: string;\n metadata?: Record<string, string>;\n failure_reason?: string;\n success_url?: string;\n cancel_url?: string;\n checkout_url: string;\n expires_at: string;\n verified_at?: string;\n created_at: string;\n}\n\n/**\n * Parameters for updating a customer (all fields optional).\n */\nexport interface CustomerParams {\n name?: string;\n phone?: string;\n email?: string | null;\n address?: string | null;\n notes?: string | null;\n}\n\n/**\n * Parameters for creating a customer.\n */\nexport interface CreateCustomerParams {\n name: string;\n phone: string;\n email?: string;\n address?: string;\n notes?: string;\n}\n\n/**\n * A customer object returned by the Fastaar API.\n */\nexport interface Customer {\n id: number;\n name: string;\n email?: string;\n phone: string;\n address?: string;\n notes?: string;\n created_at: string;\n updated_at: string;\n}\n\n/**\n * Parameters for querying the list of customers.\n */\nexport interface ListCustomersParams extends Record<string, string | number | undefined> {\n email?: string;\n phone?: string;\n per_page?: number;\n page?: number;\n}\n\n/**\n * Structure of a Fastaar Webhook event request body.\n */\nexport interface WebhookEvent {\n /**\n * The type of event (e.g., 'payment.completed').\n */\n event: string;\n\n /**\n * Indicates whether this event occurred in live mode or test mode.\n */\n livemode: boolean;\n\n /**\n * The payment object details associated with this event.\n */\n data: Payment;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
CHANGED
|
@@ -16,11 +16,10 @@ interface CreatePaymentParams {
|
|
|
16
16
|
*/
|
|
17
17
|
amount: number | string;
|
|
18
18
|
/**
|
|
19
|
-
* Your
|
|
20
|
-
*
|
|
21
|
-
* instead of creating a duplicate, ensuring idempotency.
|
|
19
|
+
* Your order reference / idempotency key.
|
|
20
|
+
* Retrying with the same invoice_number returns the existing payment instead of creating a duplicate.
|
|
22
21
|
*/
|
|
23
|
-
|
|
22
|
+
invoice_number: string;
|
|
24
23
|
/**
|
|
25
24
|
* The URL to redirect the customer to upon successful payment completion.
|
|
26
25
|
*/
|
|
@@ -45,7 +44,7 @@ interface ListPaymentsParams extends Record<string, string | number | undefined>
|
|
|
45
44
|
/**
|
|
46
45
|
* Filter payments by your custom invoice/order reference.
|
|
47
46
|
*/
|
|
48
|
-
|
|
47
|
+
invoice_number?: string;
|
|
49
48
|
/**
|
|
50
49
|
* Number of payments to return per page.
|
|
51
50
|
*/
|
|
@@ -59,54 +58,72 @@ interface ListPaymentsParams extends Record<string, string | number | undefined>
|
|
|
59
58
|
* Representation of a payment object returned by the Fastaar API.
|
|
60
59
|
*/
|
|
61
60
|
interface Payment {
|
|
62
|
-
/**
|
|
63
|
-
* Unique Fastaar transaction identifier.
|
|
64
|
-
*/
|
|
65
61
|
id: string;
|
|
66
|
-
/**
|
|
67
|
-
* The transaction amount.
|
|
68
|
-
*/
|
|
69
62
|
amount: string;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
amount_due: string;
|
|
64
|
+
gateway_charge: string;
|
|
65
|
+
gateway_charge_type: 'percentage' | 'fixed' | null;
|
|
66
|
+
gateway_charge_value: string | null;
|
|
67
|
+
currency: string;
|
|
68
|
+
livemode: boolean;
|
|
69
|
+
source: string;
|
|
77
70
|
status: string;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
checkout_url: string;
|
|
82
|
-
/**
|
|
83
|
-
* The customer's mobile number, if paid (e.g. bKash or Nagad wallet number).
|
|
84
|
-
*/
|
|
85
|
-
wallet_number?: string;
|
|
86
|
-
/**
|
|
87
|
-
* The payment method used (e.g., 'bkash', 'nagad').
|
|
88
|
-
*/
|
|
71
|
+
invoice_number: string;
|
|
72
|
+
customer_id?: number;
|
|
73
|
+
provider?: string;
|
|
89
74
|
payment_method?: string;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
trx_id?: string;
|
|
94
|
-
/**
|
|
95
|
-
* Indicates whether this payment is live or test mode.
|
|
96
|
-
*/
|
|
97
|
-
livemode: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Arbitrary metadata stored on the payment.
|
|
100
|
-
*/
|
|
75
|
+
customer_trx_id?: string;
|
|
76
|
+
customer_sender_number?: string;
|
|
101
77
|
metadata?: Record<string, string>;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
failure_reason?: string;
|
|
79
|
+
success_url?: string;
|
|
80
|
+
cancel_url?: string;
|
|
81
|
+
checkout_url: string;
|
|
82
|
+
expires_at: string;
|
|
83
|
+
verified_at?: string;
|
|
105
84
|
created_at: string;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parameters for updating a customer (all fields optional).
|
|
88
|
+
*/
|
|
89
|
+
interface CustomerParams {
|
|
90
|
+
name?: string;
|
|
91
|
+
phone?: string;
|
|
92
|
+
email?: string | null;
|
|
93
|
+
address?: string | null;
|
|
94
|
+
notes?: string | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parameters for creating a customer.
|
|
98
|
+
*/
|
|
99
|
+
interface CreateCustomerParams {
|
|
100
|
+
name: string;
|
|
101
|
+
phone: string;
|
|
102
|
+
email?: string;
|
|
103
|
+
address?: string;
|
|
104
|
+
notes?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A customer object returned by the Fastaar API.
|
|
108
|
+
*/
|
|
109
|
+
interface Customer {
|
|
110
|
+
id: number;
|
|
111
|
+
name: string;
|
|
112
|
+
email?: string;
|
|
113
|
+
phone: string;
|
|
114
|
+
address?: string;
|
|
115
|
+
notes?: string;
|
|
116
|
+
created_at: string;
|
|
117
|
+
updated_at: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parameters for querying the list of customers.
|
|
121
|
+
*/
|
|
122
|
+
interface ListCustomersParams extends Record<string, string | number | undefined> {
|
|
123
|
+
email?: string;
|
|
124
|
+
phone?: string;
|
|
125
|
+
per_page?: number;
|
|
126
|
+
page?: number;
|
|
110
127
|
}
|
|
111
128
|
/**
|
|
112
129
|
* Structure of a Fastaar Webhook event request body.
|
|
@@ -126,4 +143,4 @@ interface WebhookEvent {
|
|
|
126
143
|
data: Payment;
|
|
127
144
|
}
|
|
128
145
|
|
|
129
|
-
export type { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent };
|
|
146
|
+
export type { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent };
|
package/dist/types.d.ts
CHANGED
|
@@ -16,11 +16,10 @@ interface CreatePaymentParams {
|
|
|
16
16
|
*/
|
|
17
17
|
amount: number | string;
|
|
18
18
|
/**
|
|
19
|
-
* Your
|
|
20
|
-
*
|
|
21
|
-
* instead of creating a duplicate, ensuring idempotency.
|
|
19
|
+
* Your order reference / idempotency key.
|
|
20
|
+
* Retrying with the same invoice_number returns the existing payment instead of creating a duplicate.
|
|
22
21
|
*/
|
|
23
|
-
|
|
22
|
+
invoice_number: string;
|
|
24
23
|
/**
|
|
25
24
|
* The URL to redirect the customer to upon successful payment completion.
|
|
26
25
|
*/
|
|
@@ -45,7 +44,7 @@ interface ListPaymentsParams extends Record<string, string | number | undefined>
|
|
|
45
44
|
/**
|
|
46
45
|
* Filter payments by your custom invoice/order reference.
|
|
47
46
|
*/
|
|
48
|
-
|
|
47
|
+
invoice_number?: string;
|
|
49
48
|
/**
|
|
50
49
|
* Number of payments to return per page.
|
|
51
50
|
*/
|
|
@@ -59,54 +58,72 @@ interface ListPaymentsParams extends Record<string, string | number | undefined>
|
|
|
59
58
|
* Representation of a payment object returned by the Fastaar API.
|
|
60
59
|
*/
|
|
61
60
|
interface Payment {
|
|
62
|
-
/**
|
|
63
|
-
* Unique Fastaar transaction identifier.
|
|
64
|
-
*/
|
|
65
61
|
id: string;
|
|
66
|
-
/**
|
|
67
|
-
* The transaction amount.
|
|
68
|
-
*/
|
|
69
62
|
amount: string;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
amount_due: string;
|
|
64
|
+
gateway_charge: string;
|
|
65
|
+
gateway_charge_type: 'percentage' | 'fixed' | null;
|
|
66
|
+
gateway_charge_value: string | null;
|
|
67
|
+
currency: string;
|
|
68
|
+
livemode: boolean;
|
|
69
|
+
source: string;
|
|
77
70
|
status: string;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
checkout_url: string;
|
|
82
|
-
/**
|
|
83
|
-
* The customer's mobile number, if paid (e.g. bKash or Nagad wallet number).
|
|
84
|
-
*/
|
|
85
|
-
wallet_number?: string;
|
|
86
|
-
/**
|
|
87
|
-
* The payment method used (e.g., 'bkash', 'nagad').
|
|
88
|
-
*/
|
|
71
|
+
invoice_number: string;
|
|
72
|
+
customer_id?: number;
|
|
73
|
+
provider?: string;
|
|
89
74
|
payment_method?: string;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
trx_id?: string;
|
|
94
|
-
/**
|
|
95
|
-
* Indicates whether this payment is live or test mode.
|
|
96
|
-
*/
|
|
97
|
-
livemode: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Arbitrary metadata stored on the payment.
|
|
100
|
-
*/
|
|
75
|
+
customer_trx_id?: string;
|
|
76
|
+
customer_sender_number?: string;
|
|
101
77
|
metadata?: Record<string, string>;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
failure_reason?: string;
|
|
79
|
+
success_url?: string;
|
|
80
|
+
cancel_url?: string;
|
|
81
|
+
checkout_url: string;
|
|
82
|
+
expires_at: string;
|
|
83
|
+
verified_at?: string;
|
|
105
84
|
created_at: string;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parameters for updating a customer (all fields optional).
|
|
88
|
+
*/
|
|
89
|
+
interface CustomerParams {
|
|
90
|
+
name?: string;
|
|
91
|
+
phone?: string;
|
|
92
|
+
email?: string | null;
|
|
93
|
+
address?: string | null;
|
|
94
|
+
notes?: string | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parameters for creating a customer.
|
|
98
|
+
*/
|
|
99
|
+
interface CreateCustomerParams {
|
|
100
|
+
name: string;
|
|
101
|
+
phone: string;
|
|
102
|
+
email?: string;
|
|
103
|
+
address?: string;
|
|
104
|
+
notes?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A customer object returned by the Fastaar API.
|
|
108
|
+
*/
|
|
109
|
+
interface Customer {
|
|
110
|
+
id: number;
|
|
111
|
+
name: string;
|
|
112
|
+
email?: string;
|
|
113
|
+
phone: string;
|
|
114
|
+
address?: string;
|
|
115
|
+
notes?: string;
|
|
116
|
+
created_at: string;
|
|
117
|
+
updated_at: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parameters for querying the list of customers.
|
|
121
|
+
*/
|
|
122
|
+
interface ListCustomersParams extends Record<string, string | number | undefined> {
|
|
123
|
+
email?: string;
|
|
124
|
+
phone?: string;
|
|
125
|
+
per_page?: number;
|
|
126
|
+
page?: number;
|
|
110
127
|
}
|
|
111
128
|
/**
|
|
112
129
|
* Structure of a Fastaar Webhook event request body.
|
|
@@ -126,4 +143,4 @@ interface WebhookEvent {
|
|
|
126
143
|
data: Payment;
|
|
127
144
|
}
|
|
128
145
|
|
|
129
|
-
export type { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent };
|
|
146
|
+
export type { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent };
|