tbc-rando-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +244 -0
- package/dist/index.cjs +672 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +532 -0
- package/dist/index.d.ts +532 -0
- package/dist/index.js +623 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the TBC Bank Checkout (TPAY) API.
|
|
3
|
+
* Docs: https://developers.tbcbank.ge/docs/checkout-api-overview
|
|
4
|
+
*/
|
|
5
|
+
/** Currencies supported by TBC Checkout. */
|
|
6
|
+
declare const Currency: {
|
|
7
|
+
readonly GEL: "GEL";
|
|
8
|
+
readonly USD: "USD";
|
|
9
|
+
readonly EUR: "EUR";
|
|
10
|
+
};
|
|
11
|
+
type Currency = (typeof Currency)[keyof typeof Currency];
|
|
12
|
+
/** Checkout page languages. */
|
|
13
|
+
declare const Language: {
|
|
14
|
+
readonly Georgian: "KA";
|
|
15
|
+
readonly English: "EN";
|
|
16
|
+
};
|
|
17
|
+
type Language = (typeof Language)[keyof typeof Language];
|
|
18
|
+
/**
|
|
19
|
+
* Payment method IDs accepted by the `methods` field of a payment.
|
|
20
|
+
* Docs: https://developers.tbcbank.ge/docs/payment-methods
|
|
21
|
+
*/
|
|
22
|
+
declare const PaymentMethod: {
|
|
23
|
+
/** Web QR / BNPL — requires back-office activation. */
|
|
24
|
+
readonly WebQr: 4;
|
|
25
|
+
/** Card (PAN) payment — enabled by default. */
|
|
26
|
+
readonly Card: 5;
|
|
27
|
+
/** TBC Internet Bank login — requires merchant activation. */
|
|
28
|
+
readonly InternetBank: 7;
|
|
29
|
+
/** Installment — requires campaignId/merchantKey configured in back office. */
|
|
30
|
+
readonly Installment: 8;
|
|
31
|
+
/** Apple Pay — requires merchant activation. */
|
|
32
|
+
readonly ApplePay: 9;
|
|
33
|
+
/** Google Pay — requires merchant activation. */
|
|
34
|
+
readonly GooglePay: 14;
|
|
35
|
+
};
|
|
36
|
+
type PaymentMethod = (typeof PaymentMethod)[keyof typeof PaymentMethod];
|
|
37
|
+
/** Payment lifecycle statuses reported by the API. */
|
|
38
|
+
declare const PaymentStatus: {
|
|
39
|
+
readonly Created: "Created";
|
|
40
|
+
readonly Processing: "Processing";
|
|
41
|
+
readonly Succeeded: "Succeeded";
|
|
42
|
+
readonly Failed: "Failed";
|
|
43
|
+
readonly Expired: "Expired";
|
|
44
|
+
/** Pre-auth succeeded; waiting for the merchant to complete or cancel. */
|
|
45
|
+
readonly WaitingConfirm: "WaitingConfirm";
|
|
46
|
+
readonly CancelPaymentProcessing: "CancelPaymentProcessing";
|
|
47
|
+
readonly PaymentCompletionProcessing: "PaymentCompletionProcessing";
|
|
48
|
+
readonly Returned: "Returned";
|
|
49
|
+
readonly PartialReturned: "PartialReturned";
|
|
50
|
+
};
|
|
51
|
+
type PaymentStatus = (typeof PaymentStatus)[keyof typeof PaymentStatus];
|
|
52
|
+
/**
|
|
53
|
+
* Statuses after which the payment will no longer change on its own —
|
|
54
|
+
* polling can stop. `WaitingConfirm` is final for pre-auth payments only
|
|
55
|
+
* (it then waits for an explicit completion/cancel call from the merchant).
|
|
56
|
+
*/
|
|
57
|
+
declare const FINAL_PAYMENT_STATUSES: readonly PaymentStatus[];
|
|
58
|
+
declare function isFinalPaymentStatus(status: PaymentStatus): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Business-level transaction result codes.
|
|
61
|
+
* Docs: https://developers.tbcbank.ge/docs/result-code
|
|
62
|
+
*/
|
|
63
|
+
declare const ResultCode: {
|
|
64
|
+
/** Transaction was approved. */
|
|
65
|
+
readonly Approved: "approved";
|
|
66
|
+
/** General error. */
|
|
67
|
+
readonly DeclineGeneral: "decline_general";
|
|
68
|
+
/** Card is expired. */
|
|
69
|
+
readonly DeclineExpiredCard: "decline_expired_card";
|
|
70
|
+
/** Declined due to suspected fraud. */
|
|
71
|
+
readonly DeclineSuspectedFraud: "decline_suspected_fraud";
|
|
72
|
+
/** Card is in a restricted list. */
|
|
73
|
+
readonly DeclineRestrictedCard: "decline_restricted_card";
|
|
74
|
+
/** Declined due to invalid card number. */
|
|
75
|
+
readonly DeclineInvalidCardNumber: "decline_invalid_card_number";
|
|
76
|
+
/** Declined due to insufficient funds. */
|
|
77
|
+
readonly DeclineNotSufficientFunds: "decline_not_sufficient_funds";
|
|
78
|
+
/** Card is not active. */
|
|
79
|
+
readonly DeclineCardNotEffective: "decline_card_not_effective";
|
|
80
|
+
/** Details should be checked with the acquirer. */
|
|
81
|
+
readonly CheckWithAcquirer: "check_with_acquirer";
|
|
82
|
+
};
|
|
83
|
+
/** Open union (`string & {}`) so unknown/new codes from TBC still type-check. */
|
|
84
|
+
type ResultCode = (typeof ResultCode)[keyof typeof ResultCode] | (string & {});
|
|
85
|
+
/** Amount object sent when creating a payment. */
|
|
86
|
+
interface Money {
|
|
87
|
+
currency: Currency;
|
|
88
|
+
/** Total amount to charge, format 0.00. */
|
|
89
|
+
total: number;
|
|
90
|
+
subTotal?: number;
|
|
91
|
+
tax?: number;
|
|
92
|
+
shipping?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A product line for installment payments (payment method 8).
|
|
96
|
+
* Serialized to the wire as `{ Name, Price, Quantity }` (PascalCase),
|
|
97
|
+
* which is what the TBC API expects.
|
|
98
|
+
*/
|
|
99
|
+
interface InstallmentProduct {
|
|
100
|
+
name: string;
|
|
101
|
+
/** Unit price, format 0.00. */
|
|
102
|
+
price: number;
|
|
103
|
+
quantity: number;
|
|
104
|
+
}
|
|
105
|
+
interface CreatePaymentRequest {
|
|
106
|
+
amount: Money;
|
|
107
|
+
/** URL the payer is redirected to after finishing the payment. Wire name: `returnurl`. */
|
|
108
|
+
returnUrl: string;
|
|
109
|
+
/** Restrict the checkout page to specific payment methods. Omit to allow all enabled methods. */
|
|
110
|
+
methods?: PaymentMethod[];
|
|
111
|
+
/** POST endpoint on your side notified when the payment reaches a final status. */
|
|
112
|
+
callbackUrl?: string;
|
|
113
|
+
/** Reserve (block) the amount instead of charging; complete within 30 days. */
|
|
114
|
+
preAuth?: boolean;
|
|
115
|
+
/** Checkout page language; defaults to Georgian (KA). */
|
|
116
|
+
language?: Language;
|
|
117
|
+
/** Payment page lifetime; TBC recommends at most 12 minutes. */
|
|
118
|
+
expirationMinutes?: number;
|
|
119
|
+
/** Your own identifier for this payment. */
|
|
120
|
+
merchantPaymentId?: string;
|
|
121
|
+
/** Save the card for later merchant-initiated (recurring) charges. Must be enabled by TBC. */
|
|
122
|
+
saveCard?: boolean;
|
|
123
|
+
/** Save-card validity end date, format "MMYY". */
|
|
124
|
+
saveCardToDate?: string;
|
|
125
|
+
/** Short description shown on the checkout page, max 30 chars. */
|
|
126
|
+
description?: string;
|
|
127
|
+
/** Extra info that appears in the account statement, max 25 ANSI chars. */
|
|
128
|
+
extra?: string;
|
|
129
|
+
/** Additional merchant info, max 52 ANSI chars. */
|
|
130
|
+
extra2?: string;
|
|
131
|
+
/** End customer IP address. */
|
|
132
|
+
userIpAddress?: string;
|
|
133
|
+
skipInfoMessage?: boolean;
|
|
134
|
+
/** Required when `methods` includes PaymentMethod.Installment (8). */
|
|
135
|
+
installmentProducts?: InstallmentProduct[];
|
|
136
|
+
}
|
|
137
|
+
interface PaymentLink {
|
|
138
|
+
uri: string;
|
|
139
|
+
method?: string;
|
|
140
|
+
rel?: string;
|
|
141
|
+
}
|
|
142
|
+
interface CreatePaymentResponse {
|
|
143
|
+
payId: string;
|
|
144
|
+
status: PaymentStatus;
|
|
145
|
+
currency: Currency;
|
|
146
|
+
amount: number;
|
|
147
|
+
/** Contains the checkout-page redirect link and a self link. */
|
|
148
|
+
links?: PaymentLink[];
|
|
149
|
+
transactionId?: string;
|
|
150
|
+
preAuth?: boolean;
|
|
151
|
+
/** Saved-card / recurring identifier (when saveCard was requested). */
|
|
152
|
+
recId?: string;
|
|
153
|
+
httpStatusCode: number;
|
|
154
|
+
developerMessage?: string | null;
|
|
155
|
+
userMessage?: string | null;
|
|
156
|
+
}
|
|
157
|
+
interface RecurringCard {
|
|
158
|
+
recId: string;
|
|
159
|
+
cardMask?: string;
|
|
160
|
+
expiryDate?: string;
|
|
161
|
+
}
|
|
162
|
+
interface PaymentDetails {
|
|
163
|
+
payId: string;
|
|
164
|
+
status: PaymentStatus;
|
|
165
|
+
currency: Currency;
|
|
166
|
+
amount: number;
|
|
167
|
+
/** Confirmed amount of a pre-authorization. */
|
|
168
|
+
confirmedAmount?: number;
|
|
169
|
+
/** Amount returned (refunded) to the payer. */
|
|
170
|
+
returnedAmount?: number;
|
|
171
|
+
/** UFC transaction id. */
|
|
172
|
+
transactionId?: string;
|
|
173
|
+
/** Payment method code used by the payer (see PaymentMethod). */
|
|
174
|
+
paymentMethod?: number;
|
|
175
|
+
/** 12-character bank transaction identifier. */
|
|
176
|
+
rrn?: string | null;
|
|
177
|
+
recurringCard?: RecurringCard;
|
|
178
|
+
preAuth?: boolean;
|
|
179
|
+
/** Who initiated the transaction. */
|
|
180
|
+
initiator?: string;
|
|
181
|
+
resultCode?: ResultCode;
|
|
182
|
+
extra?: string;
|
|
183
|
+
extra2?: string;
|
|
184
|
+
httpStatusCode: number;
|
|
185
|
+
developerMessage?: string | null;
|
|
186
|
+
userMessage?: string | null;
|
|
187
|
+
}
|
|
188
|
+
interface CancelPaymentOptions {
|
|
189
|
+
/**
|
|
190
|
+
* Amount to cancel/refund, format 0.00. Omit for a full cancellation.
|
|
191
|
+
* Must not exceed the transaction amount.
|
|
192
|
+
*/
|
|
193
|
+
amount?: number;
|
|
194
|
+
/** Split cancellations only: IBAN to cancel from. */
|
|
195
|
+
extra?: string;
|
|
196
|
+
/** Split cancellations only: amount to cancel from that IBAN. */
|
|
197
|
+
extra2?: string;
|
|
198
|
+
}
|
|
199
|
+
interface CompletePreAuthResponse {
|
|
200
|
+
status: PaymentStatus;
|
|
201
|
+
amount?: number;
|
|
202
|
+
confirmedAmount?: number;
|
|
203
|
+
httpStatusCode: number;
|
|
204
|
+
developerMessage?: string | null;
|
|
205
|
+
userMessage?: string | null;
|
|
206
|
+
}
|
|
207
|
+
/** Request for charging a saved card (recurring payment execution). */
|
|
208
|
+
interface ChargeRecurringRequest {
|
|
209
|
+
/** Saved-card identifier obtained from a saveCard payment. */
|
|
210
|
+
recId: string;
|
|
211
|
+
amount: number;
|
|
212
|
+
currency: Currency;
|
|
213
|
+
/** Reserve instead of charge; requires completion later. */
|
|
214
|
+
preAuth?: boolean;
|
|
215
|
+
/** Pass 'merchant' for merchant-initiated (subscription) charges; omit for customer-initiated. */
|
|
216
|
+
initiator?: 'merchant';
|
|
217
|
+
merchantPaymentId?: string;
|
|
218
|
+
extra?: string;
|
|
219
|
+
extra2?: string;
|
|
220
|
+
}
|
|
221
|
+
interface ChargeRecurringResponse {
|
|
222
|
+
payId: string;
|
|
223
|
+
status: PaymentStatus;
|
|
224
|
+
currency?: Currency;
|
|
225
|
+
amount?: number;
|
|
226
|
+
confirmedAmount?: number;
|
|
227
|
+
transactionId?: string;
|
|
228
|
+
preAuth?: boolean;
|
|
229
|
+
recurringCard?: RecurringCard;
|
|
230
|
+
httpStatusCode: number;
|
|
231
|
+
developerMessage?: string | null;
|
|
232
|
+
userMessage?: string | null;
|
|
233
|
+
}
|
|
234
|
+
/** Parsed TBC callback (webhook) notification. */
|
|
235
|
+
interface CallbackEvent {
|
|
236
|
+
paymentId: string;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Returns the checkout-page URL the payer must be redirected to,
|
|
240
|
+
* or undefined if the response carries no redirect link.
|
|
241
|
+
*/
|
|
242
|
+
declare function getRedirectUrl(payment: Pick<CreatePaymentResponse, 'links'>): string | undefined;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Standard checkout payments.
|
|
246
|
+
* Docs: https://developers.tbcbank.ge/docs/checkout-create-checkout-payment
|
|
247
|
+
*/
|
|
248
|
+
declare class Payments {
|
|
249
|
+
private readonly client;
|
|
250
|
+
constructor(client: TbcCheckoutClient);
|
|
251
|
+
/**
|
|
252
|
+
* Creates a checkout payment (POST /tpay/payments) and returns the payment
|
|
253
|
+
* with a redirect link to the hosted checkout page (see `getRedirectUrl`).
|
|
254
|
+
*/
|
|
255
|
+
create(request: CreatePaymentRequest): Promise<CreatePaymentResponse>;
|
|
256
|
+
/** Fetches payment details and current status (GET /tpay/payments/{payId}). */
|
|
257
|
+
retrieve(payId: string): Promise<PaymentDetails>;
|
|
258
|
+
/**
|
|
259
|
+
* Cancels (refunds) a payment, fully or partially
|
|
260
|
+
* (POST /tpay/payments/{payId}/cancel). Resolves on success; the API
|
|
261
|
+
* returns an empty 200 body.
|
|
262
|
+
*/
|
|
263
|
+
cancel(payId: string, options?: CancelPaymentOptions): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Completes a pre-authorized payment (POST /tpay/payments/{payId}/completion).
|
|
266
|
+
* `amount` may be lower than the blocked amount — the difference is
|
|
267
|
+
* automatically returned to the customer. Must be called within 30 days
|
|
268
|
+
* of the pre-authorization.
|
|
269
|
+
*/
|
|
270
|
+
completePreAuth(payId: string, amount: number): Promise<CompletePreAuthResponse>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
interface CreateInstallmentRequest extends Omit<CreatePaymentRequest, 'amount' | 'methods' | 'installmentProducts' | 'preAuth' | 'saveCard' | 'saveCardToDate'> {
|
|
274
|
+
/** Product lines financed by the installment. Their sum becomes the payment total. */
|
|
275
|
+
products: InstallmentProduct[];
|
|
276
|
+
/** Default: GEL (installments are offered in GEL). */
|
|
277
|
+
currency?: Currency;
|
|
278
|
+
/**
|
|
279
|
+
* Explicit total, format 0.00. Optional — computed as
|
|
280
|
+
* sum(price * quantity) over `products` when omitted. If provided it must
|
|
281
|
+
* match the computed sum.
|
|
282
|
+
*/
|
|
283
|
+
total?: number;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Installment payments via TBC Checkout (payment method 8).
|
|
287
|
+
*
|
|
288
|
+
* The merchant account must have an installment campaignId/merchantKey
|
|
289
|
+
* configured in the TBC back office. The payer picks the installment terms
|
|
290
|
+
* on the hosted checkout page.
|
|
291
|
+
*
|
|
292
|
+
* Docs: https://developers.tbcbank.ge/docs/checkout-create-checkout-payment
|
|
293
|
+
*/
|
|
294
|
+
declare class Installments {
|
|
295
|
+
private readonly client;
|
|
296
|
+
constructor(client: TbcCheckoutClient);
|
|
297
|
+
/**
|
|
298
|
+
* Creates a checkout payment restricted to the installment method, with
|
|
299
|
+
* the product lines TBC requires for installment applications.
|
|
300
|
+
*/
|
|
301
|
+
create(request: CreateInstallmentRequest): Promise<CreatePaymentResponse>;
|
|
302
|
+
}
|
|
303
|
+
/** Rounds to 2 decimal places, avoiding float drift like 0.1 + 0.2. */
|
|
304
|
+
declare function roundMoney(value: number): number;
|
|
305
|
+
|
|
306
|
+
type StartSubscriptionRequest = Omit<CreatePaymentRequest, 'saveCard'>;
|
|
307
|
+
/**
|
|
308
|
+
* Subscriptions / recurring payments built on TBC's saved-card flow:
|
|
309
|
+
*
|
|
310
|
+
* 1. `start()` — the customer pays once on the hosted checkout page with
|
|
311
|
+
* `saveCard: true`. Once the payment succeeds, `payments.retrieve()`
|
|
312
|
+
* returns `recurringCard.recId` — persist it against the subscriber.
|
|
313
|
+
* 2. `charge()` — bill the saved card server-side on your own schedule
|
|
314
|
+
* (POST /tpay/payments/execution).
|
|
315
|
+
* 3. `cancel()` — delete the saved card to stop the subscription
|
|
316
|
+
* (POST /tpay/payments/{recId}/delete).
|
|
317
|
+
*
|
|
318
|
+
* Card saving must be enabled for the merchant by TBC.
|
|
319
|
+
* Docs: https://developers.tbcbank.ge/docs/checkout-execute-recurring-payment
|
|
320
|
+
*/
|
|
321
|
+
declare class Subscriptions {
|
|
322
|
+
private readonly client;
|
|
323
|
+
constructor(client: TbcCheckoutClient);
|
|
324
|
+
/**
|
|
325
|
+
* Creates the initial checkout payment with card saving enabled. Redirect
|
|
326
|
+
* the customer to the returned checkout page; after the payment succeeds,
|
|
327
|
+
* read `recurringCard.recId` from `payments.retrieve(payId)`.
|
|
328
|
+
*/
|
|
329
|
+
start(request: StartSubscriptionRequest): Promise<CreatePaymentResponse>;
|
|
330
|
+
/**
|
|
331
|
+
* Charges a saved card (recurring payment execution). Pass
|
|
332
|
+
* `initiator: 'merchant'` for unattended subscription billing; omit it
|
|
333
|
+
* when the customer triggers the charge themselves.
|
|
334
|
+
*
|
|
335
|
+
* The response is final — no redirect happens. Check `status`
|
|
336
|
+
* ('Succeeded' | 'WaitingConfirm' | 'Failed').
|
|
337
|
+
*/
|
|
338
|
+
charge(request: ChargeRecurringRequest): Promise<ChargeRecurringResponse>;
|
|
339
|
+
/**
|
|
340
|
+
* Deletes a saved card so it can no longer be charged
|
|
341
|
+
* (POST /tpay/payments/{recId}/delete). Resolves on success.
|
|
342
|
+
*/
|
|
343
|
+
cancel(recId: string): Promise<void>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Source IPs TBC sends callback notifications from — whitelist these on
|
|
348
|
+
* your callback endpoint.
|
|
349
|
+
* Docs: https://developers.tbcbank.ge/docs/checkout-callback-url
|
|
350
|
+
*/
|
|
351
|
+
declare const TBC_CALLBACK_IPS: readonly string[];
|
|
352
|
+
declare function isTbcCallbackIp(ip: string | null | undefined): boolean;
|
|
353
|
+
/**
|
|
354
|
+
* Extracts the payment id from a TBC callback body. Accepts a raw string
|
|
355
|
+
* (JSON or form-urlencoded) or an already-parsed object; key matching is
|
|
356
|
+
* case-insensitive (TBC documents the field as `PaymentId`).
|
|
357
|
+
*/
|
|
358
|
+
declare function parseCallbackBody(body: unknown): CallbackEvent;
|
|
359
|
+
interface CallbackHandlerOptions {
|
|
360
|
+
/**
|
|
361
|
+
* Reject requests not originating from TBC's documented callback IPs.
|
|
362
|
+
* The client IP is read from the X-Forwarded-For / X-Real-IP headers, so
|
|
363
|
+
* only enable this when those headers are set by YOUR proxy and cannot be
|
|
364
|
+
* spoofed by the caller. Default: false (the payment status is fetched
|
|
365
|
+
* from the TBC API anyway, so a forged callback cannot inject a fake status).
|
|
366
|
+
*/
|
|
367
|
+
verifySourceIp?: boolean;
|
|
368
|
+
/** Called when the request cannot be handled; useful for logging. */
|
|
369
|
+
onError?: (error: unknown) => void;
|
|
370
|
+
}
|
|
371
|
+
type CallbackListener = (payment: PaymentDetails, event: CallbackEvent) => void | Promise<void>;
|
|
372
|
+
/**
|
|
373
|
+
* TBC callback (webhook) handling.
|
|
374
|
+
*
|
|
375
|
+
* The callback body only carries a `PaymentId` — never a status — so the
|
|
376
|
+
* handler fetches the authoritative payment details from the TBC API before
|
|
377
|
+
* invoking your listener. This also means forged callbacks are harmless:
|
|
378
|
+
* at worst they make you re-fetch a payment you own.
|
|
379
|
+
*/
|
|
380
|
+
declare class Webhooks {
|
|
381
|
+
private readonly client;
|
|
382
|
+
constructor(client: TbcCheckoutClient);
|
|
383
|
+
/** Parses a callback body and fetches the payment it refers to. */
|
|
384
|
+
resolveCallback(body: unknown): Promise<{
|
|
385
|
+
event: CallbackEvent;
|
|
386
|
+
payment: PaymentDetails;
|
|
387
|
+
}>;
|
|
388
|
+
/**
|
|
389
|
+
* Builds a `(Request) => Promise<Response>` handler using the web-standard
|
|
390
|
+
* Request/Response types — usable directly as a Next.js App Router route:
|
|
391
|
+
*
|
|
392
|
+
* ```ts
|
|
393
|
+
* // app/api/tbc/callback/route.ts
|
|
394
|
+
* export const POST = tbc.webhooks.handler(async (payment) => {
|
|
395
|
+
* if (payment.status === 'Succeeded') await fulfillOrder(payment.payId);
|
|
396
|
+
* });
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* Always responds 200 to TBC once your listener has run; responds 400 for
|
|
400
|
+
* unparseable bodies and 500 when the listener or the details fetch throws.
|
|
401
|
+
*/
|
|
402
|
+
handler(listener: CallbackListener, options?: CallbackHandlerOptions): (request: Request) => Promise<Response>;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
declare const DEFAULT_BASE_URL = "https://api.tbcbank.ge/v1";
|
|
406
|
+
interface TbcCheckoutConfig {
|
|
407
|
+
/** Developer app API key (from developers.tbcbank.ge). Sent as the `apikey` header. */
|
|
408
|
+
apiKey: string;
|
|
409
|
+
/** TBC E-Commerce merchant client_id. */
|
|
410
|
+
clientId: string;
|
|
411
|
+
/** TBC E-Commerce merchant client_secret. */
|
|
412
|
+
clientSecret: string;
|
|
413
|
+
/** Override the API base URL. Default: https://api.tbcbank.ge/v1 */
|
|
414
|
+
baseUrl?: string;
|
|
415
|
+
/** Custom fetch implementation (useful for testing/instrumentation). Default: global fetch. */
|
|
416
|
+
fetch?: typeof fetch;
|
|
417
|
+
/** Per-request timeout in ms. Default: 30000. */
|
|
418
|
+
timeoutMs?: number;
|
|
419
|
+
}
|
|
420
|
+
interface RequestOptions {
|
|
421
|
+
method: 'GET' | 'POST';
|
|
422
|
+
path: string;
|
|
423
|
+
/** JSON body; serialized and sent with Content-Type: application/json. */
|
|
424
|
+
json?: unknown;
|
|
425
|
+
/** Whether to attach the bearer token. Default true. */
|
|
426
|
+
auth?: boolean;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Client for the TBC Bank Checkout (TPAY) API.
|
|
430
|
+
*
|
|
431
|
+
* ```ts
|
|
432
|
+
* const tbc = new TbcCheckoutClient({
|
|
433
|
+
* apiKey: process.env.TBC_API_KEY!,
|
|
434
|
+
* clientId: process.env.TBC_CLIENT_ID!,
|
|
435
|
+
* clientSecret: process.env.TBC_CLIENT_SECRET!,
|
|
436
|
+
* });
|
|
437
|
+
* const payment = await tbc.payments.create({
|
|
438
|
+
* amount: { currency: 'GEL', total: 10.5 },
|
|
439
|
+
* returnUrl: 'https://example.ge/checkout/return',
|
|
440
|
+
* });
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
declare class TbcCheckoutClient {
|
|
444
|
+
readonly baseUrl: string;
|
|
445
|
+
readonly payments: Payments;
|
|
446
|
+
readonly installments: Installments;
|
|
447
|
+
readonly subscriptions: Subscriptions;
|
|
448
|
+
readonly webhooks: Webhooks;
|
|
449
|
+
private readonly apiKey;
|
|
450
|
+
private readonly fetchFn;
|
|
451
|
+
private readonly timeoutMs;
|
|
452
|
+
private readonly tokens;
|
|
453
|
+
constructor(config: TbcCheckoutConfig);
|
|
454
|
+
/** Fetches (or returns the cached) TPAY access token. */
|
|
455
|
+
getAccessToken(forceRefresh?: boolean): Promise<string>;
|
|
456
|
+
/**
|
|
457
|
+
* Low-level request helper used by all resources. Attaches the apikey and
|
|
458
|
+
* bearer token, and transparently refreshes the token once on a 401.
|
|
459
|
+
*/
|
|
460
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
461
|
+
private send;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
interface AccessTokenResponse {
|
|
465
|
+
access_token: string;
|
|
466
|
+
token_type: string;
|
|
467
|
+
/** Lifetime in seconds (typically 86400 = 24h). */
|
|
468
|
+
expires_in: number;
|
|
469
|
+
}
|
|
470
|
+
interface TokenManagerOptions {
|
|
471
|
+
baseUrl: string;
|
|
472
|
+
apiKey: string;
|
|
473
|
+
clientId: string;
|
|
474
|
+
clientSecret: string;
|
|
475
|
+
fetchFn: typeof fetch;
|
|
476
|
+
/** Refresh this many ms before the reported expiry. Default 60s. */
|
|
477
|
+
expirySkewMs?: number;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Fetches and caches the TPAY bearer token (POST /tpay/access-token).
|
|
481
|
+
* Tokens live ~24h; this caches until shortly before expiry and dedupes
|
|
482
|
+
* concurrent refreshes so parallel API calls trigger a single token request.
|
|
483
|
+
*/
|
|
484
|
+
declare class TokenManager {
|
|
485
|
+
private readonly opts;
|
|
486
|
+
private cached;
|
|
487
|
+
private pending;
|
|
488
|
+
constructor(options: TokenManagerOptions);
|
|
489
|
+
getToken(forceRefresh?: boolean): Promise<string>;
|
|
490
|
+
/** Drops the cached token so the next call fetches a fresh one. */
|
|
491
|
+
invalidate(): void;
|
|
492
|
+
private fetchToken;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** Base class for every error thrown by this SDK. */
|
|
496
|
+
declare class TbcError extends Error {
|
|
497
|
+
constructor(message: string, options?: ErrorOptions);
|
|
498
|
+
}
|
|
499
|
+
/** Thrown before a request is sent when input is invalid. */
|
|
500
|
+
declare class TbcValidationError extends TbcError {
|
|
501
|
+
}
|
|
502
|
+
/** Shape of TBC problem+json error bodies. */
|
|
503
|
+
interface TbcErrorBody {
|
|
504
|
+
type?: string;
|
|
505
|
+
title?: string;
|
|
506
|
+
status?: string | number;
|
|
507
|
+
detail?: string;
|
|
508
|
+
systemCode?: string;
|
|
509
|
+
resultCode?: ResultCode;
|
|
510
|
+
}
|
|
511
|
+
/** Thrown when the TBC API responds with a non-2xx status. */
|
|
512
|
+
declare class TbcApiError extends TbcError {
|
|
513
|
+
/** HTTP status code of the response. */
|
|
514
|
+
readonly status: number;
|
|
515
|
+
/** Link to the error reference, e.g. https://developers.tbcbank.ge/docs/error-type-401 */
|
|
516
|
+
readonly type?: string;
|
|
517
|
+
readonly title?: string;
|
|
518
|
+
readonly detail?: string;
|
|
519
|
+
/** TBC internal problem code, e.g. "tpay-access-token.401.001". */
|
|
520
|
+
readonly systemCode?: string;
|
|
521
|
+
/** Business-level result, e.g. "decline_not_sufficient_funds". */
|
|
522
|
+
readonly resultCode?: ResultCode;
|
|
523
|
+
/** Raw response body (parsed JSON if possible, otherwise text). */
|
|
524
|
+
readonly body: unknown;
|
|
525
|
+
constructor(status: number, body: unknown);
|
|
526
|
+
static fromResponse(response: Response): Promise<TbcApiError>;
|
|
527
|
+
}
|
|
528
|
+
/** Thrown on HTTP 401 — invalid apikey or expired/invalid access token. */
|
|
529
|
+
declare class TbcAuthError extends TbcApiError {
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export { type AccessTokenResponse, type CallbackEvent, type CallbackHandlerOptions, type CallbackListener, type CancelPaymentOptions, type ChargeRecurringRequest, type ChargeRecurringResponse, type CompletePreAuthResponse, type CreateInstallmentRequest, type CreatePaymentRequest, type CreatePaymentResponse, Currency, DEFAULT_BASE_URL, FINAL_PAYMENT_STATUSES, type InstallmentProduct, Installments, Language, type Money, type PaymentDetails, type PaymentLink, PaymentMethod, PaymentStatus, Payments, type RecurringCard, type RequestOptions, ResultCode, type StartSubscriptionRequest, Subscriptions, TBC_CALLBACK_IPS, TbcApiError, TbcAuthError, TbcCheckoutClient, type TbcCheckoutConfig, TbcError, type TbcErrorBody, TbcValidationError, TokenManager, type TokenManagerOptions, Webhooks, getRedirectUrl, isFinalPaymentStatus, isTbcCallbackIp, parseCallbackBody, roundMoney };
|