@fastaar/nextjs 0.1.2 → 0.1.4

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 CHANGED
@@ -32,6 +32,10 @@ FASTAAR_API_KEY="fk_live_..."
32
32
  FASTAAR_WEBHOOK_SECRET="whsec_..."
33
33
  ```
34
34
 
35
+ Keys are scoped to abilities (`payments:read`/`write`/`refund`, `customers:read`/`write`) and can have an
36
+ expiry date, set in the merchant panel. Calls outside the key's abilities return `403 ability_denied`;
37
+ calls with an expired key return `401 authentication_error`.
38
+
35
39
  ---
36
40
 
37
41
  ## Usage
@@ -86,6 +90,7 @@ export default function CheckoutPage() {
86
90
  const payment = await fastaar.createPayment({
87
91
  amount: 1250,
88
92
  invoice_number: 'ORDER-42',
93
+ customer_id: customer?.id, // optional — attach an existing customer
89
94
  success_url: 'https://your-site.com/thanks',
90
95
  cancel_url: 'https://your-site.com/cart',
91
96
  });
@@ -164,6 +169,11 @@ import { getFastaarClient } from '@fastaar/nextjs';
164
169
  const fastaar = getFastaarClient();
165
170
  const payment = await fastaar.refundPayment('01jxyz...');
166
171
  // payment.status === 'refunded'
172
+
173
+ const partial = await fastaar.refundPayment('01jxyz...', 200); // refund only part of it
174
+ // partial.status === 'partially_refunded'
175
+
176
+ const refunds = await fastaar.listRefunds('01jxyz...'); // full refund history, newest first
167
177
  ```
168
178
 
169
179
  ### 6. Customers
