@kuvarpay/sdk 1.2.0 → 1.2.2
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.d.ts +23 -0
- package/index.js +62 -5
- package/index.mjs +49 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -56,6 +56,22 @@ export class KuvarPayServer {
|
|
|
56
56
|
[key: string]: any;
|
|
57
57
|
}): Promise<{ sessionId: string; authToken?: string; approvalUrl?: string; raw: any }>;
|
|
58
58
|
|
|
59
|
+
createDirectPayment(data: {
|
|
60
|
+
amount: number;
|
|
61
|
+
currency: string;
|
|
62
|
+
fromCurrency: string;
|
|
63
|
+
fromNetwork: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
customerEmail?: string;
|
|
66
|
+
customerName?: string;
|
|
67
|
+
redirectUrl?: string;
|
|
68
|
+
callbackUrl?: string;
|
|
69
|
+
metadata?: Record<string, any>;
|
|
70
|
+
subaccount?: string;
|
|
71
|
+
splitCode?: string;
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
}): Promise<any>;
|
|
74
|
+
|
|
59
75
|
createTransaction(transactionData: {
|
|
60
76
|
amount: number;
|
|
61
77
|
currency: string;
|
|
@@ -98,6 +114,13 @@ export class KuvarPayServer {
|
|
|
98
114
|
|
|
99
115
|
// Subscriptions
|
|
100
116
|
createSubscriptionCheckoutSession(subscriptionData: Record<string, any>): Promise<{ sessionId: string; approvalUrl?: string; raw: any }>;
|
|
117
|
+
createDirectSubscription(data: {
|
|
118
|
+
amount: number;
|
|
119
|
+
currency: string;
|
|
120
|
+
customer: { email: string; firstName?: string; lastName?: string };
|
|
121
|
+
billingMode?: 'FIXED' | 'METERED';
|
|
122
|
+
[key: string]: any;
|
|
123
|
+
}): Promise<{ sessionId: string; approvalUrl?: string; raw: any }>;
|
|
101
124
|
getSubscriptionCheckoutSession(id: string): Promise<any>;
|
|
102
125
|
confirmSubscriptionCheckoutSession(id: string, body?: Record<string, any>): Promise<any>;
|
|
103
126
|
|
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
|
}
|
|
@@ -251,6 +252,42 @@ class KuvarPayServer {
|
|
|
251
252
|
return this._post('/api/v1/transactions/create', payload);
|
|
252
253
|
}
|
|
253
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Create a payment session and initiate a transaction in one call (Headless Flow)
|
|
257
|
+
* @param {Object} data - Combines checkout session and transaction data
|
|
258
|
+
* @returns {Promise<any>} The created transaction object
|
|
259
|
+
*/
|
|
260
|
+
async createDirectPayment(data) {
|
|
261
|
+
// 1. Create Checkout Session
|
|
262
|
+
const sessionData = {
|
|
263
|
+
amount: data.amount,
|
|
264
|
+
currency: data.currency,
|
|
265
|
+
description: data.description,
|
|
266
|
+
customerEmail: data.customerEmail,
|
|
267
|
+
customerName: data.customerName,
|
|
268
|
+
redirectUrl: data.redirectUrl,
|
|
269
|
+
callbackUrl: data.callbackUrl,
|
|
270
|
+
expiresIn: data.expiresIn,
|
|
271
|
+
metadata: data.metadata,
|
|
272
|
+
subaccount: data.subaccount,
|
|
273
|
+
split_code: data.split_code || data.splitCode
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const session = await this.createCheckoutSession(sessionData);
|
|
277
|
+
|
|
278
|
+
// 2. Create Transaction using the session. We omit toAmount/toCurrency
|
|
279
|
+
// to let the API use the values already locked into the session.
|
|
280
|
+
const transactionData = {
|
|
281
|
+
checkoutSessionId: session.sessionId,
|
|
282
|
+
fromCurrency: data.fromCurrency,
|
|
283
|
+
fromNetwork: data.fromNetwork,
|
|
284
|
+
description: data.description,
|
|
285
|
+
metadata: data.metadata,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
return this.createTransaction(transactionData);
|
|
289
|
+
}
|
|
290
|
+
|
|
254
291
|
/**
|
|
255
292
|
* Email an invoice to a customer
|
|
256
293
|
*/
|
|
@@ -429,6 +466,26 @@ class KuvarPayServer {
|
|
|
429
466
|
return this.createMeteredInvoice(subscriptionId, invoiceData);
|
|
430
467
|
}
|
|
431
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Convenience method to initiate a subscription setup
|
|
471
|
+
* @param {Object} data - { amount, currency, customer: {email}, billingMode, ... }
|
|
472
|
+
*/
|
|
473
|
+
async createDirectSubscription(data) {
|
|
474
|
+
const payload = Object.assign({
|
|
475
|
+
billingMode: data.billingMode || 'FIXED',
|
|
476
|
+
}, data);
|
|
477
|
+
|
|
478
|
+
// If amount/currency is provided but expectedUsage is not, map it
|
|
479
|
+
if (data.amount && data.currency && !data.expectedUsage) {
|
|
480
|
+
payload.expectedUsage = {
|
|
481
|
+
amount: data.amount,
|
|
482
|
+
currency: data.currency
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return this.createSubscriptionCheckoutSession(payload);
|
|
487
|
+
}
|
|
488
|
+
|
|
432
489
|
/**
|
|
433
490
|
* Schedule a subscription invoice (convenience wrapper)
|
|
434
491
|
*/
|
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
|
}
|
|
@@ -187,6 +189,34 @@ export class KuvarPayServer {
|
|
|
187
189
|
return this._post('/api/v1/transactions/create', payload);
|
|
188
190
|
}
|
|
189
191
|
|
|
192
|
+
async createDirectPayment(data) {
|
|
193
|
+
const sessionData = {
|
|
194
|
+
amount: data.amount,
|
|
195
|
+
currency: data.currency,
|
|
196
|
+
description: data.description,
|
|
197
|
+
customerEmail: data.customerEmail,
|
|
198
|
+
customerName: data.customerName,
|
|
199
|
+
redirectUrl: data.redirectUrl,
|
|
200
|
+
callbackUrl: data.callbackUrl,
|
|
201
|
+
expiresIn: data.expiresIn,
|
|
202
|
+
metadata: data.metadata,
|
|
203
|
+
subaccount: data.subaccount,
|
|
204
|
+
split_code: data.split_code || data.splitCode
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const session = await this.createCheckoutSession(sessionData);
|
|
208
|
+
|
|
209
|
+
const transactionData = {
|
|
210
|
+
checkoutSessionId: session.sessionId,
|
|
211
|
+
fromCurrency: data.fromCurrency,
|
|
212
|
+
fromNetwork: data.fromNetwork,
|
|
213
|
+
description: data.description,
|
|
214
|
+
metadata: data.metadata,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
return this.createTransaction(transactionData);
|
|
218
|
+
}
|
|
219
|
+
|
|
190
220
|
async sendInvoiceEmail(sessionId) {
|
|
191
221
|
return this._post(`/api/v1/invoices/${encodeURIComponent(sessionId)}/send-email`, {});
|
|
192
222
|
}
|
|
@@ -296,6 +326,21 @@ export class KuvarPayServer {
|
|
|
296
326
|
return this.createMeteredInvoice(subscriptionId, invoiceData);
|
|
297
327
|
}
|
|
298
328
|
|
|
329
|
+
async createDirectSubscription(data) {
|
|
330
|
+
const payload = Object.assign({
|
|
331
|
+
billingMode: data.billingMode || 'FIXED',
|
|
332
|
+
}, data);
|
|
333
|
+
|
|
334
|
+
if (data.amount && data.currency && !data.expectedUsage) {
|
|
335
|
+
payload.expectedUsage = {
|
|
336
|
+
amount: data.amount,
|
|
337
|
+
currency: data.currency
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return this.createSubscriptionCheckoutSession(payload);
|
|
342
|
+
}
|
|
343
|
+
|
|
299
344
|
async scheduleSubscriptionInvoice(subscriptionId, invoiceData) {
|
|
300
345
|
if (!invoiceData?.dueDate) throw new Error('dueDate is required to schedule an invoice');
|
|
301
346
|
const payload = Object.assign({}, invoiceData, { chargeSchedule: 'SCHEDULED' });
|