@solvapay/server 1.2.0 → 1.2.1-preview-e89fa52f99b6d0c7bf9834fcf2d1403141051fa0
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 +13 -8
- package/dist/edge.d.ts +210 -44
- package/dist/edge.js +153 -43
- package/dist/fetch/index.cjs +153 -43
- package/dist/fetch/index.d.cts +130 -0
- package/dist/fetch/index.d.ts +130 -0
- package/dist/fetch/index.js +153 -43
- package/dist/index.cjs +153 -43
- package/dist/index.d.cts +213 -45
- package/dist/index.d.ts +213 -45
- package/dist/index.js +153 -43
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -99,7 +99,9 @@ function createSolvaPayClient(opts) {
|
|
|
99
99
|
if (!res.ok) {
|
|
100
100
|
const error = await res.text();
|
|
101
101
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
102
|
-
throw new import_core.SolvaPayError(`Check limits failed (${res.status}): ${error}`, {
|
|
102
|
+
throw new import_core.SolvaPayError(`Check limits failed (${res.status}): ${error}`, {
|
|
103
|
+
status: res.status
|
|
104
|
+
});
|
|
103
105
|
}
|
|
104
106
|
const result = await res.json();
|
|
105
107
|
return result;
|
|
@@ -115,8 +117,28 @@ function createSolvaPayClient(opts) {
|
|
|
115
117
|
if (!res.ok) {
|
|
116
118
|
const error = await res.text();
|
|
117
119
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
118
|
-
throw new import_core.SolvaPayError(`Track usage failed (${res.status}): ${error}`, {
|
|
120
|
+
throw new import_core.SolvaPayError(`Track usage failed (${res.status}): ${error}`, {
|
|
121
|
+
status: res.status
|
|
122
|
+
});
|
|
119
123
|
}
|
|
124
|
+
return await res.json();
|
|
125
|
+
},
|
|
126
|
+
// POST: /v1/sdk/usages/bulk
|
|
127
|
+
async trackUsageBulk(params) {
|
|
128
|
+
const url = `${base}/v1/sdk/usages/bulk`;
|
|
129
|
+
const res = await fetch(url, {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers,
|
|
132
|
+
body: JSON.stringify(params)
|
|
133
|
+
});
|
|
134
|
+
if (!res.ok) {
|
|
135
|
+
const error = await res.text();
|
|
136
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
137
|
+
throw new import_core.SolvaPayError(`Track usage bulk failed (${res.status}): ${error}`, {
|
|
138
|
+
status: res.status
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return await res.json();
|
|
120
142
|
},
|
|
121
143
|
// POST: /v1/sdk/customers
|
|
122
144
|
async createCustomer(params) {
|
|
@@ -129,7 +151,9 @@ function createSolvaPayClient(opts) {
|
|
|
129
151
|
if (!res.ok) {
|
|
130
152
|
const error = await res.text();
|
|
131
153
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
132
|
-
throw new import_core.SolvaPayError(`Create customer failed (${res.status}): ${error}`, {
|
|
154
|
+
throw new import_core.SolvaPayError(`Create customer failed (${res.status}): ${error}`, {
|
|
155
|
+
status: res.status
|
|
156
|
+
});
|
|
133
157
|
}
|
|
134
158
|
const result = await res.json();
|
|
135
159
|
return {
|
|
@@ -147,7 +171,9 @@ function createSolvaPayClient(opts) {
|
|
|
147
171
|
if (!res.ok) {
|
|
148
172
|
const error = await res.text();
|
|
149
173
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
150
|
-
throw new import_core.SolvaPayError(`Update customer failed (${res.status}): ${error}`, {
|
|
174
|
+
throw new import_core.SolvaPayError(`Update customer failed (${res.status}): ${error}`, {
|
|
175
|
+
status: res.status
|
|
176
|
+
});
|
|
151
177
|
}
|
|
152
178
|
const result = await res.json();
|
|
153
179
|
return {
|
|
@@ -177,7 +203,9 @@ function createSolvaPayClient(opts) {
|
|
|
177
203
|
if (!res.ok) {
|
|
178
204
|
const error = await res.text();
|
|
179
205
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
180
|
-
throw new import_core.SolvaPayError(`Get customer failed (${res.status}): ${error}`, {
|
|
206
|
+
throw new import_core.SolvaPayError(`Get customer failed (${res.status}): ${error}`, {
|
|
207
|
+
status: res.status
|
|
208
|
+
});
|
|
181
209
|
}
|
|
182
210
|
const result = await res.json();
|
|
183
211
|
let customer = result;
|
|
@@ -198,6 +226,27 @@ function createSolvaPayClient(opts) {
|
|
|
198
226
|
purchases: customer.purchases || []
|
|
199
227
|
};
|
|
200
228
|
},
|
|
229
|
+
// POST: /v1/sdk/customers/{reference}/credits
|
|
230
|
+
async assignCredits(params) {
|
|
231
|
+
const { customerRef, idempotencyKey, ...body } = params;
|
|
232
|
+
const url = `${base}/v1/sdk/customers/${encodeURIComponent(customerRef)}/credits`;
|
|
233
|
+
const res = await fetch(url, {
|
|
234
|
+
method: "POST",
|
|
235
|
+
headers: {
|
|
236
|
+
...headers,
|
|
237
|
+
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
|
|
238
|
+
},
|
|
239
|
+
body: JSON.stringify(body)
|
|
240
|
+
});
|
|
241
|
+
if (!res.ok) {
|
|
242
|
+
const error = await res.text();
|
|
243
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
244
|
+
throw new import_core.SolvaPayError(`Assign credits failed (${res.status}): ${error}`, {
|
|
245
|
+
status: res.status
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return await res.json();
|
|
249
|
+
},
|
|
201
250
|
// GET: /v1/sdk/merchant
|
|
202
251
|
async getMerchant() {
|
|
203
252
|
const url = `${base}/v1/sdk/merchant`;
|
|
@@ -208,7 +257,9 @@ function createSolvaPayClient(opts) {
|
|
|
208
257
|
if (!res.ok) {
|
|
209
258
|
const error = await res.text();
|
|
210
259
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
211
|
-
throw new import_core.SolvaPayError(`Get merchant failed (${res.status}): ${error}`, {
|
|
260
|
+
throw new import_core.SolvaPayError(`Get merchant failed (${res.status}): ${error}`, {
|
|
261
|
+
status: res.status
|
|
262
|
+
});
|
|
212
263
|
}
|
|
213
264
|
return res.json();
|
|
214
265
|
},
|
|
@@ -222,7 +273,9 @@ function createSolvaPayClient(opts) {
|
|
|
222
273
|
if (!res.ok) {
|
|
223
274
|
const error = await res.text();
|
|
224
275
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
225
|
-
throw new import_core.SolvaPayError(`Get platform config failed (${res.status}): ${error}`, {
|
|
276
|
+
throw new import_core.SolvaPayError(`Get platform config failed (${res.status}): ${error}`, {
|
|
277
|
+
status: res.status
|
|
278
|
+
});
|
|
226
279
|
}
|
|
227
280
|
return res.json();
|
|
228
281
|
},
|
|
@@ -236,7 +289,9 @@ function createSolvaPayClient(opts) {
|
|
|
236
289
|
if (!res.ok) {
|
|
237
290
|
const error = await res.text();
|
|
238
291
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
239
|
-
throw new import_core.SolvaPayError(`Get product failed (${res.status}): ${error}`, {
|
|
292
|
+
throw new import_core.SolvaPayError(`Get product failed (${res.status}): ${error}`, {
|
|
293
|
+
status: res.status
|
|
294
|
+
});
|
|
240
295
|
}
|
|
241
296
|
const result = await res.json();
|
|
242
297
|
const data = result.data || {};
|
|
@@ -253,7 +308,9 @@ function createSolvaPayClient(opts) {
|
|
|
253
308
|
if (!res.ok) {
|
|
254
309
|
const error = await res.text();
|
|
255
310
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
256
|
-
throw new import_core.SolvaPayError(`List products failed (${res.status}): ${error}`, {
|
|
311
|
+
throw new import_core.SolvaPayError(`List products failed (${res.status}): ${error}`, {
|
|
312
|
+
status: res.status
|
|
313
|
+
});
|
|
257
314
|
}
|
|
258
315
|
const result = await res.json();
|
|
259
316
|
const products = Array.isArray(result) ? result : result.products || [];
|
|
@@ -273,7 +330,9 @@ function createSolvaPayClient(opts) {
|
|
|
273
330
|
if (!res.ok) {
|
|
274
331
|
const error = await res.text();
|
|
275
332
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
276
|
-
throw new import_core.SolvaPayError(`Create product failed (${res.status}): ${error}`, {
|
|
333
|
+
throw new import_core.SolvaPayError(`Create product failed (${res.status}): ${error}`, {
|
|
334
|
+
status: res.status
|
|
335
|
+
});
|
|
277
336
|
}
|
|
278
337
|
const result = await res.json();
|
|
279
338
|
return result;
|
|
@@ -289,7 +348,9 @@ function createSolvaPayClient(opts) {
|
|
|
289
348
|
if (!res.ok) {
|
|
290
349
|
const error = await res.text();
|
|
291
350
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
292
|
-
throw new import_core.SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`, {
|
|
351
|
+
throw new import_core.SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`, {
|
|
352
|
+
status: res.status
|
|
353
|
+
});
|
|
293
354
|
}
|
|
294
355
|
return await res.json();
|
|
295
356
|
},
|
|
@@ -304,7 +365,9 @@ function createSolvaPayClient(opts) {
|
|
|
304
365
|
if (!res.ok) {
|
|
305
366
|
const error = await res.text();
|
|
306
367
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
307
|
-
throw new import_core.SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`, {
|
|
368
|
+
throw new import_core.SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`, {
|
|
369
|
+
status: res.status
|
|
370
|
+
});
|
|
308
371
|
}
|
|
309
372
|
return await res.json();
|
|
310
373
|
},
|
|
@@ -318,7 +381,9 @@ function createSolvaPayClient(opts) {
|
|
|
318
381
|
if (!res.ok && res.status !== 404) {
|
|
319
382
|
const error = await res.text();
|
|
320
383
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
321
|
-
throw new import_core.SolvaPayError(`Delete product failed (${res.status}): ${error}`, {
|
|
384
|
+
throw new import_core.SolvaPayError(`Delete product failed (${res.status}): ${error}`, {
|
|
385
|
+
status: res.status
|
|
386
|
+
});
|
|
322
387
|
}
|
|
323
388
|
},
|
|
324
389
|
// POST: /v1/sdk/products/{productRef}/clone
|
|
@@ -332,7 +397,9 @@ function createSolvaPayClient(opts) {
|
|
|
332
397
|
if (!res.ok) {
|
|
333
398
|
const error = await res.text();
|
|
334
399
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
335
|
-
throw new import_core.SolvaPayError(`Clone product failed (${res.status}): ${error}`, {
|
|
400
|
+
throw new import_core.SolvaPayError(`Clone product failed (${res.status}): ${error}`, {
|
|
401
|
+
status: res.status
|
|
402
|
+
});
|
|
336
403
|
}
|
|
337
404
|
return await res.json();
|
|
338
405
|
},
|
|
@@ -346,7 +413,9 @@ function createSolvaPayClient(opts) {
|
|
|
346
413
|
if (!res.ok) {
|
|
347
414
|
const error = await res.text();
|
|
348
415
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
349
|
-
throw new import_core.SolvaPayError(`List plans failed (${res.status}): ${error}`, {
|
|
416
|
+
throw new import_core.SolvaPayError(`List plans failed (${res.status}): ${error}`, {
|
|
417
|
+
status: res.status
|
|
418
|
+
});
|
|
350
419
|
}
|
|
351
420
|
const result = await res.json();
|
|
352
421
|
const plans = Array.isArray(result) ? result : result.plans || [];
|
|
@@ -373,7 +442,9 @@ function createSolvaPayClient(opts) {
|
|
|
373
442
|
if (!res.ok) {
|
|
374
443
|
const error = await res.text();
|
|
375
444
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
376
|
-
throw new import_core.SolvaPayError(`Create plan failed (${res.status}): ${error}`, {
|
|
445
|
+
throw new import_core.SolvaPayError(`Create plan failed (${res.status}): ${error}`, {
|
|
446
|
+
status: res.status
|
|
447
|
+
});
|
|
377
448
|
}
|
|
378
449
|
const result = await res.json();
|
|
379
450
|
return result;
|
|
@@ -389,7 +460,9 @@ function createSolvaPayClient(opts) {
|
|
|
389
460
|
if (!res.ok) {
|
|
390
461
|
const error = await res.text();
|
|
391
462
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
392
|
-
throw new import_core.SolvaPayError(`Update plan failed (${res.status}): ${error}`, {
|
|
463
|
+
throw new import_core.SolvaPayError(`Update plan failed (${res.status}): ${error}`, {
|
|
464
|
+
status: res.status
|
|
465
|
+
});
|
|
393
466
|
}
|
|
394
467
|
return await res.json();
|
|
395
468
|
},
|
|
@@ -403,7 +476,9 @@ function createSolvaPayClient(opts) {
|
|
|
403
476
|
if (!res.ok && res.status !== 404) {
|
|
404
477
|
const error = await res.text();
|
|
405
478
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
406
|
-
throw new import_core.SolvaPayError(`Delete plan failed (${res.status}): ${error}`, {
|
|
479
|
+
throw new import_core.SolvaPayError(`Delete plan failed (${res.status}): ${error}`, {
|
|
480
|
+
status: res.status
|
|
481
|
+
});
|
|
407
482
|
}
|
|
408
483
|
},
|
|
409
484
|
// POST: /payment-intents
|
|
@@ -419,13 +494,16 @@ function createSolvaPayClient(opts) {
|
|
|
419
494
|
body: JSON.stringify({
|
|
420
495
|
productRef: params.productRef,
|
|
421
496
|
planRef: params.planRef,
|
|
422
|
-
customerRef: params.customerRef
|
|
497
|
+
customerRef: params.customerRef,
|
|
498
|
+
...params.currency && { currency: params.currency }
|
|
423
499
|
})
|
|
424
500
|
});
|
|
425
501
|
if (!res.ok) {
|
|
426
502
|
const error = await res.text();
|
|
427
503
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
428
|
-
throw new import_core.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`, {
|
|
504
|
+
throw new import_core.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`, {
|
|
505
|
+
status: res.status
|
|
506
|
+
});
|
|
429
507
|
}
|
|
430
508
|
return await res.json();
|
|
431
509
|
},
|
|
@@ -450,7 +528,9 @@ function createSolvaPayClient(opts) {
|
|
|
450
528
|
if (!res.ok) {
|
|
451
529
|
const error = await res.text();
|
|
452
530
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
453
|
-
throw new import_core.SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`, {
|
|
531
|
+
throw new import_core.SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`, {
|
|
532
|
+
status: res.status
|
|
533
|
+
});
|
|
454
534
|
}
|
|
455
535
|
return await res.json();
|
|
456
536
|
},
|
|
@@ -472,7 +552,9 @@ function createSolvaPayClient(opts) {
|
|
|
472
552
|
if (!res.ok) {
|
|
473
553
|
const error = await res.text();
|
|
474
554
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
475
|
-
throw new import_core.SolvaPayError(`Process payment failed (${res.status}): ${error}`, {
|
|
555
|
+
throw new import_core.SolvaPayError(`Process payment failed (${res.status}): ${error}`, {
|
|
556
|
+
status: res.status
|
|
557
|
+
});
|
|
476
558
|
}
|
|
477
559
|
const result = await res.json();
|
|
478
560
|
return result;
|
|
@@ -500,7 +582,9 @@ function createSolvaPayClient(opts) {
|
|
|
500
582
|
{ status: 400 }
|
|
501
583
|
);
|
|
502
584
|
}
|
|
503
|
-
throw new import_core.SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`, {
|
|
585
|
+
throw new import_core.SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`, {
|
|
586
|
+
status: res.status
|
|
587
|
+
});
|
|
504
588
|
}
|
|
505
589
|
const responseText = await res.text();
|
|
506
590
|
let responseData;
|
|
@@ -544,12 +628,11 @@ function createSolvaPayClient(opts) {
|
|
|
544
628
|
throw new import_core.SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
|
|
545
629
|
}
|
|
546
630
|
if (res.status === 400) {
|
|
547
|
-
throw new import_core.SolvaPayError(
|
|
548
|
-
`Purchase cannot be reactivated: ${error}`,
|
|
549
|
-
{ status: 400 }
|
|
550
|
-
);
|
|
631
|
+
throw new import_core.SolvaPayError(`Purchase cannot be reactivated: ${error}`, { status: 400 });
|
|
551
632
|
}
|
|
552
|
-
throw new import_core.SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`, {
|
|
633
|
+
throw new import_core.SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`, {
|
|
634
|
+
status: res.status
|
|
635
|
+
});
|
|
553
636
|
}
|
|
554
637
|
const responseText = await res.text();
|
|
555
638
|
let responseData;
|
|
@@ -590,7 +673,9 @@ function createSolvaPayClient(opts) {
|
|
|
590
673
|
if (!res.ok) {
|
|
591
674
|
const error = await res.text();
|
|
592
675
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
593
|
-
throw new import_core.SolvaPayError(`Get user info failed (${res.status}): ${error}`, {
|
|
676
|
+
throw new import_core.SolvaPayError(`Get user info failed (${res.status}): ${error}`, {
|
|
677
|
+
status: res.status
|
|
678
|
+
});
|
|
594
679
|
}
|
|
595
680
|
return await res.json();
|
|
596
681
|
},
|
|
@@ -604,7 +689,9 @@ function createSolvaPayClient(opts) {
|
|
|
604
689
|
if (!res.ok) {
|
|
605
690
|
const error = await res.text();
|
|
606
691
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
607
|
-
throw new import_core.SolvaPayError(`Get customer balance failed (${res.status}): ${error}`, {
|
|
692
|
+
throw new import_core.SolvaPayError(`Get customer balance failed (${res.status}): ${error}`, {
|
|
693
|
+
status: res.status
|
|
694
|
+
});
|
|
608
695
|
}
|
|
609
696
|
return await res.json();
|
|
610
697
|
},
|
|
@@ -619,7 +706,9 @@ function createSolvaPayClient(opts) {
|
|
|
619
706
|
if (!res.ok) {
|
|
620
707
|
const error = await res.text();
|
|
621
708
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
622
|
-
throw new import_core.SolvaPayError(`Create checkout session failed (${res.status}): ${error}`, {
|
|
709
|
+
throw new import_core.SolvaPayError(`Create checkout session failed (${res.status}): ${error}`, {
|
|
710
|
+
status: res.status
|
|
711
|
+
});
|
|
623
712
|
}
|
|
624
713
|
const result = await res.json();
|
|
625
714
|
return result;
|
|
@@ -635,7 +724,9 @@ function createSolvaPayClient(opts) {
|
|
|
635
724
|
if (!res.ok) {
|
|
636
725
|
const error = await res.text();
|
|
637
726
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
638
|
-
throw new import_core.SolvaPayError(`Create customer session failed (${res.status}): ${error}`, {
|
|
727
|
+
throw new import_core.SolvaPayError(`Create customer session failed (${res.status}): ${error}`, {
|
|
728
|
+
status: res.status
|
|
729
|
+
});
|
|
639
730
|
}
|
|
640
731
|
const result = await res.json();
|
|
641
732
|
return result;
|
|
@@ -651,7 +742,9 @@ function createSolvaPayClient(opts) {
|
|
|
651
742
|
if (!res.ok) {
|
|
652
743
|
const error = await res.text();
|
|
653
744
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
654
|
-
throw new import_core.SolvaPayError(`Activate plan failed (${res.status}): ${error}`, {
|
|
745
|
+
throw new import_core.SolvaPayError(`Activate plan failed (${res.status}): ${error}`, {
|
|
746
|
+
status: res.status
|
|
747
|
+
});
|
|
655
748
|
}
|
|
656
749
|
return await res.json();
|
|
657
750
|
},
|
|
@@ -662,7 +755,9 @@ function createSolvaPayClient(opts) {
|
|
|
662
755
|
if (!res.ok) {
|
|
663
756
|
const error = await res.text();
|
|
664
757
|
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
665
|
-
throw new import_core.SolvaPayError(`Get payment method failed (${res.status}): ${error}`, {
|
|
758
|
+
throw new import_core.SolvaPayError(`Get payment method failed (${res.status}): ${error}`, {
|
|
759
|
+
status: res.status
|
|
760
|
+
});
|
|
666
761
|
}
|
|
667
762
|
return await res.json();
|
|
668
763
|
}
|
|
@@ -1952,6 +2047,12 @@ function createSolvaPay(config) {
|
|
|
1952
2047
|
trackUsage(params) {
|
|
1953
2048
|
return apiClient.trackUsage(params);
|
|
1954
2049
|
},
|
|
2050
|
+
trackUsageBulk(params) {
|
|
2051
|
+
if (!apiClient.trackUsageBulk) {
|
|
2052
|
+
throw new import_core2.SolvaPayError("trackUsageBulk is not available on this API client");
|
|
2053
|
+
}
|
|
2054
|
+
return apiClient.trackUsageBulk(params);
|
|
2055
|
+
},
|
|
1955
2056
|
createCustomer(params) {
|
|
1956
2057
|
if (!apiClient.createCustomer) {
|
|
1957
2058
|
throw new import_core2.SolvaPayError("createCustomer is not available on this API client");
|
|
@@ -1961,6 +2062,12 @@ function createSolvaPay(config) {
|
|
|
1961
2062
|
getCustomer(params) {
|
|
1962
2063
|
return apiClient.getCustomer(params);
|
|
1963
2064
|
},
|
|
2065
|
+
assignCredits(params) {
|
|
2066
|
+
if (!apiClient.assignCredits) {
|
|
2067
|
+
throw new import_core2.SolvaPayError("assignCredits is not available on this API client");
|
|
2068
|
+
}
|
|
2069
|
+
return apiClient.assignCredits(params);
|
|
2070
|
+
},
|
|
1964
2071
|
getCustomerBalance(params) {
|
|
1965
2072
|
if (!apiClient.getCustomerBalance) {
|
|
1966
2073
|
throw new import_core2.SolvaPayError("getCustomerBalance is not available on this API client");
|
|
@@ -2046,7 +2153,9 @@ function createSolvaPay(config) {
|
|
|
2046
2153
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2047
2154
|
async function(businessLogic) {
|
|
2048
2155
|
const getCustomerRef = (args) => {
|
|
2049
|
-
const configuredRef = options.getCustomerRef?.(
|
|
2156
|
+
const configuredRef = options.getCustomerRef?.(
|
|
2157
|
+
args
|
|
2158
|
+
);
|
|
2050
2159
|
if (typeof configuredRef === "string") {
|
|
2051
2160
|
return configuredRef;
|
|
2052
2161
|
}
|
|
@@ -2065,9 +2174,7 @@ function createSolvaPay(config) {
|
|
|
2065
2174
|
);
|
|
2066
2175
|
if (decision.outcome === "gate") {
|
|
2067
2176
|
const errorMessage = decision.gate.kind === "activation_required" ? "Activation required" : "Payment required";
|
|
2068
|
-
const body = paywallErrorToClientPayload(
|
|
2069
|
-
new PaywallError(errorMessage, decision.gate)
|
|
2070
|
-
);
|
|
2177
|
+
const body = paywallErrorToClientPayload(new PaywallError(errorMessage, decision.gate));
|
|
2071
2178
|
const response = new Response(JSON.stringify(body), {
|
|
2072
2179
|
status: 402,
|
|
2073
2180
|
headers: { "content-type": "application/json" }
|
|
@@ -2166,6 +2273,7 @@ function handleRouteError(error, operationName, defaultMessage) {
|
|
|
2166
2273
|
}
|
|
2167
2274
|
|
|
2168
2275
|
// src/helpers/auth.ts
|
|
2276
|
+
var import_auth = require("@solvapay/auth");
|
|
2169
2277
|
function base64UrlDecode(input) {
|
|
2170
2278
|
const padded = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
2171
2279
|
const padding = padded.length % 4 === 0 ? "" : "=".repeat(4 - padded.length % 4);
|
|
@@ -2242,7 +2350,7 @@ async function getAuthenticatedUserCore(request, options = {}) {
|
|
|
2242
2350
|
try {
|
|
2243
2351
|
const includeEmail = options.includeEmail !== false;
|
|
2244
2352
|
const includeName = options.includeName !== false;
|
|
2245
|
-
const headerUserId = request.headers.get(
|
|
2353
|
+
const headerUserId = request.headers.get(import_auth.SOLVAPAY_USER_ID_HEADER);
|
|
2246
2354
|
if (headerUserId) {
|
|
2247
2355
|
let email = null;
|
|
2248
2356
|
let name = null;
|
|
@@ -2356,7 +2464,8 @@ async function createPaymentIntentCore(request, body, options = {}) {
|
|
|
2356
2464
|
const paymentIntent = await solvaPay.createPaymentIntent({
|
|
2357
2465
|
productRef: body.productRef,
|
|
2358
2466
|
planRef: body.planRef,
|
|
2359
|
-
customerRef
|
|
2467
|
+
customerRef,
|
|
2468
|
+
...body.currency && { currency: body.currency }
|
|
2360
2469
|
});
|
|
2361
2470
|
return {
|
|
2362
2471
|
processorPaymentId: paymentIntent.processorPaymentId,
|
|
@@ -3012,15 +3121,16 @@ async function trackUsageCore(request, body, options = {}) {
|
|
|
3012
3121
|
email: email || void 0,
|
|
3013
3122
|
name: name || void 0
|
|
3014
3123
|
});
|
|
3015
|
-
await solvaPay.trackUsage({
|
|
3124
|
+
const result = await solvaPay.trackUsage({
|
|
3016
3125
|
customerRef,
|
|
3017
3126
|
actionType: body.actionType,
|
|
3018
3127
|
units: body.units,
|
|
3019
3128
|
productRef: body.productRef,
|
|
3020
3129
|
description: body.description,
|
|
3021
|
-
metadata: body.metadata
|
|
3130
|
+
metadata: body.metadata,
|
|
3131
|
+
idempotencyKey: body.idempotencyKey
|
|
3022
3132
|
});
|
|
3023
|
-
return
|
|
3133
|
+
return result;
|
|
3024
3134
|
} catch (error) {
|
|
3025
3135
|
return handleRouteError(error, "Track usage", "Track usage failed");
|
|
3026
3136
|
}
|