package/dist/client.cjs CHANGED
@@ -61,9 +61,11 @@ class FastaarClient {
61
61
  * Create a payment intent. Returns the payment object including
62
62
  * `id`, `status`, and `checkout_url`.
63
63
  *
64
- * Reusing the same `invoice_number` returns the existing payment instead of
65
- * creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
66
- * to return the customer to your site after checkout.
64
+ * Reusing the same `invoice_number` while a previous payment for it is still
65
+ * active (not `failed`/`expired`) throws a FastaarError with errorType
66
+ * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate — look
67
+ * the existing payment up with `findByInvoiceNumber()` rather than retrying blindly.
68
+ * Supply `success_url`/`cancel_url` to return the customer to your site after checkout.
67
69
  */
68
70
  async createPayment(params) {
69
71
  return this.request("POST", "/api/v1/payments", params);
@@ -95,13 +97,28 @@ class FastaarClient {
95
97
  return payments[0] ?? null;
96
98
  }
97
99
  /**
98
- * Refund a completed payment. Only payments with status `completed` can be refunded.
100
+ * Refund a payment, in full or in part. Only payments with status `completed` or
101
+ * `partially_refunded` can be refunded. Pass an amount to refund only part of the
102
+ * remaining balance; omit it to refund whatever is still refundable.
99
103
  *
100
- * @returns The updated payment object with status `refunded`.
101
- * @throws FastaarError if the payment is not in a refundable state.
104
+ * @returns The updated payment object. `status` is `refunded` once fully refunded,
105
+ * or `partially_refunded` if some balance remains.
106
+ * @throws FastaarError if the payment is not in a refundable state, or the amount
107
+ * exceeds the remaining refundable balance.
102
108
  */
103
- async refundPayment(paymentId) {
104
- return this.request("POST", `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`);
109
+ async refundPayment(paymentId, amount) {
110
+ return this.request(
111
+ "POST",
112
+ `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`,
113
+ amount !== void 0 ? { amount } : void 0
114
+ );
115
+ }
116
+ /**
117
+ * List a payment's refund history, newest first — one entry per refund call, even
118
+ * across several partial refunds.
119
+ */
120
+ async listRefunds(paymentId) {
121
+ return this.request("GET", `/api/v1/payments/${encodeURIComponent(paymentId)}/refunds`);
105
122
  }
106
123
  // ---------------------------------------------------------------------------
107
124
  // Customers
@@ -1 +1 @@
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,IACnG;AACA,SAAK,SAAS;AACd,SAAK,YAAY,QAAQ,aAAa;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,cAAc,QAA+C;AACjE,WAAO,KAAK,QAAiB,QAAQ,oBAAoB,MAAM;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW,WAAqC;AACpD,WAA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,qBAAiB,gBAAgB,IAAI,cAAc,QAAQ,EAAE,UAAU,CAAC;AAAA,EAC1E;AAEA,SAAO,iBAAiB;AAC1B;","names":[]}
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 Refund,\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` while a previous payment for it is still\n * active (not `failed`/`expired`) throws a FastaarError with errorType\n * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate — look\n * the existing payment up with `findByInvoiceNumber()` rather than retrying blindly.\n * Supply `success_url`/`cancel_url` 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 payment, in full or in part. Only payments with status `completed` or\n * `partially_refunded` can be refunded. Pass an amount to refund only part of the\n * remaining balance; omit it to refund whatever is still refundable.\n *\n * @returns The updated payment object. `status` is `refunded` once fully refunded,\n * or `partially_refunded` if some balance remains.\n * @throws FastaarError if the payment is not in a refundable state, or the amount\n * exceeds the remaining refundable balance.\n */\n async refundPayment(paymentId: string, amount?: number | string): Promise<Payment> {\n return this.request<Payment>(\n 'POST',\n `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`,\n amount !== undefined ? { amount } : undefined,\n );\n }\n\n /**\n * List a payment's refund history, newest first — one entry per refund call, even\n * across several partial refunds.\n */\n async listRefunds(paymentId: string): Promise<Refund[]> {\n return this.request<Refund[]>('GET', `/api/v1/payments/${encodeURIComponent(paymentId)}/refunds`);\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 }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CustomersParams, Customer, CreateCustomerParams, CustomerParams } from './types.cjs';
1
+ import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams, Refund, ListCustomersParams, Customer, CreateCustomerParams, CustomerParams } from './types.cjs';
2
2
 
3
3
  /**
4
4
  * Custom error class for Fastaar API errors.
@@ -29,9 +29,11 @@ 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 `invoice_number` returns the existing payment instead of
33
- * creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
34
- * to return the customer to your site after checkout.
32
+ * Reusing the same `invoice_number` while a previous payment for it is still
33
+ * active (not `failed`/`expired`) throws a FastaarError with errorType
34
+ * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate — look
35
+ * the existing payment up with `findByInvoiceNumber()` rather than retrying blindly.
36
+ * Supply `success_url`/`cancel_url` to return the customer to your site after checkout.
35
37
  */
36
38
  createPayment(params: CreatePaymentParams): Promise<Payment>;
37
39
  /**
@@ -47,12 +49,21 @@ declare class FastaarClient {
47
49
  */
48
50
  findByInvoiceNumber(invoiceNumber: string): Promise<Payment | null>;
49
51
  /**
50
- * Refund a completed payment. Only payments with status `completed` can be refunded.
52
+ * Refund a payment, in full or in part. Only payments with status `completed` or
53
+ * `partially_refunded` can be refunded. Pass an amount to refund only part of the
54
+ * remaining balance; omit it to refund whatever is still refundable.
51
55
  *
52
- * @returns The updated payment object with status `refunded`.
53
- * @throws FastaarError if the payment is not in a refundable state.
56
+ * @returns The updated payment object. `status` is `refunded` once fully refunded,
57
+ * or `partially_refunded` if some balance remains.
58
+ * @throws FastaarError if the payment is not in a refundable state, or the amount
59
+ * exceeds the remaining refundable balance.
54
60
  */
55
- refundPayment(paymentId: string): Promise<Payment>;
61
+ refundPayment(paymentId: string, amount?: number | string): Promise<Payment>;
62
+ /**
63
+ * List a payment's refund history, newest first — one entry per refund call, even
64
+ * across several partial refunds.
65
+ */
66
+ listRefunds(paymentId: string): Promise<Refund[]>;
56
67
  listCustomers(params?: ListCustomersParams): Promise<Customer[]>;
57
68
  createCustomer(params: CreateCustomerParams): Promise<Customer>;
58
69
  getCustomer(customerId: number): Promise<Customer>;
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams, ListCustomersParams, Customer, CreateCustomerParams, CustomerParams } from './types.js';
1
+ import { FastaarClientOptions, CreatePaymentParams, Payment, ListPaymentsParams, Refund, ListCustomersParams, Customer, CreateCustomerParams, CustomerParams } from './types.js';
2
2
 
3
3
  /**
4
4
  * Custom error class for Fastaar API errors.
@@ -29,9 +29,11 @@ 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 `invoice_number` returns the existing payment instead of
33
- * creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
34
- * to return the customer to your site after checkout.
32
+ * Reusing the same `invoice_number` while a previous payment for it is still
33
+ * active (not `failed`/`expired`) throws a FastaarError with errorType
34
+ * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate — look
35
+ * the existing payment up with `findByInvoiceNumber()` rather than retrying blindly.
36
+ * Supply `success_url`/`cancel_url` to return the customer to your site after checkout.
35
37
  */
36
38
  createPayment(params: CreatePaymentParams): Promise<Payment>;
37
39
  /**
@@ -47,12 +49,21 @@ declare class FastaarClient {
47
49
  */
48
50
  findByInvoiceNumber(invoiceNumber: string): Promise<Payment | null>;
49
51
  /**
50
- * Refund a completed payment. Only payments with status `completed` can be refunded.
52
+ * Refund a payment, in full or in part. Only payments with status `completed` or
53
+ * `partially_refunded` can be refunded. Pass an amount to refund only part of the
54
+ * remaining balance; omit it to refund whatever is still refundable.
51
55
  *
52
- * @returns The updated payment object with status `refunded`.
53
- * @throws FastaarError if the payment is not in a refundable state.
56
+ * @returns The updated payment object. `status` is `refunded` once fully refunded,
57
+ * or `partially_refunded` if some balance remains.
58
+ * @throws FastaarError if the payment is not in a refundable state, or the amount
59
+ * exceeds the remaining refundable balance.
54
60
  */
55
- refundPayment(paymentId: string): Promise<Payment>;
61
+ refundPayment(paymentId: string, amount?: number | string): Promise<Payment>;
62
+ /**
63
+ * List a payment's refund history, newest first — one entry per refund call, even
64
+ * across several partial refunds.
65
+ */
66
+ listRefunds(paymentId: string): Promise<Refund[]>;
56
67
  listCustomers(params?: ListCustomersParams): Promise<Customer[]>;
57
68
  createCustomer(params: CreateCustomerParams): Promise<Customer>;
58
69
  getCustomer(customerId: number): Promise<Customer>;
package/dist/client.js CHANGED
@@ -36,9 +36,11 @@ class FastaarClient {
36
36
  * Create a payment intent. Returns the payment object including
37
37
  * `id`, `status`, and `checkout_url`.
38
38
  *
39
- * Reusing the same `invoice_number` returns the existing payment instead of
40
- * creating a duplicate, so retries are safe. Supply `success_url`/`cancel_url`
41
- * to return the customer to your site after checkout.
39
+ * Reusing the same `invoice_number` while a previous payment for it is still
40
+ * active (not `failed`/`expired`) throws a FastaarError with errorType
41
+ * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate — look
42
+ * the existing payment up with `findByInvoiceNumber()` rather than retrying blindly.
43
+ * Supply `success_url`/`cancel_url` to return the customer to your site after checkout.
42
44
  */
43
45
  async createPayment(params) {
44
46
  return this.request("POST", "/api/v1/payments", params);
@@ -70,13 +72,28 @@ class FastaarClient {
70
72
  return payments[0] ?? null;
71
73
  }
72
74
  /**
73
- * Refund a completed payment. Only payments with status `completed` can be refunded.
75
+ * Refund a payment, in full or in part. Only payments with status `completed` or
76
+ * `partially_refunded` can be refunded. Pass an amount to refund only part of the
77
+ * remaining balance; omit it to refund whatever is still refundable.
74
78
  *
75
- * @returns The updated payment object with status `refunded`.
76
- * @throws FastaarError if the payment is not in a refundable state.
79
+ * @returns The updated payment object. `status` is `refunded` once fully refunded,
80
+ * or `partially_refunded` if some balance remains.
81
+ * @throws FastaarError if the payment is not in a refundable state, or the amount
82
+ * exceeds the remaining refundable balance.
77
83
  */
78
- async refundPayment(paymentId) {
79
- return this.request("POST", `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`);
84
+ async refundPayment(paymentId, amount) {
85
+ return this.request(
86
+ "POST",
87
+ `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`,
88
+ amount !== void 0 ? { amount } : void 0
89
+ );
90
+ }
91
+ /**
92
+ * List a payment's refund history, newest first — one entry per refund call, even
93
+ * across several partial refunds.
94
+ */
95
+ async listRefunds(paymentId) {
96
+ return this.request("GET", `/api/v1/payments/${encodeURIComponent(paymentId)}/refunds`);
80
97
  }
81
98
  // ---------------------------------------------------------------------------
82
99
  // Customers
@@ -1 +1 @@
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;AAA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,SAAS,OAAY;AACnB,YAAM,IAAI,aAAa,oCAAoC,MAAM,OAAO,IAAI,kBAAkB;AAAA,IAChG;AAEA,UAAM,UAAU,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,IAAI;AAEtD,QAAI,CAAC,SAAS,MAAM,YAAY,MAAM;AACpC,YAAM,IAAI;AAAA,QACR,SAAS,OAAO,WAAW,6BAA6B,SAAS,MAAM;AAAA,QACvE,SAAS,OAAO,QAAQ;AAAA,QACxB,SAAS;AAAA,MACX;AAAA,IACF;AAEA,WAAQ,QAAQ,QAAQ;AAAA,EAC1B;AACF;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":[]}
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 Refund,\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` while a previous payment for it is still\n * active (not `failed`/`expired`) throws a FastaarError with errorType\n * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate — look\n * the existing payment up with `findByInvoiceNumber()` rather than retrying blindly.\n * Supply `success_url`/`cancel_url` 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 payment, in full or in part. Only payments with status `completed` or\n * `partially_refunded` can be refunded. Pass an amount to refund only part of the\n * remaining balance; omit it to refund whatever is still refundable.\n *\n * @returns The updated payment object. `status` is `refunded` once fully refunded,\n * or `partially_refunded` if some balance remains.\n * @throws FastaarError if the payment is not in a refundable state, or the amount\n * exceeds the remaining refundable balance.\n */\n async refundPayment(paymentId: string, amount?: number | string): Promise<Payment> {\n return this.request<Payment>(\n 'POST',\n `/api/v1/payments/${encodeURIComponent(paymentId)}/refund`,\n amount !== undefined ? { amount } : undefined,\n );\n }\n\n /**\n * List a payment's refund history, newest first — one entry per refund call, even\n * across several partial refunds.\n */\n async listRefunds(paymentId: string): Promise<Refund[]> {\n return this.request<Refund[]>('GET', `/api/v1/payments/${encodeURIComponent(paymentId)}/refunds`);\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":"AAYA,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;AAAA;AAAA;AAAA;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AAA,QACvE,SAAS,OAAO,QAAQ;AAAA,QACxB,SAAS;AAAA,MACX;AAAA,IACF;AAEA,WAAQ,QAAQ,QAAQ;AAAA,EAC1B;AACF;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/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent } from './types.cjs';
1
+ export { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, Refund, 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 { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent } from './types.js';
1
+ export { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, Refund, 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';
@@ -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 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":[]}
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 while a previous payment for it is still\n * active (not `failed`/`expired`) throws a FastaarError with errorType\n * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate.\n */\n invoice_number: string;\n\n /**\n * An existing customer to attach to this payment. Must belong to your merchant account.\n */\n customer_id?: number;\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 refunded_amount: 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 * A single refund event on a payment — one per refund call, even across several\n * partial refunds.\n */\nexport interface Refund {\n id: number;\n amount: string;\n source: 'api' | 'panel';\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
@@ -17,9 +17,15 @@ interface CreatePaymentParams {
17
17
  amount: number | string;
18
18
  /**
19
19
  * Your order reference / idempotency key.
20
- * Retrying with the same invoice_number returns the existing payment instead of creating a duplicate.
20
+ * Retrying with the same invoice_number while a previous payment for it is still
21
+ * active (not `failed`/`expired`) throws a FastaarError with errorType
22
+ * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate.
21
23
  */
22
24
  invoice_number: string;
25
+ /**
26
+ * An existing customer to attach to this payment. Must belong to your merchant account.
27
+ */
28
+ customer_id?: number;
23
29
  /**
24
30
  * The URL to redirect the customer to upon successful payment completion.
25
31
  */
@@ -61,6 +67,7 @@ interface Payment {
61
67
  id: string;
62
68
  amount: string;
63
69
  amount_due: string;
70
+ refunded_amount: string;
64
71
  gateway_charge: string;
65
72
  gateway_charge_type: 'percentage' | 'fixed' | null;
66
73
  gateway_charge_value: string | null;
@@ -83,6 +90,16 @@ interface Payment {
83
90
  verified_at?: string;
84
91
  created_at: string;
85
92
  }
93
+ /**
94
+ * A single refund event on a payment — one per refund call, even across several
95
+ * partial refunds.
96
+ */
97
+ interface Refund {
98
+ id: number;
99
+ amount: string;
100
+ source: 'api' | 'panel';
101
+ created_at: string;
102
+ }
86
103
  /**
87
104
  * Parameters for updating a customer (all fields optional).
88
105
  */
@@ -143,4 +160,4 @@ interface WebhookEvent {
143
160
  data: Payment;
144
161
  }
145
162
 
146
- export type { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent };
163
+ export type { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, Refund, WebhookEvent };
package/dist/types.d.ts CHANGED
@@ -17,9 +17,15 @@ interface CreatePaymentParams {
17
17
  amount: number | string;
18
18
  /**
19
19
  * Your order reference / idempotency key.
20
- * Retrying with the same invoice_number returns the existing payment instead of creating a duplicate.
20
+ * Retrying with the same invoice_number while a previous payment for it is still
21
+ * active (not `failed`/`expired`) throws a FastaarError with errorType
22
+ * `duplicate_invoice_number` (HTTP 409) instead of creating a duplicate.
21
23
  */
22
24
  invoice_number: string;
25
+ /**
26
+ * An existing customer to attach to this payment. Must belong to your merchant account.
27
+ */
28
+ customer_id?: number;
23
29
  /**
24
30
  * The URL to redirect the customer to upon successful payment completion.
25
31
  */
@@ -61,6 +67,7 @@ interface Payment {
61
67
  id: string;
62
68
  amount: string;
63
69
  amount_due: string;
70
+ refunded_amount: string;
64
71
  gateway_charge: string;
65
72
  gateway_charge_type: 'percentage' | 'fixed' | null;
66
73
  gateway_charge_value: string | null;
@@ -83,6 +90,16 @@ interface Payment {
83
90
  verified_at?: string;
84
91
  created_at: string;
85
92
  }
93
+ /**
94
+ * A single refund event on a payment — one per refund call, even across several
95
+ * partial refunds.
96
+ */
97
+ interface Refund {
98
+ id: number;
99
+ amount: string;
100
+ source: 'api' | 'panel';
101
+ created_at: string;
102
+ }
86
103
  /**
87
104
  * Parameters for updating a customer (all fields optional).
88
105
  */
@@ -143,4 +160,4 @@ interface WebhookEvent {
143
160
  data: Payment;
144
161
  }
145
162
 
146
- export type { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, WebhookEvent };
163
+ export type { CreateCustomerParams, CreatePaymentParams, Customer, CustomerParams, FastaarClientOptions, ListCustomersParams, ListPaymentsParams, Payment, Refund, WebhookEvent };
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@fastaar/nextjs",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Next.js React Server Components & Route Handlers integration for Fastaar payment gateway",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/fastaar/fastaar-nextjs.git"
9
+ },
6
10
  "type": "module",
7
11
  "main": "./dist/index.js",
8
12
  "module": "./dist/index.js",