@kuvarpay/sdk 1.2.1 → 1.3.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/index.js +21 -14
- package/index.mjs +18 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -221,13 +221,14 @@ class KuvarPayServer {
|
|
|
221
221
|
const payload = Object.assign({}, checkoutSessionData, {
|
|
222
222
|
businessId: checkoutSessionData.businessId || this.businessId,
|
|
223
223
|
});
|
|
224
|
-
// payload can include 'subaccount' (string) or 'split_code' (string)
|
|
225
|
-
// Guide says /api/v1/checkout-sessions
|
|
226
224
|
const data = await this._post('/api/v1/checkout-sessions', payload);
|
|
225
|
+
const body = data.data || data.checkoutSession || data;
|
|
227
226
|
return {
|
|
228
|
-
sessionId:
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
sessionId: body.sessionId || body.id || body.uid,
|
|
228
|
+
amount: body.amount,
|
|
229
|
+
currency: body.currency,
|
|
230
|
+
authToken: body.authToken,
|
|
231
|
+
approvalUrl: body.approvalUrl || body.approval_url,
|
|
231
232
|
raw: data,
|
|
232
233
|
};
|
|
233
234
|
}
|
|
@@ -274,15 +275,12 @@ class KuvarPayServer {
|
|
|
274
275
|
|
|
275
276
|
const session = await this.createCheckoutSession(sessionData);
|
|
276
277
|
|
|
277
|
-
// 2. Create Transaction using the
|
|
278
|
+
// 2. Create Transaction using the session. We omit toAmount/toCurrency
|
|
279
|
+
// to let the API use the values already locked into the session.
|
|
278
280
|
const transactionData = {
|
|
279
281
|
checkoutSessionId: session.sessionId,
|
|
280
282
|
fromCurrency: data.fromCurrency,
|
|
281
283
|
fromNetwork: data.fromNetwork,
|
|
282
|
-
toCurrency: data.toCurrency || data.currency,
|
|
283
|
-
toAmount: data.toAmount || data.amount,
|
|
284
|
-
subaccountCode: data.subaccountCode || data.subaccount,
|
|
285
|
-
splitCode: data.splitCode || data.split_code,
|
|
286
284
|
description: data.description,
|
|
287
285
|
metadata: data.metadata,
|
|
288
286
|
};
|
|
@@ -391,9 +389,19 @@ class KuvarPayServer {
|
|
|
391
389
|
businessId: subscriptionData?.businessId || this.businessId,
|
|
392
390
|
}, subscriptionData);
|
|
393
391
|
const data = await this._post('/api/v1/subscriptions/checkout-sessions', payload);
|
|
392
|
+
const body = data.data || data.checkoutSession || data;
|
|
393
|
+
const approvalUrl = body.approvalUrl || body.approval_url || body.approvalUrl;
|
|
394
|
+
|
|
395
|
+
// Fallback: Extract ID from approval URL if missing (e.g., .../subscriptions/ID)
|
|
396
|
+
let sessionId = body.sessionId || body.id || body.uid;
|
|
397
|
+
if (!sessionId && approvalUrl) {
|
|
398
|
+
const parts = approvalUrl.split('/');
|
|
399
|
+
sessionId = parts[parts.length - 1];
|
|
400
|
+
}
|
|
401
|
+
|
|
394
402
|
return {
|
|
395
|
-
sessionId
|
|
396
|
-
approvalUrl
|
|
403
|
+
sessionId,
|
|
404
|
+
approvalUrl,
|
|
397
405
|
raw: data,
|
|
398
406
|
};
|
|
399
407
|
}
|
|
@@ -474,10 +482,9 @@ class KuvarPayServer {
|
|
|
474
482
|
*/
|
|
475
483
|
async createDirectSubscription(data) {
|
|
476
484
|
const payload = Object.assign({
|
|
477
|
-
billingMode: data.billingMode || 'FIXED',
|
|
485
|
+
billingMode: data.amount ? 'METERED' : (data.billingMode || 'FIXED'),
|
|
478
486
|
}, data);
|
|
479
487
|
|
|
480
|
-
// If amount/currency is provided but expectedUsage is not, map it
|
|
481
488
|
if (data.amount && data.currency && !data.expectedUsage) {
|
|
482
489
|
payload.expectedUsage = {
|
|
483
490
|
amount: data.amount,
|
package/index.mjs
CHANGED
|
@@ -164,12 +164,14 @@ export class KuvarPayServer {
|
|
|
164
164
|
const payload = Object.assign({}, checkoutSessionData, {
|
|
165
165
|
businessId: checkoutSessionData.businessId || this.businessId,
|
|
166
166
|
});
|
|
167
|
-
// payload can include 'subaccount' (string) or 'split_code' (string)
|
|
168
167
|
const data = await this._post('/api/v1/checkout-sessions', payload);
|
|
168
|
+
const body = data.data || data.checkoutSession || data;
|
|
169
169
|
return {
|
|
170
|
-
sessionId:
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
sessionId: body.sessionId || body.id || body.uid,
|
|
171
|
+
amount: body.amount,
|
|
172
|
+
currency: body.currency,
|
|
173
|
+
authToken: body.authToken,
|
|
174
|
+
approvalUrl: body.approvalUrl || body.approval_url,
|
|
173
175
|
raw: data,
|
|
174
176
|
};
|
|
175
177
|
}
|
|
@@ -208,10 +210,6 @@ export class KuvarPayServer {
|
|
|
208
210
|
checkoutSessionId: session.sessionId,
|
|
209
211
|
fromCurrency: data.fromCurrency,
|
|
210
212
|
fromNetwork: data.fromNetwork,
|
|
211
|
-
toCurrency: data.toCurrency || data.currency,
|
|
212
|
-
toAmount: data.toAmount || data.amount,
|
|
213
|
-
subaccountCode: data.subaccountCode || data.subaccount,
|
|
214
|
-
splitCode: data.splitCode || data.split_code,
|
|
215
213
|
description: data.description,
|
|
216
214
|
metadata: data.metadata,
|
|
217
215
|
};
|
|
@@ -276,9 +274,18 @@ export class KuvarPayServer {
|
|
|
276
274
|
businessId: subscriptionData?.businessId || this.businessId,
|
|
277
275
|
}, subscriptionData);
|
|
278
276
|
const data = await this._post('/api/v1/subscriptions/checkout-sessions', payload);
|
|
277
|
+
const body = data.data || data.checkoutSession || data;
|
|
278
|
+
const approvalUrl = body.approvalUrl || body.approval_url || body.approvalUrl;
|
|
279
|
+
|
|
280
|
+
let sessionId = body.sessionId || body.id || body.uid;
|
|
281
|
+
if (!sessionId && approvalUrl) {
|
|
282
|
+
const parts = approvalUrl.split('/');
|
|
283
|
+
sessionId = parts[parts.length - 1];
|
|
284
|
+
}
|
|
285
|
+
|
|
279
286
|
return {
|
|
280
|
-
sessionId
|
|
281
|
-
approvalUrl
|
|
287
|
+
sessionId,
|
|
288
|
+
approvalUrl,
|
|
282
289
|
raw: data,
|
|
283
290
|
};
|
|
284
291
|
}
|
|
@@ -330,7 +337,7 @@ export class KuvarPayServer {
|
|
|
330
337
|
|
|
331
338
|
async createDirectSubscription(data) {
|
|
332
339
|
const payload = Object.assign({
|
|
333
|
-
billingMode: data.billingMode || 'FIXED',
|
|
340
|
+
billingMode: data.amount ? 'METERED' : (data.billingMode || 'FIXED'),
|
|
334
341
|
}, data);
|
|
335
342
|
|
|
336
343
|
if (data.amount && data.currency && !data.expectedUsage) {
|