@kuvarpay/sdk 1.2.2 → 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 +13 -4
- package/index.mjs +12 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -389,9 +389,19 @@ class KuvarPayServer {
|
|
|
389
389
|
businessId: subscriptionData?.businessId || this.businessId,
|
|
390
390
|
}, subscriptionData);
|
|
391
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
|
+
|
|
392
402
|
return {
|
|
393
|
-
sessionId
|
|
394
|
-
approvalUrl
|
|
403
|
+
sessionId,
|
|
404
|
+
approvalUrl,
|
|
395
405
|
raw: data,
|
|
396
406
|
};
|
|
397
407
|
}
|
|
@@ -472,10 +482,9 @@ class KuvarPayServer {
|
|
|
472
482
|
*/
|
|
473
483
|
async createDirectSubscription(data) {
|
|
474
484
|
const payload = Object.assign({
|
|
475
|
-
billingMode: data.billingMode || 'FIXED',
|
|
485
|
+
billingMode: data.amount ? 'METERED' : (data.billingMode || 'FIXED'),
|
|
476
486
|
}, data);
|
|
477
487
|
|
|
478
|
-
// If amount/currency is provided but expectedUsage is not, map it
|
|
479
488
|
if (data.amount && data.currency && !data.expectedUsage) {
|
|
480
489
|
payload.expectedUsage = {
|
|
481
490
|
amount: data.amount,
|
package/index.mjs
CHANGED
|
@@ -274,9 +274,18 @@ export class KuvarPayServer {
|
|
|
274
274
|
businessId: subscriptionData?.businessId || this.businessId,
|
|
275
275
|
}, subscriptionData);
|
|
276
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
|
+
|
|
277
286
|
return {
|
|
278
|
-
sessionId
|
|
279
|
-
approvalUrl
|
|
287
|
+
sessionId,
|
|
288
|
+
approvalUrl,
|
|
280
289
|
raw: data,
|
|
281
290
|
};
|
|
282
291
|
}
|
|
@@ -328,7 +337,7 @@ export class KuvarPayServer {
|
|
|
328
337
|
|
|
329
338
|
async createDirectSubscription(data) {
|
|
330
339
|
const payload = Object.assign({
|
|
331
|
-
billingMode: data.billingMode || 'FIXED',
|
|
340
|
+
billingMode: data.amount ? 'METERED' : (data.billingMode || 'FIXED'),
|
|
332
341
|
}, data);
|
|
333
342
|
|
|
334
343
|
if (data.amount && data.currency && !data.expectedUsage) {
|