@uveysservetoglu/kobil-payment 2.0.0 → 3.0.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/README.md +46 -35
- package/dist/amount.d.ts +11 -0
- package/dist/amount.d.ts.map +1 -0
- package/dist/amount.js +37 -0
- package/dist/amount.js.map +1 -0
- package/dist/client.d.ts +40 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +160 -39
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +37 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -6
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @uveysservetoglu/kobil-payment
|
|
2
2
|
|
|
3
|
-
KOBIL Pay
|
|
4
|
-
management and typed models.
|
|
3
|
+
KOBIL Pay client for Node.js / TypeScript — the MiniApp API's `/v1/payments` (default) or the
|
|
4
|
+
legacy mpay-merchant API — with automatic OAuth token management and typed models.
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
7
|
npm install @uveysservetoglu/kobil-payment
|
|
@@ -12,43 +12,47 @@ npm install @uveysservetoglu/kobil-payment
|
|
|
12
12
|
```ts
|
|
13
13
|
import { PaymentClient, paymentGroup } from "@uveysservetoglu/kobil-payment";
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
// PAYMENT_MERCHANT_NAME come from the environment.
|
|
15
|
+
// OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET and PAYMENT_MERCHANT_ID come from the environment.
|
|
17
16
|
const payment = new PaymentClient({
|
|
18
17
|
defaultCurrency: "TRY",
|
|
19
18
|
defaultMerchantCallback: "https://yourapi.com/payment-callback",
|
|
20
19
|
});
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
> **Amounts** are in the smallest currency unit (`1300` = 13.00 TRY)
|
|
22
|
+
> **Amounts** are in the smallest currency unit (`1300` = 13.00 TRY) and **timeouts** in minutes, in
|
|
23
|
+
> both API modes. Miniapp mode sends the amount as the API's decimal string (`{ value: "13.00",
|
|
24
|
+
> currency: "TRY" }`, decimals per ISO 4217 — see `formatMinorUnits`) and the timeout as
|
|
25
|
+
> `timeoutSeconds` (600–3600; omit it for the API's 15-minute default).
|
|
24
26
|
|
|
25
|
-
##
|
|
27
|
+
## API mode
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
are two registrations with their own ids, secrets and tenants, and the payment API checks which one
|
|
30
|
-
the token was issued for — a MiniApp token is refused with `PAY_WRONG_CLIENT`.
|
|
29
|
+
Pass `apiMode: "legacy"` (or set `KOBIL_API_MODE=legacy`) for the legacy mpay-merchant API; leave it
|
|
30
|
+
unset for the MiniApp API. See `@uveysservetoglu/kobil-core` for the shared settings.
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
| | Miniapp (default) | Legacy |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| Token | The MiniApp's own (`OIDC_CLIENT_ID` / `OIDC_CLIENT_SECRET`) | The **merchant** client's (`PAYMENT_MERCHANT_ID` / `PAYMENT_MERCHANT_SECRET`) |
|
|
35
|
+
| `merchantId` on the wire | `PAYMENT_MERCHANT_ID`, else the client id | `PAYMENT_MERCHANT_ID`, else the client id |
|
|
36
|
+
| Callback | **Required** on every operation (`merchantCallback` or `defaultMerchantCallback`) | Optional |
|
|
37
|
+
| Idempotency | `Idempotency-Key` header | `idempotencyId` in the body |
|
|
38
|
+
| Also needs | — | `PAYMENT_BASE`, `PAYMENT_TENANT_ID`, `PAYMENT_MERCHANT_NAME` |
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|---|---|
|
|
38
|
-
| `PAYMENT_BASE` | Payment origin. `{base}/mpay-merchant/create/transaction` is derived from it, and `/postauth`, `/status`, `/void`, `/refund` from that. |
|
|
39
|
-
| `PAYMENT_MERCHANT_ID` | Merchant **client id**, and the `merchantId` on the wire. |
|
|
40
|
-
| `PAYMENT_MERCHANT_SECRET` | Merchant client secret. |
|
|
41
|
-
| `PAYMENT_TENANT_ID` | Payment tenant — **a different tenant from mPower's**. Mixing them up is the other common failure. |
|
|
42
|
-
| `PAYMENT_MERCHANT_NAME` | Merchant name shown to the payer. |
|
|
43
|
-
| `OIDC_ISSUER` | Realm issuer URL; the token endpoint is derived from it. |
|
|
40
|
+
### Legacy: payment has its own client
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
In legacy mode **payment authenticates as the merchant client, not as the MiniApp.** They are two
|
|
43
|
+
registrations with their own ids, secrets and tenants, and the payment API checks which one the token
|
|
44
|
+
was issued for — a MiniApp token is refused with `PAY_WRONG_CLIENT`. So the token is fetched with
|
|
45
|
+
`PAYMENT_MERCHANT_ID` / `PAYMENT_MERCHANT_SECRET`, and that id is also the `merchantId`: the API
|
|
46
|
+
requires `merchantId === merchantServiceUUID === the merchant client id`. `PAYMENT_TENANT_ID` is a
|
|
47
|
+
**different tenant from mPower's** — mixing them up is the other common failure.
|
|
48
|
+
|
|
49
|
+
The MiniApp API takes one token for every operation and names the merchant in the body instead.
|
|
50
|
+
Pass `clientId` / `clientSecret` explicitly to override either choice.
|
|
47
51
|
|
|
48
52
|
## The six operations
|
|
49
53
|
|
|
50
54
|
```ts
|
|
51
|
-
// 1. Regular payment
|
|
55
|
+
// 1. Regular payment
|
|
52
56
|
const res = await payment.createTransaction({
|
|
53
57
|
userId,
|
|
54
58
|
amount: 1300,
|
|
@@ -56,36 +60,43 @@ const res = await payment.createTransaction({
|
|
|
56
60
|
});
|
|
57
61
|
// res.transactionId ; parsePaymentStatus(res) === "new"
|
|
58
62
|
|
|
59
|
-
// 2. Pre-authorization (hold funds)
|
|
63
|
+
// 2. Pre-authorization (hold funds) — keep the idempotency key
|
|
60
64
|
const pre = await payment.createPreAuthTransaction({ userId, amount: 1300 });
|
|
61
|
-
// pre.nextAction holds the post-auth handle
|
|
62
65
|
|
|
63
|
-
// 3. Post-authorization (settle
|
|
64
|
-
await payment.postAuth({ transactionId: pre.transactionId!, amount: 40 });
|
|
66
|
+
// 3. Post-authorization (settle; omit amount to capture the full hold)
|
|
67
|
+
await payment.postAuth({ transactionId: pre.transactionId!, amount: 40, idempotencyId: pre.idempotencyKey });
|
|
65
68
|
|
|
66
|
-
// 4. Status
|
|
69
|
+
// 4. Status (the resolved status goes to the callback; miniapp mode also returns a snapshot)
|
|
67
70
|
const status = await payment.getStatus({ transactionId });
|
|
68
71
|
|
|
69
72
|
// 5. Cancel (void)
|
|
70
|
-
await payment.cancel({ transactionId, userId,
|
|
73
|
+
await payment.cancel({ transactionId, userId, reason: "Customer cancelled" });
|
|
71
74
|
|
|
72
|
-
// 6. Refund (partial or full)
|
|
73
|
-
await payment.refund({ transactionId, userId, amount: 5555, currency: "USD" });
|
|
75
|
+
// 6. Refund (partial or full; several partial refunds are allowed)
|
|
76
|
+
await payment.refund({ transactionId, userId, amount: 5555, currency: "USD", reason: "Returned" });
|
|
74
77
|
```
|
|
75
78
|
|
|
79
|
+
**Capturing a pre-authorization in miniapp mode** needs the pre-authorization's idempotency key —
|
|
80
|
+
the API uses it to tie the two together. Every result carries the key it was sent with as
|
|
81
|
+
`idempotencyKey`; store the pre-authorization's next to its `transactionId` and pass it to `postAuth`.
|
|
82
|
+
|
|
83
|
+
`reason` (alias `cancellationMessage`) is required for cancel and refund in miniapp mode. Results
|
|
84
|
+
carry `transactionId` in both modes; in miniapp mode it mirrors the API's `paymentId`, and
|
|
85
|
+
`createdAt` is set. `parsePaymentStatus` knows both APIs' statuses.
|
|
86
|
+
|
|
76
87
|
JavaScript usage is identical (`const { PaymentClient } = require("@uveysservetoglu/kobil-payment")`).
|
|
77
88
|
|
|
78
89
|
## Errors
|
|
79
90
|
|
|
80
|
-
All operations
|
|
81
|
-
`responseBody`
|
|
91
|
+
All operations reject with `KobilPaymentError` (extends `KobilError`) carrying `statusCode` and
|
|
92
|
+
`responseBody`, plus `errorCode` / `subsystem` / `traceId` from the MiniApp API's error envelope.
|
|
82
93
|
|
|
83
94
|
```ts
|
|
84
95
|
import { KobilPaymentError } from "@uveysservetoglu/kobil-payment";
|
|
85
96
|
try {
|
|
86
97
|
await payment.createTransaction({ userId, amount: 1300 });
|
|
87
98
|
} catch (e) {
|
|
88
|
-
if (e instanceof KobilPaymentError) console.error(e.statusCode, e.responseBody);
|
|
99
|
+
if (e instanceof KobilPaymentError) console.error(e.statusCode, e.errorCode, e.traceId, e.responseBody);
|
|
89
100
|
}
|
|
90
101
|
```
|
|
91
102
|
|
package/dist/amount.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Number of decimal places the currency uses (ISO 4217 minor unit). */
|
|
2
|
+
export declare function currencyExponent(currency: string): number;
|
|
3
|
+
/**
|
|
4
|
+
* Renders an amount in the smallest currency unit as the MiniApp API's decimal string, with exactly the
|
|
5
|
+
* currency's number of decimals: `formatMinorUnits(1300, "TRY") === "13.00"`, `(1300, "JPY") === "1300"`.
|
|
6
|
+
*
|
|
7
|
+
* The SDK takes minor units in both API modes so code does not change with the mode; this is the
|
|
8
|
+
* conversion the miniapp mode applies. Integer arithmetic on the digits — no floating point.
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatMinorUnits(amount: number, currency: string): string;
|
|
11
|
+
//# sourceMappingURL=amount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":"AAaA,wEAAwE;AACxE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQzE"}
|
package/dist/amount.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currencyExponent = currencyExponent;
|
|
4
|
+
exports.formatMinorUnits = formatMinorUnits;
|
|
5
|
+
const error_1 = require("./error");
|
|
6
|
+
/**
|
|
7
|
+
* ISO 4217 minor-unit exponents that differ from the usual 2. Every currency not listed has two decimal
|
|
8
|
+
* places (TRY, EUR, USD, GBP, …).
|
|
9
|
+
*/
|
|
10
|
+
const EXPONENTS = {
|
|
11
|
+
BIF: 0, CLP: 0, DJF: 0, GNF: 0, ISK: 0, JPY: 0, KMF: 0, KRW: 0, PYG: 0, RWF: 0,
|
|
12
|
+
UGX: 0, UYI: 0, VND: 0, VUV: 0, XAF: 0, XOF: 0, XPF: 0,
|
|
13
|
+
BHD: 3, IQD: 3, JOD: 3, KWD: 3, LYD: 3, OMR: 3, TND: 3,
|
|
14
|
+
CLF: 4, UYW: 4,
|
|
15
|
+
};
|
|
16
|
+
/** Number of decimal places the currency uses (ISO 4217 minor unit). */
|
|
17
|
+
function currencyExponent(currency) {
|
|
18
|
+
return EXPONENTS[currency.toUpperCase()] ?? 2;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Renders an amount in the smallest currency unit as the MiniApp API's decimal string, with exactly the
|
|
22
|
+
* currency's number of decimals: `formatMinorUnits(1300, "TRY") === "13.00"`, `(1300, "JPY") === "1300"`.
|
|
23
|
+
*
|
|
24
|
+
* The SDK takes minor units in both API modes so code does not change with the mode; this is the
|
|
25
|
+
* conversion the miniapp mode applies. Integer arithmetic on the digits — no floating point.
|
|
26
|
+
*/
|
|
27
|
+
function formatMinorUnits(amount, currency) {
|
|
28
|
+
if (!Number.isSafeInteger(amount) || amount < 0) {
|
|
29
|
+
throw new error_1.KobilPaymentError(`amount must be a non-negative integer in minor units, got ${amount}.`);
|
|
30
|
+
}
|
|
31
|
+
const exponent = currencyExponent(currency);
|
|
32
|
+
if (exponent === 0)
|
|
33
|
+
return String(amount);
|
|
34
|
+
const digits = String(amount).padStart(exponent + 1, "0");
|
|
35
|
+
return `${digits.slice(0, -exponent)}.${digits.slice(-exponent)}`;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":";;AAcA,4CAEC;AASD,4CAQC;AAjCD,mCAA4C;AAE5C;;;GAGG;AACH,MAAM,SAAS,GAA2B;IACxC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IAC9E,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IACtD,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IACtD,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;CACf,CAAC;AAEF,wEAAwE;AACxE,SAAgB,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,MAAc,EAAE,QAAgB;IAC/D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,yBAAiB,CAAC,6DAA6D,MAAM,GAAG,CAAC,CAAC;IACtG,CAAC;IACD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1D,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;AACpE,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
-
import { KobilCredentials, KobilError, KobilServiceClient, TokenProvider } from "@uveysservetoglu/kobil-core";
|
|
1
|
+
import { ApiMode, KobilApiOptions, KobilCredentials, KobilError, KobilServiceClient, TokenProvider } from "@uveysservetoglu/kobil-core";
|
|
2
2
|
import { CancelInput, CreateTransactionInput, PostAuthInput, RefundInput, StatusInput, TransactionResult } from "./types";
|
|
3
|
-
export interface PaymentClientOptions extends Partial<KobilCredentials
|
|
3
|
+
export interface PaymentClientOptions extends Partial<KobilCredentials>, KobilApiOptions {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Legacy mode: base transaction URL; `/postauth`, `/status`, `/void`, `/refund` are derived from it.
|
|
6
6
|
* Derived from `PAYMENT_BASE` when omitted.
|
|
7
7
|
*/
|
|
8
8
|
paymentBaseUrl?: string;
|
|
9
9
|
/**
|
|
10
|
-
* The merchant
|
|
11
|
-
*
|
|
10
|
+
* The merchant id sent on the wire. Falls back to `PAYMENT_MERCHANT_ID`, then to `clientId`.
|
|
11
|
+
* In legacy mode it is also the client the token is fetched for (see the constructor).
|
|
12
12
|
*/
|
|
13
13
|
merchantId?: string;
|
|
14
|
-
/**
|
|
14
|
+
/** Legacy mode: must match `merchantId`; defaults to it. */
|
|
15
15
|
merchantServiceUuid?: string;
|
|
16
|
-
/**
|
|
16
|
+
/** Legacy mode: merchant name shown to the payer. Falls back to `PAYMENT_MERCHANT_NAME`. */
|
|
17
17
|
merchantName?: string;
|
|
18
|
-
/**
|
|
18
|
+
/** Legacy mode: payment tenant — a different tenant from mPower's. Falls back to `PAYMENT_TENANT_ID`. */
|
|
19
19
|
tenantId?: string;
|
|
20
20
|
/** Default ISO currency code. Default: "TRY". */
|
|
21
21
|
defaultCurrency?: string;
|
|
22
|
+
/** Default result callback. Every miniapp-mode operation needs one (here or per request). */
|
|
22
23
|
defaultMerchantCallback?: string;
|
|
23
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Default transaction timeout in minutes. Legacy default: 59. Miniapp mode sends it as `timeoutSeconds`
|
|
26
|
+
* only when set, so the API's own default (15 minutes) applies otherwise.
|
|
27
|
+
*/
|
|
24
28
|
defaultTransactionTimeoutMinutes?: number;
|
|
25
|
-
/**
|
|
29
|
+
/** Legacy mode: wire protocol version. Default: 1. */
|
|
26
30
|
version?: number;
|
|
27
31
|
/** Reuse a shared token provider (e.g. across modules). If omitted, one is created from credentials/env. */
|
|
28
32
|
tokenProvider?: TokenProvider;
|
|
29
33
|
}
|
|
30
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Client for KOBIL Pay: the MiniApp API's `/v1/payments` (default) or the legacy mpay-merchant API.
|
|
36
|
+
* Inputs are the same in both modes — amounts in minor units, timeouts in minutes — and are converted
|
|
37
|
+
* to the selected API's shape.
|
|
38
|
+
*/
|
|
31
39
|
export declare class PaymentClient extends KobilServiceClient {
|
|
40
|
+
readonly apiMode: ApiMode;
|
|
32
41
|
private readonly baseUrl;
|
|
33
42
|
private readonly clientId;
|
|
34
43
|
private readonly merchantName;
|
|
@@ -37,17 +46,36 @@ export declare class PaymentClient extends KobilServiceClient {
|
|
|
37
46
|
private readonly tenantId?;
|
|
38
47
|
private readonly defaultCurrency;
|
|
39
48
|
private readonly defaultMerchantCallback?;
|
|
40
|
-
private readonly
|
|
49
|
+
private readonly defaultTimeoutOption?;
|
|
41
50
|
private readonly version;
|
|
42
51
|
constructor(options?: PaymentClientOptions);
|
|
43
52
|
protected makeError(message: string, statusCode?: number, responseBody?: string, cause?: unknown): KobilError;
|
|
53
|
+
/** Regular payment: the amount is charged once the user confirms. */
|
|
44
54
|
createTransaction(input: CreateTransactionInput, signal?: AbortSignal): Promise<TransactionResult>;
|
|
55
|
+
/** Pre-authorization: holds the amount until {@link postAuth}. Keep the result's `idempotencyKey`. */
|
|
45
56
|
createPreAuthTransaction(input: CreateTransactionInput, signal?: AbortSignal): Promise<TransactionResult>;
|
|
46
57
|
private createInternal;
|
|
58
|
+
/**
|
|
59
|
+
* Settles a pre-authorization (full amount when `amount` is omitted, partial otherwise).
|
|
60
|
+
*
|
|
61
|
+
* Miniapp mode correlates the capture with the pre-authorization through the idempotency key, so pass
|
|
62
|
+
* the pre-authorization result's `idempotencyKey` as `idempotencyId`.
|
|
63
|
+
*/
|
|
47
64
|
postAuth(input: PostAuthInput, signal?: AbortSignal): Promise<TransactionResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Asks for the transaction's status. The resolved status is delivered to the callback; miniapp mode
|
|
67
|
+
* also returns a snapshot of it in the response.
|
|
68
|
+
*/
|
|
48
69
|
getStatus(input: StatusInput, signal?: AbortSignal): Promise<TransactionResult>;
|
|
70
|
+
/** Cancels (voids) a transaction that is still in process. */
|
|
49
71
|
cancel(input: CancelInput, signal?: AbortSignal): Promise<TransactionResult>;
|
|
72
|
+
/** Refunds a completed transaction, fully or partially. Several partial refunds are allowed. */
|
|
50
73
|
refund(input: RefundInput, signal?: AbortSignal): Promise<TransactionResult>;
|
|
74
|
+
private paymentUrl;
|
|
75
|
+
/** MiniApp results name the id `paymentId`; mirror it as `transactionId` so callers read one field. */
|
|
76
|
+
private normalize;
|
|
77
|
+
private requireCallback;
|
|
78
|
+
private legacyTimeout;
|
|
51
79
|
private merchantId;
|
|
52
80
|
private merchantServiceUuid;
|
|
53
81
|
}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAEP,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,aAAa,EAKd,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,WAAW,EACX,sBAAsB,EAEtB,aAAa,EACb,WAAW,EACX,WAAW,EACX,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,oBAAqB,SAAQ,OAAO,CAAC,gBAAgB,CAAC,EAAE,eAAe;IACtF;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,4FAA4F;IAC5F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAC1C,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4GAA4G;IAC5G,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,kBAAkB;IACnD,QAAQ,CAAC,OAAO,EAAE,OAAO,C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AC,iBAAiB,CAAC;IAoClF,gGAAgG;IAC1F,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA0ClF,OAAO,CAAC,UAAU;IAIlB,uGAAuG;IACvG,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,mBAAmB;CAK5B"}
|
package/dist/client.js
CHANGED
|
@@ -3,9 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PaymentClient = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const kobil_core_1 = require("@uveysservetoglu/kobil-core");
|
|
6
|
+
const amount_1 = require("./amount");
|
|
6
7
|
const error_1 = require("./error");
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Client for KOBIL Pay: the MiniApp API's `/v1/payments` (default) or the legacy mpay-merchant API.
|
|
10
|
+
* Inputs are the same in both modes — amounts in minor units, timeouts in minutes — and are converted
|
|
11
|
+
* to the selected API's shape.
|
|
12
|
+
*/
|
|
8
13
|
class PaymentClient extends kobil_core_1.KobilServiceClient {
|
|
14
|
+
apiMode;
|
|
9
15
|
baseUrl;
|
|
10
16
|
clientId;
|
|
11
17
|
merchantName;
|
|
@@ -14,134 +20,239 @@ class PaymentClient extends kobil_core_1.KobilServiceClient {
|
|
|
14
20
|
tenantId;
|
|
15
21
|
defaultCurrency;
|
|
16
22
|
defaultMerchantCallback;
|
|
17
|
-
|
|
23
|
+
defaultTimeoutOption;
|
|
18
24
|
version;
|
|
19
25
|
constructor(options = {}) {
|
|
26
|
+
const apiMode = (0, kobil_core_1.resolveApiMode)(options.apiMode);
|
|
20
27
|
/**
|
|
21
|
-
*
|
|
28
|
+
* Legacy: payment authenticates as the **merchant** client, not as the MiniApp.
|
|
22
29
|
*
|
|
23
30
|
* They are two registrations with their own ids, secrets and tenants, and the payment API checks
|
|
24
31
|
* it: a token issued for the MiniApp's client is refused with `PAY_WRONG_CLIENT`. So the merchant
|
|
25
32
|
* credentials are what this client's token is fetched with, and `PAYMENT_MERCHANT_ID` doubles as
|
|
26
33
|
* the `merchantId` sent on the wire — the API requires those to be the same value.
|
|
27
34
|
*
|
|
28
|
-
*
|
|
35
|
+
* MiniApp API: one token — the MiniApp's own — serves every operation, and the merchant is named in
|
|
36
|
+
* the request body instead. So the shared `OIDC_*` credentials are used and `merchantId` only travels
|
|
37
|
+
* on the wire.
|
|
38
|
+
*
|
|
39
|
+
* `clientId`/`clientSecret` override either choice.
|
|
29
40
|
*/
|
|
41
|
+
const legacy = apiMode === "legacy";
|
|
30
42
|
const credentials = (0, kobil_core_1.credentialsFromEnv)({
|
|
31
43
|
tokenEndpoint: options.tokenEndpoint,
|
|
32
|
-
clientId: options.clientId ?? options.merchantId ?? process.env.PAYMENT_MERCHANT_ID,
|
|
33
|
-
clientSecret: options.clientSecret ?? process.env.PAYMENT_MERCHANT_SECRET,
|
|
44
|
+
clientId: legacy ? options.clientId ?? options.merchantId ?? process.env.PAYMENT_MERCHANT_ID : options.clientId,
|
|
45
|
+
clientSecret: legacy ? options.clientSecret ?? process.env.PAYMENT_MERCHANT_SECRET : options.clientSecret,
|
|
34
46
|
tokenAuthMode: options.tokenAuthMode,
|
|
35
47
|
defaultTokenTtlSeconds: options.defaultTokenTtlSeconds,
|
|
36
48
|
tokenExpirySkewSeconds: options.tokenExpirySkewSeconds,
|
|
37
|
-
});
|
|
49
|
+
}, { apiMode, apiBaseUrl: options.apiBaseUrl, realm: options.realm });
|
|
38
50
|
super(options.tokenProvider ?? new kobil_core_1.DefaultTokenProvider(credentials));
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
this.apiMode = apiMode;
|
|
52
|
+
if (legacy) {
|
|
53
|
+
const baseUrl = options.paymentBaseUrl || (0, kobil_core_1.paymentTransactionEndpoint)(process.env.PAYMENT_BASE);
|
|
54
|
+
if (!baseUrl)
|
|
55
|
+
throw new kobil_core_1.KobilError("No payment endpoint: set PAYMENT_BASE (or pass paymentBaseUrl).");
|
|
56
|
+
const merchantName = options.merchantName ?? process.env.PAYMENT_MERCHANT_NAME;
|
|
57
|
+
if (!merchantName)
|
|
58
|
+
throw new kobil_core_1.KobilError("No merchant name: set PAYMENT_MERCHANT_NAME (or pass merchantName).");
|
|
59
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
60
|
+
this.merchantName = merchantName;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.baseUrl = `${(0, kobil_core_1.miniappApiBase)(options.apiBaseUrl)}/v1/payments`;
|
|
64
|
+
this.merchantName = options.merchantName ?? process.env.PAYMENT_MERCHANT_NAME ?? "";
|
|
65
|
+
}
|
|
46
66
|
this.clientId = credentials.clientId;
|
|
47
|
-
this.merchantName = merchantName;
|
|
48
67
|
this.merchantIdOption = options.merchantId ?? process.env.PAYMENT_MERCHANT_ID;
|
|
49
68
|
this.merchantServiceUuidOption = options.merchantServiceUuid;
|
|
50
69
|
this.tenantId = options.tenantId ?? process.env.PAYMENT_TENANT_ID;
|
|
51
70
|
this.defaultCurrency = options.defaultCurrency ?? "TRY";
|
|
52
71
|
this.defaultMerchantCallback = options.defaultMerchantCallback;
|
|
53
|
-
this.
|
|
72
|
+
this.defaultTimeoutOption = options.defaultTransactionTimeoutMinutes;
|
|
54
73
|
this.version = options.version ?? 1;
|
|
55
74
|
}
|
|
56
75
|
makeError(message, statusCode, responseBody, cause) {
|
|
57
76
|
return new error_1.KobilPaymentError(message, { statusCode, responseBody, cause });
|
|
58
77
|
}
|
|
78
|
+
/** Regular payment: the amount is charged once the user confirms. */
|
|
59
79
|
createTransaction(input, signal) {
|
|
60
80
|
return this.createInternal(input, false, signal);
|
|
61
81
|
}
|
|
82
|
+
/** Pre-authorization: holds the amount until {@link postAuth}. Keep the result's `idempotencyKey`. */
|
|
62
83
|
createPreAuthTransaction(input, signal) {
|
|
63
84
|
return this.createInternal(input, true, signal);
|
|
64
85
|
}
|
|
65
|
-
createInternal(input, preAuth, signal) {
|
|
86
|
+
async createInternal(input, preAuth, signal) {
|
|
66
87
|
if (!input.userId)
|
|
67
88
|
throw new error_1.KobilPaymentError("userId cannot be empty.");
|
|
89
|
+
const idempotencyKey = input.idempotencyId ?? (0, crypto_1.randomUUID)();
|
|
90
|
+
const currency = (input.currency ?? this.defaultCurrency).toUpperCase();
|
|
91
|
+
if (this.apiMode === "miniapp") {
|
|
92
|
+
const timeoutMinutes = input.transactionTimeoutMinutes ?? this.defaultTimeoutOption;
|
|
93
|
+
const res = await this.sendJson("POST", `${this.baseUrl}/${preAuth ? "startPreAuth" : "start"}`, prune({
|
|
94
|
+
userId: input.userId,
|
|
95
|
+
merchantId: this.merchantId(),
|
|
96
|
+
amount: { value: (0, amount_1.formatMinorUnits)(input.amount, currency), currency },
|
|
97
|
+
callbackUrl: this.requireCallback(input.merchantCallback),
|
|
98
|
+
paymentContent: stringifyContent(input.paymentContent),
|
|
99
|
+
timeoutSeconds: timeoutMinutes === undefined ? undefined : timeoutMinutes * 60,
|
|
100
|
+
}), signal, { "idempotency-key": idempotencyKey });
|
|
101
|
+
return this.normalize(res, idempotencyKey);
|
|
102
|
+
}
|
|
68
103
|
const body = {
|
|
69
104
|
version: this.version,
|
|
70
|
-
idempotencyId:
|
|
105
|
+
idempotencyId: idempotencyKey,
|
|
71
106
|
userId: input.userId,
|
|
72
107
|
merchantId: this.merchantId(),
|
|
73
108
|
merchantServiceUUID: this.merchantServiceUuid(),
|
|
74
109
|
merchantName: this.merchantName,
|
|
75
110
|
merchantCallback: input.merchantCallback ?? this.defaultMerchantCallback,
|
|
76
|
-
transactionTimeout: input.transactionTimeoutMinutes ?? this.
|
|
111
|
+
transactionTimeout: input.transactionTimeoutMinutes ?? this.legacyTimeout(),
|
|
77
112
|
tenantId: this.tenantId,
|
|
78
113
|
amount: input.amount,
|
|
79
|
-
currency
|
|
114
|
+
currency,
|
|
80
115
|
paymentContent: input.paymentContent,
|
|
81
116
|
};
|
|
82
117
|
if (preAuth)
|
|
83
118
|
body.paymentTenantType = "preAuth";
|
|
84
|
-
|
|
119
|
+
const res = await this.sendJson("POST", this.baseUrl, prune(body), signal);
|
|
120
|
+
return { ...res, idempotencyKey };
|
|
85
121
|
}
|
|
86
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Settles a pre-authorization (full amount when `amount` is omitted, partial otherwise).
|
|
124
|
+
*
|
|
125
|
+
* Miniapp mode correlates the capture with the pre-authorization through the idempotency key, so pass
|
|
126
|
+
* the pre-authorization result's `idempotencyKey` as `idempotencyId`.
|
|
127
|
+
*/
|
|
128
|
+
async postAuth(input, signal) {
|
|
87
129
|
if (!input.transactionId)
|
|
88
130
|
throw new error_1.KobilPaymentError("transactionId cannot be empty.");
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
131
|
+
if (this.apiMode === "miniapp") {
|
|
132
|
+
if (!input.idempotencyId) {
|
|
133
|
+
throw new error_1.KobilPaymentError("postAuth needs idempotencyId in miniapp mode: pass the idempotencyKey returned by createPreAuthTransaction.");
|
|
134
|
+
}
|
|
135
|
+
const currency = (input.currency ?? this.defaultCurrency).toUpperCase();
|
|
136
|
+
const res = await this.sendJson("POST", `${this.paymentUrl(input.transactionId)}/capture`, prune({
|
|
137
|
+
callbackUrl: this.requireCallback(input.merchantCallback),
|
|
138
|
+
amount: input.amount === undefined ? undefined : { value: (0, amount_1.formatMinorUnits)(input.amount, currency), currency },
|
|
139
|
+
}), signal, { "idempotency-key": input.idempotencyId });
|
|
140
|
+
return this.normalize(res, input.idempotencyId);
|
|
141
|
+
}
|
|
142
|
+
const idempotencyKey = input.idempotencyId ?? (0, crypto_1.randomUUID)();
|
|
143
|
+
const query = new URLSearchParams({ id: input.transactionId, idempotencyId: idempotencyKey });
|
|
144
|
+
if (input.amount !== undefined)
|
|
145
|
+
query.set("amount", String(input.amount));
|
|
94
146
|
const callback = input.merchantCallback ?? this.defaultMerchantCallback;
|
|
95
147
|
if (callback)
|
|
96
148
|
query.set("merchantCallback", callback);
|
|
97
|
-
|
|
149
|
+
const res = await this.sendJson("GET", `${this.baseUrl}/postauth?${query.toString()}`, undefined, signal);
|
|
150
|
+
return { ...res, idempotencyKey };
|
|
98
151
|
}
|
|
99
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Asks for the transaction's status. The resolved status is delivered to the callback; miniapp mode
|
|
154
|
+
* also returns a snapshot of it in the response.
|
|
155
|
+
*/
|
|
156
|
+
async getStatus(input, signal) {
|
|
100
157
|
if (!input.transactionId)
|
|
101
158
|
throw new error_1.KobilPaymentError("transactionId cannot be empty.");
|
|
159
|
+
if (this.apiMode === "miniapp") {
|
|
160
|
+
const res = await this.sendJson("POST", `${this.paymentUrl(input.transactionId)}/checkStatus`, { merchantId: this.merchantId(), callbackUrl: this.requireCallback(input.merchantCallback) }, signal);
|
|
161
|
+
return this.normalize(res);
|
|
162
|
+
}
|
|
102
163
|
return this.sendJson("POST", `${this.baseUrl}/status`, prune({
|
|
103
164
|
merchantId: this.merchantId(),
|
|
104
165
|
merchantCallback: input.merchantCallback ?? this.defaultMerchantCallback,
|
|
105
166
|
transactionId: input.transactionId,
|
|
106
167
|
}), signal);
|
|
107
168
|
}
|
|
108
|
-
|
|
169
|
+
/** Cancels (voids) a transaction that is still in process. */
|
|
170
|
+
async cancel(input, signal) {
|
|
109
171
|
if (!input.transactionId)
|
|
110
172
|
throw new error_1.KobilPaymentError("transactionId cannot be empty.");
|
|
111
173
|
if (!input.userId)
|
|
112
174
|
throw new error_1.KobilPaymentError("userId cannot be empty.");
|
|
113
|
-
|
|
175
|
+
const idempotencyKey = input.idempotencyId ?? (0, crypto_1.randomUUID)();
|
|
176
|
+
const reason = input.reason ?? input.cancellationMessage;
|
|
177
|
+
if (this.apiMode === "miniapp") {
|
|
178
|
+
const res = await this.sendJson("POST", `${this.paymentUrl(input.transactionId)}/cancel`, {
|
|
179
|
+
userId: input.userId,
|
|
180
|
+
merchantId: this.merchantId(),
|
|
181
|
+
callbackUrl: this.requireCallback(input.merchantCallback),
|
|
182
|
+
reason: requireReason(reason),
|
|
183
|
+
}, signal, { "idempotency-key": idempotencyKey });
|
|
184
|
+
return this.normalize(res, idempotencyKey);
|
|
185
|
+
}
|
|
186
|
+
const res = await this.sendJson("POST", `${this.baseUrl}/void`, prune({
|
|
114
187
|
version: this.version,
|
|
115
188
|
userId: input.userId,
|
|
116
|
-
idempotencyId:
|
|
189
|
+
idempotencyId: idempotencyKey,
|
|
117
190
|
merchantServiceUUID: this.merchantServiceUuid(),
|
|
118
191
|
merchantCallback: input.merchantCallback ?? this.defaultMerchantCallback,
|
|
119
|
-
transactionTimeout: input.transactionTimeoutMinutes ?? this.
|
|
192
|
+
transactionTimeout: input.transactionTimeoutMinutes ?? this.legacyTimeout(),
|
|
120
193
|
merchantId: this.merchantId(),
|
|
121
194
|
paymentTransactionId: input.transactionId,
|
|
122
|
-
cancellationMessage:
|
|
195
|
+
cancellationMessage: reason,
|
|
123
196
|
}), signal);
|
|
197
|
+
return { ...res, idempotencyKey };
|
|
124
198
|
}
|
|
125
|
-
|
|
199
|
+
/** Refunds a completed transaction, fully or partially. Several partial refunds are allowed. */
|
|
200
|
+
async refund(input, signal) {
|
|
126
201
|
if (!input.transactionId)
|
|
127
202
|
throw new error_1.KobilPaymentError("transactionId cannot be empty.");
|
|
128
203
|
if (!input.userId)
|
|
129
204
|
throw new error_1.KobilPaymentError("userId cannot be empty.");
|
|
205
|
+
const idempotencyKey = input.idempotencyId ?? (0, crypto_1.randomUUID)();
|
|
206
|
+
const currency = (input.currency ?? this.defaultCurrency).toUpperCase();
|
|
207
|
+
const reason = input.reason ?? input.cancellationMessage;
|
|
208
|
+
if (this.apiMode === "miniapp") {
|
|
209
|
+
const res = await this.sendJson("POST", `${this.paymentUrl(input.transactionId)}/refund`, {
|
|
210
|
+
userId: input.userId,
|
|
211
|
+
merchantId: this.merchantId(),
|
|
212
|
+
amount: { value: (0, amount_1.formatMinorUnits)(input.amount, currency), currency },
|
|
213
|
+
callbackUrl: this.requireCallback(input.merchantCallback),
|
|
214
|
+
reason: requireReason(reason),
|
|
215
|
+
}, signal, { "idempotency-key": idempotencyKey });
|
|
216
|
+
return this.normalize(res, idempotencyKey);
|
|
217
|
+
}
|
|
130
218
|
const serviceUuid = this.merchantServiceUuid();
|
|
131
|
-
|
|
219
|
+
const res = await this.sendJson("POST", `${this.baseUrl}/refund`, prune({
|
|
132
220
|
version: this.version,
|
|
133
221
|
userId: input.userId,
|
|
134
|
-
idempotencyId:
|
|
222
|
+
idempotencyId: idempotencyKey,
|
|
135
223
|
merchantServiceUUID: serviceUuid,
|
|
136
224
|
merchantCallback: input.merchantCallback ?? this.defaultMerchantCallback,
|
|
137
|
-
transactionTimeout: input.transactionTimeoutMinutes ?? this.
|
|
225
|
+
transactionTimeout: input.transactionTimeoutMinutes ?? this.legacyTimeout(),
|
|
138
226
|
merchantId: this.merchantId(),
|
|
139
227
|
merchantUserId: input.userId,
|
|
140
228
|
paymentTransactionId: input.transactionId,
|
|
141
229
|
amount: input.amount,
|
|
142
|
-
currency
|
|
230
|
+
currency,
|
|
143
231
|
merchantServiceProviderId: serviceUuid,
|
|
144
232
|
}), signal);
|
|
233
|
+
return { ...res, idempotencyKey };
|
|
234
|
+
}
|
|
235
|
+
paymentUrl(transactionId) {
|
|
236
|
+
return `${this.baseUrl}/${encodeURIComponent(transactionId)}`;
|
|
237
|
+
}
|
|
238
|
+
/** MiniApp results name the id `paymentId`; mirror it as `transactionId` so callers read one field. */
|
|
239
|
+
normalize(res, idempotencyKey) {
|
|
240
|
+
const out = { ...res };
|
|
241
|
+
if (out.transactionId === undefined && out.paymentId !== undefined)
|
|
242
|
+
out.transactionId = out.paymentId;
|
|
243
|
+
if (idempotencyKey !== undefined)
|
|
244
|
+
out.idempotencyKey = idempotencyKey;
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
requireCallback(callback) {
|
|
248
|
+
const url = callback ?? this.defaultMerchantCallback;
|
|
249
|
+
if (!url) {
|
|
250
|
+
throw new error_1.KobilPaymentError("No callback URL: the MiniApp API requires one for every payment operation — pass merchantCallback or set defaultMerchantCallback.");
|
|
251
|
+
}
|
|
252
|
+
return url;
|
|
253
|
+
}
|
|
254
|
+
legacyTimeout() {
|
|
255
|
+
return this.defaultTimeoutOption ?? 59;
|
|
145
256
|
}
|
|
146
257
|
merchantId() {
|
|
147
258
|
return this.merchantIdOption && this.merchantIdOption.length > 0 ? this.merchantIdOption : this.clientId;
|
|
@@ -153,6 +264,16 @@ class PaymentClient extends kobil_core_1.KobilServiceClient {
|
|
|
153
264
|
}
|
|
154
265
|
}
|
|
155
266
|
exports.PaymentClient = PaymentClient;
|
|
267
|
+
function requireReason(reason) {
|
|
268
|
+
if (!reason) {
|
|
269
|
+
throw new error_1.KobilPaymentError("A reason is required in miniapp mode: pass reason (or cancellationMessage).");
|
|
270
|
+
}
|
|
271
|
+
return reason;
|
|
272
|
+
}
|
|
273
|
+
/** The MiniApp API takes display values as strings. */
|
|
274
|
+
function stringifyContent(content) {
|
|
275
|
+
return content?.map((group) => group.map(({ key, value }) => ({ key, value: String(value) })));
|
|
276
|
+
}
|
|
156
277
|
/** Removes undefined/null properties so optional fields are omitted from the JSON body. */
|
|
157
278
|
function prune(obj) {
|
|
158
279
|
const out = {};
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AACpC,4DAQqC;AACrC,mCAA4C;AAsC5C,oDAAoD;AACpD,MAAa,aAAc,SAAQ,+BAAkB;IAClC,OAAO,CAAS;IAChB,QAAQ,CAAS;IACjB,YAAY,CAAS;IACrB,gBAAgB,CAAU;IAC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AK,CAAC;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { PaymentClient } from "./client";
|
|
|
2
2
|
export type { PaymentClientOptions } from "./client";
|
|
3
3
|
export { KobilPaymentError } from "./error";
|
|
4
4
|
export { paymentGroup, paymentGroups } from "./content";
|
|
5
|
+
export { currencyExponent, formatMinorUnits } from "./amount";
|
|
5
6
|
export { parsePaymentStatus } from "./types";
|
|
6
7
|
export type { CreateTransactionInput, PostAuthInput, StatusInput, CancelInput, RefundInput, TransactionResult, PaymentContent, PaymentContentItem, PaymentStatus, } from "./types";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,YAAY,EACV,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,aAAa,GACd,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,YAAY,EACV,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,aAAa,GACd,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePaymentStatus = exports.paymentGroups = exports.paymentGroup = exports.KobilPaymentError = exports.PaymentClient = void 0;
|
|
3
|
+
exports.parsePaymentStatus = exports.formatMinorUnits = exports.currencyExponent = exports.paymentGroups = exports.paymentGroup = exports.KobilPaymentError = exports.PaymentClient = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "PaymentClient", { enumerable: true, get: function () { return client_1.PaymentClient; } });
|
|
6
6
|
var error_1 = require("./error");
|
|
@@ -8,6 +8,9 @@ Object.defineProperty(exports, "KobilPaymentError", { enumerable: true, get: fun
|
|
|
8
8
|
var content_1 = require("./content");
|
|
9
9
|
Object.defineProperty(exports, "paymentGroup", { enumerable: true, get: function () { return content_1.paymentGroup; } });
|
|
10
10
|
Object.defineProperty(exports, "paymentGroups", { enumerable: true, get: function () { return content_1.paymentGroups; } });
|
|
11
|
+
var amount_1 = require("./amount");
|
|
12
|
+
Object.defineProperty(exports, "currencyExponent", { enumerable: true, get: function () { return amount_1.currencyExponent; } });
|
|
13
|
+
Object.defineProperty(exports, "formatMinorUnits", { enumerable: true, get: function () { return amount_1.formatMinorUnits; } });
|
|
11
14
|
var types_1 = require("./types");
|
|
12
15
|
Object.defineProperty(exports, "parsePaymentStatus", { enumerable: true, get: function () { return types_1.parsePaymentStatus; } });
|
|
13
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AAEtB,iCAA4C;AAAnC,0GAAA,iBAAiB,OAAA;AAC1B,qCAAwD;AAA/C,uGAAA,YAAY,OAAA;AAAE,wGAAA,aAAa,OAAA;AACpC,iCAA6C;AAApC,2GAAA,kBAAkB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AAEtB,iCAA4C;AAAnC,0GAAA,iBAAiB,OAAA;AAC1B,qCAAwD;AAA/C,uGAAA,YAAY,OAAA;AAAE,wGAAA,aAAa,OAAA;AACpC,mCAA8D;AAArD,0GAAA,gBAAgB,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAC3C,iCAA6C;AAApC,2GAAA,kBAAkB,OAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
1
|
/** A single key/value line shown to the payer. */
|
|
2
2
|
export interface PaymentContentItem {
|
|
3
3
|
key: string;
|
|
4
|
+
/** Sent as-is in legacy mode; converted to a string in miniapp mode (max 128 characters). */
|
|
4
5
|
value: unknown;
|
|
5
6
|
}
|
|
6
7
|
/** Payment content is a list of groups, each group a list of key/value lines. */
|
|
7
8
|
export type PaymentContent = PaymentContentItem[][];
|
|
8
9
|
export interface CreateTransactionInput {
|
|
9
10
|
userId: string;
|
|
10
|
-
/** Amount in the smallest currency unit (e.g. 1300 = 13.00 TRY). */
|
|
11
|
+
/** Amount in the smallest currency unit (e.g. 1300 = 13.00 TRY), in both API modes. */
|
|
11
12
|
amount: number;
|
|
12
13
|
currency?: string;
|
|
14
|
+
/** Result callback. Required in miniapp mode (here or as `defaultMerchantCallback`). */
|
|
13
15
|
merchantCallback?: string;
|
|
16
|
+
/** Minutes. Miniapp mode sends it as `timeoutSeconds` (600–3600 s); omit it there for the 15-minute default. */
|
|
14
17
|
transactionTimeoutMinutes?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Idempotency key. Generated when omitted and returned as `idempotencyKey` on the result — keep the
|
|
20
|
+
* pre-authorization's: miniapp mode needs it again for `postAuth`.
|
|
21
|
+
*/
|
|
15
22
|
idempotencyId?: string;
|
|
16
23
|
paymentContent?: PaymentContent;
|
|
17
24
|
}
|
|
18
25
|
export interface PostAuthInput {
|
|
19
26
|
transactionId: string;
|
|
20
|
-
/** Final amount to settle, in the smallest currency unit. */
|
|
21
|
-
amount
|
|
27
|
+
/** Final amount to settle, in the smallest currency unit. Omit to capture the full pre-authorized amount. */
|
|
28
|
+
amount?: number;
|
|
29
|
+
/** Currency of `amount` (miniapp mode). Defaults to the client's default currency. */
|
|
30
|
+
currency?: string;
|
|
22
31
|
merchantCallback?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Legacy mode: a fresh key for this request (generated when omitted).
|
|
34
|
+
* Miniapp mode: **required** — the `idempotencyKey` of the pre-authorization being captured.
|
|
35
|
+
*/
|
|
23
36
|
idempotencyId?: string;
|
|
24
37
|
}
|
|
25
38
|
export interface StatusInput {
|
|
26
39
|
transactionId: string;
|
|
40
|
+
/** Required in miniapp mode (here or as `defaultMerchantCallback`): the fresh status is POSTed there. */
|
|
27
41
|
merchantCallback?: string;
|
|
28
42
|
}
|
|
29
43
|
export interface CancelInput {
|
|
30
44
|
transactionId: string;
|
|
31
45
|
userId: string;
|
|
46
|
+
/** Reason for the cancellation. Required in miniapp mode (as `reason` or `cancellationMessage`). */
|
|
32
47
|
cancellationMessage?: string;
|
|
48
|
+
/** Alias of `cancellationMessage`, matching the MiniApp API's name. */
|
|
49
|
+
reason?: string;
|
|
33
50
|
merchantCallback?: string;
|
|
51
|
+
/** Legacy mode only. */
|
|
34
52
|
transactionTimeoutMinutes?: number;
|
|
35
53
|
idempotencyId?: string;
|
|
36
54
|
}
|
|
@@ -40,16 +58,30 @@ export interface RefundInput {
|
|
|
40
58
|
/** Amount to refund, in the smallest currency unit. */
|
|
41
59
|
amount: number;
|
|
42
60
|
currency?: string;
|
|
61
|
+
/** Reason for the refund. Required in miniapp mode (as `reason` or `cancellationMessage`). */
|
|
43
62
|
cancellationMessage?: string;
|
|
63
|
+
/** Alias of `cancellationMessage`, matching the MiniApp API's name. */
|
|
64
|
+
reason?: string;
|
|
44
65
|
merchantCallback?: string;
|
|
66
|
+
/** Legacy mode only. */
|
|
45
67
|
transactionTimeoutMinutes?: number;
|
|
46
68
|
idempotencyId?: string;
|
|
47
69
|
}
|
|
48
70
|
export interface TransactionResult {
|
|
71
|
+
/**
|
|
72
|
+
* The transaction id. In miniapp mode this mirrors `paymentId` (the refund's own id for a refund, the
|
|
73
|
+
* settlement id for a capture), so code written against either mode reads the same field.
|
|
74
|
+
*/
|
|
49
75
|
transactionId?: string;
|
|
76
|
+
/** MiniApp API's transaction id. */
|
|
77
|
+
paymentId?: string;
|
|
50
78
|
operationId?: string;
|
|
51
79
|
status?: string;
|
|
52
80
|
message?: string;
|
|
81
|
+
/** MiniApp API: when the operation was accepted (ISO 8601). */
|
|
82
|
+
createdAt?: string;
|
|
83
|
+
/** The idempotency key the request was sent with. Keep a pre-authorization's for `postAuth`. */
|
|
84
|
+
idempotencyKey?: string;
|
|
53
85
|
/** Present on pre-auth: URL/handle to continue with post-auth. */
|
|
54
86
|
nextAction?: string;
|
|
55
87
|
transactionStatus?: string;
|
|
@@ -57,7 +89,7 @@ export interface TransactionResult {
|
|
|
57
89
|
gateway?: string;
|
|
58
90
|
[key: string]: unknown;
|
|
59
91
|
}
|
|
60
|
-
export type PaymentStatus = "new" | "processing" | "processing_3d_secure" | "processing_digital" | "finished" | "cancelled" | "closed" | "timeout" | "error" | "void" | "refund" | "unknown";
|
|
61
|
-
/** Returns the strongly-typed status, preferring `transactionStatus` then `status`. */
|
|
92
|
+
export type PaymentStatus = "new" | "processing" | "processing_3d_secure" | "processing_digital" | "finished" | "cancelled" | "closed" | "timeout" | "error" | "void" | "refund" | "inquiring" | "cancellation" | "notification" | "requiresRefund" | "failed" | "unknown";
|
|
93
|
+
/** Returns the strongly-typed status, preferring `transactionStatus` then `status`. Case-insensitive. */
|
|
62
94
|
export declare function parsePaymentStatus(result: TransactionResult): PaymentStatus;
|
|
63
95
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,kBAAkB,EAAE,EAAE,CAAC;AAEpD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,6FAA6F;IAC7F,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,kBAAkB,EAAE,EAAE,CAAC;AAEpD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gHAAgH;IAChH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,cAA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;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gGAAgG;IAChG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,YAAY,GACZ,sBAAsB,GACtB,oBAAoB,GACpB,UAAU,GACV,WAAW,GACX,QAAQ,GACR,SAAS,GACT,OAAO,GACP,MAAM,GACN,QAAQ,GACR,WAAW,GACX,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,QAAQ,GACR,SAAS,CAAC;AAUd,yGAAyG;AACzG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,aAAa,CAG3E"}
|
package/dist/types.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parsePaymentStatus = parsePaymentStatus;
|
|
4
|
-
|
|
4
|
+
const KNOWN_STATUSES = [
|
|
5
|
+
"new", "processing", "processing_3d_secure", "processing_digital",
|
|
6
|
+
"finished", "cancelled", "closed", "timeout", "error", "void", "refund",
|
|
7
|
+
"inquiring", "cancellation", "notification", "requiresRefund", "failed",
|
|
8
|
+
];
|
|
9
|
+
const STATUS_BY_LOWERCASE = new Map(KNOWN_STATUSES.map((s) => [s.toLowerCase(), s]));
|
|
10
|
+
/** Returns the strongly-typed status, preferring `transactionStatus` then `status`. Case-insensitive. */
|
|
5
11
|
function parsePaymentStatus(result) {
|
|
6
|
-
const known = [
|
|
7
|
-
"new", "processing", "processing_3d_secure", "processing_digital",
|
|
8
|
-
"finished", "cancelled", "closed", "timeout", "error", "void", "refund",
|
|
9
|
-
];
|
|
10
12
|
const raw = (result.transactionStatus ?? result.status ?? "").toLowerCase();
|
|
11
|
-
return
|
|
13
|
+
return STATUS_BY_LOWERCASE.get(raw) ?? "unknown";
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AA+HA,gDAGC;AAZD,MAAM,cAAc,GAAoB;IACtC,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,oBAAoB;IACjE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ;IACvE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ;CACxE,CAAC;AAEF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAErF,yGAAyG;AACzG,SAAgB,kBAAkB,CAAC,MAAyB;IAC1D,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5E,OAAO,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;AACnD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uveysservetoglu/kobil-payment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "KOBIL Pay (mpay-merchant) client for Node.js: create/pre-auth/post-auth, status, cancel and refund transactions with automatic OAuth token management.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "https://github.com/uveysservetoglu/kobil-sdks"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@uveysservetoglu/kobil-core": "^
|
|
22
|
+
"@uveysservetoglu/kobil-core": "^3.0.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc -b"
|