@kuvarpay/sdk 1.1.0 → 1.2.1

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 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
@@ -10,10 +10,10 @@
10
10
 
11
11
  const crypto = require('crypto');
12
12
 
13
- const DEFAULT_BASE = (process.env.PAYMENT_API_BASE_URL
14
- || process.env.PAYMENT_SERVER_URL
15
- || process.env.NEXT_PUBLIC_PAYMENT_API_BASE_URL
16
- || 'http://localhost:3002').replace(/\/+$/, '');
13
+ const DEFAULT_BASE = (process.env.KUVARPAY_API_BASE_URL
14
+ || process.env.PAYMENT_API_BASE_URL
15
+ || 'https://payment.kuvarpay.com'
16
+ ).replace(/\/$/, '');
17
17
 
18
18
  class KuvarPayServer {
19
19
  /**
@@ -251,6 +251,45 @@ class KuvarPayServer {
251
251
  return this._post('/api/v1/transactions/create', payload);
252
252
  }
253
253
 
254
+ /**
255
+ * Create a payment session and initiate a transaction in one call (Headless Flow)
256
+ * @param {Object} data - Combines checkout session and transaction data
257
+ * @returns {Promise<any>} The created transaction object
258
+ */
259
+ async createDirectPayment(data) {
260
+ // 1. Create Checkout Session
261
+ const sessionData = {
262
+ amount: data.amount,
263
+ currency: data.currency,
264
+ description: data.description,
265
+ customerEmail: data.customerEmail,
266
+ customerName: data.customerName,
267
+ redirectUrl: data.redirectUrl,
268
+ callbackUrl: data.callbackUrl,
269
+ expiresIn: data.expiresIn,
270
+ metadata: data.metadata,
271
+ subaccount: data.subaccount,
272
+ split_code: data.split_code || data.splitCode
273
+ };
274
+
275
+ const session = await this.createCheckoutSession(sessionData);
276
+
277
+ // 2. Create Transaction using the new Session ID
278
+ const transactionData = {
279
+ checkoutSessionId: session.sessionId,
280
+ fromCurrency: data.fromCurrency,
281
+ 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
+ description: data.description,
287
+ metadata: data.metadata,
288
+ };
289
+
290
+ return this.createTransaction(transactionData);
291
+ }
292
+
254
293
  /**
255
294
  * Email an invoice to a customer
256
295
  */
@@ -429,6 +468,26 @@ class KuvarPayServer {
429
468
  return this.createMeteredInvoice(subscriptionId, invoiceData);
430
469
  }
431
470
 
471
+ /**
472
+ * Convenience method to initiate a subscription setup
473
+ * @param {Object} data - { amount, currency, customer: {email}, billingMode, ... }
474
+ */
475
+ async createDirectSubscription(data) {
476
+ const payload = Object.assign({
477
+ billingMode: data.billingMode || 'FIXED',
478
+ }, data);
479
+
480
+ // If amount/currency is provided but expectedUsage is not, map it
481
+ if (data.amount && data.currency && !data.expectedUsage) {
482
+ payload.expectedUsage = {
483
+ amount: data.amount,
484
+ currency: data.currency
485
+ };
486
+ }
487
+
488
+ return this.createSubscriptionCheckoutSession(payload);
489
+ }
490
+
432
491
  /**
433
492
  * Schedule a subscription invoice (convenience wrapper)
434
493
  */
package/index.mjs CHANGED
@@ -8,10 +8,10 @@
8
8
 
9
9
  import crypto from 'node:crypto';
10
10
 
11
- const DEFAULT_BASE = (process.env.PAYMENT_API_BASE_URL
12
- || process.env.PAYMENT_SERVER_URL
13
- || process.env.NEXT_PUBLIC_PAYMENT_API_BASE_URL
14
- || 'http://localhost:3002').replace(/\/+$/, '');
11
+ const DEFAULT_BASE = (process.env.KUVARPAY_API_BASE_URL
12
+ || process.env.PAYMENT_API_BASE_URL
13
+ || 'https://payment.kuvarpay.com'
14
+ ).replace(/\/$/, '');
15
15
 
16
16
  export class KuvarPayServer {
17
17
  /**
@@ -187,6 +187,38 @@ export class KuvarPayServer {
187
187
  return this._post('/api/v1/transactions/create', payload);
188
188
  }
189
189
 
190
+ async createDirectPayment(data) {
191
+ const sessionData = {
192
+ amount: data.amount,
193
+ currency: data.currency,
194
+ description: data.description,
195
+ customerEmail: data.customerEmail,
196
+ customerName: data.customerName,
197
+ redirectUrl: data.redirectUrl,
198
+ callbackUrl: data.callbackUrl,
199
+ expiresIn: data.expiresIn,
200
+ metadata: data.metadata,
201
+ subaccount: data.subaccount,
202
+ split_code: data.split_code || data.splitCode
203
+ };
204
+
205
+ const session = await this.createCheckoutSession(sessionData);
206
+
207
+ const transactionData = {
208
+ checkoutSessionId: session.sessionId,
209
+ fromCurrency: data.fromCurrency,
210
+ 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
+ description: data.description,
216
+ metadata: data.metadata,
217
+ };
218
+
219
+ return this.createTransaction(transactionData);
220
+ }
221
+
190
222
  async sendInvoiceEmail(sessionId) {
191
223
  return this._post(`/api/v1/invoices/${encodeURIComponent(sessionId)}/send-email`, {});
192
224
  }
@@ -296,6 +328,21 @@ export class KuvarPayServer {
296
328
  return this.createMeteredInvoice(subscriptionId, invoiceData);
297
329
  }
298
330
 
331
+ async createDirectSubscription(data) {
332
+ const payload = Object.assign({
333
+ billingMode: data.billingMode || 'FIXED',
334
+ }, data);
335
+
336
+ if (data.amount && data.currency && !data.expectedUsage) {
337
+ payload.expectedUsage = {
338
+ amount: data.amount,
339
+ currency: data.currency
340
+ };
341
+ }
342
+
343
+ return this.createSubscriptionCheckoutSession(payload);
344
+ }
345
+
299
346
  async scheduleSubscriptionInvoice(subscriptionId, invoiceData) {
300
347
  if (!invoiceData?.dueDate) throw new Error('dueDate is required to schedule an invoice');
301
348
  const payload = Object.assign({}, invoiceData, { chargeSchedule: 'SCHEDULED' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuvarpay/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Official KuvarPay Server SDK for Node.js",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",