@beep-it/sdk-core 0.1.1 → 0.1.2-beta.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/README.md +228 -210
- package/dist/index.d.ts +111 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +348 -10
- package/dist/index.mjs +347 -10
- package/dist/modules/payments.d.ts +197 -11
- package/dist/modules/payments.d.ts.map +1 -1
- package/dist/modules/widget.d.ts +31 -0
- package/dist/modules/widget.d.ts.map +1 -0
- package/dist/types/payment.d.ts +211 -0
- package/dist/types/payment.d.ts.map +1 -1
- package/dist/types/public.d.ts +34 -0
- package/dist/types/public.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -200,22 +200,116 @@ var PaymentsModule = class {
|
|
|
200
200
|
this.client = client;
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
203
|
+
* Initiate a payout from your treasury wallet to an external address.
|
|
204
|
+
* Requires a secret API key (server-side only).
|
|
205
|
+
*
|
|
206
|
+
* Notes:
|
|
207
|
+
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
208
|
+
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
209
|
+
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
210
|
+
*
|
|
211
|
+
* Example:
|
|
212
|
+
* const res = await beep.payments.createPayout({
|
|
213
|
+
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
214
|
+
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
215
|
+
* chain: 'SOLANA',
|
|
216
|
+
* token: 'USDC',
|
|
217
|
+
* });
|
|
218
|
+
*/
|
|
219
|
+
async createPayout(params) {
|
|
220
|
+
const { data } = await this.client.post("/v1/payouts", params);
|
|
221
|
+
return data;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Waits for a payment to complete by polling the 402 endpoint using a reference key.
|
|
225
|
+
* The request is considered complete when the response no longer includes `referenceKey`.
|
|
226
|
+
*/
|
|
227
|
+
async waitForPaymentCompletion(options) {
|
|
228
|
+
const baseIntervalMs = options.intervalMs ?? 15e3;
|
|
229
|
+
let currentIntervalMs = baseIntervalMs;
|
|
230
|
+
const timeoutMs = options.timeoutMs ?? 5 * 6e4;
|
|
231
|
+
const deadline = Date.now() + timeoutMs;
|
|
232
|
+
let last = null;
|
|
233
|
+
while (true) {
|
|
234
|
+
if (options.signal?.aborted) {
|
|
235
|
+
return { paid: false, last };
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
try {
|
|
239
|
+
const resp = await this.client.post(
|
|
240
|
+
`/v1/payment/request-payment`,
|
|
241
|
+
{
|
|
242
|
+
assets: options.assets,
|
|
243
|
+
paymentReference: options.paymentReference,
|
|
244
|
+
paymentLabel: options.paymentLabel,
|
|
245
|
+
generateQrCode: false
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
last = resp.data.data;
|
|
249
|
+
} catch (err) {
|
|
250
|
+
const ax = err;
|
|
251
|
+
const status = ax.response?.status;
|
|
252
|
+
if (status === 402) {
|
|
253
|
+
last = ax.response?.data?.data ?? null;
|
|
254
|
+
} else {
|
|
255
|
+
if (status && [400, 401, 403, 404, 422].includes(status)) {
|
|
256
|
+
options.onError?.(err);
|
|
257
|
+
return { paid: false, last };
|
|
258
|
+
}
|
|
259
|
+
options.onError?.(err);
|
|
260
|
+
currentIntervalMs = Math.min(Math.ceil(currentIntervalMs * 1.5), 6e4);
|
|
261
|
+
last = last ?? null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
options.onUpdate?.(last);
|
|
265
|
+
if (last?.status === "expired" /* EXPIRED */ || last?.status === "failed" /* FAILED */) {
|
|
266
|
+
return { paid: false, last };
|
|
267
|
+
}
|
|
268
|
+
const paid = !last?.referenceKey;
|
|
269
|
+
if (paid) return { paid: true, last };
|
|
270
|
+
currentIntervalMs = baseIntervalMs;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
options.onError?.(e);
|
|
273
|
+
currentIntervalMs = Math.min(Math.ceil(currentIntervalMs * 1.5), 6e4);
|
|
274
|
+
}
|
|
275
|
+
if (Date.now() >= deadline) return { paid: false, last };
|
|
276
|
+
await new Promise((r) => setTimeout(r, currentIntervalMs));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Creates a payment request for purchasing assets using a two‑phase 402 flow.
|
|
281
|
+
*
|
|
282
|
+
* Phase 1 – Request payment (no paymentReference):
|
|
283
|
+
* - Server responds with HTTP 402 Payment Required and a payload containing:
|
|
284
|
+
* referenceKey, paymentUrl (Solana Pay), optional qrCode, amount, expiresAt, status.
|
|
285
|
+
* - The SDK normalizes this by returning the payload (even when status code is 402).
|
|
286
|
+
* - The caller must instruct the user to pay via their wallet using paymentUrl/qrCode.
|
|
287
|
+
*
|
|
288
|
+
* Phase 2 – Check/complete payment (with paymentReference):
|
|
289
|
+
* - Call again with the same assets and paymentReference returned in Phase 1.
|
|
290
|
+
* - If payment is still pending, server may again provide the referenceKey (or return 402).
|
|
291
|
+
* - When payment is complete, server will return success (no referenceKey required). In this SDK
|
|
292
|
+
* we consider the payment complete when the response does NOT include referenceKey.
|
|
204
293
|
*
|
|
205
294
|
* @param input - Parameters for the asset purchase request
|
|
206
|
-
* @returns
|
|
295
|
+
* @returns Payment request data or null when the input is invalid
|
|
207
296
|
*
|
|
208
297
|
* @example
|
|
209
|
-
*
|
|
210
|
-
* const
|
|
211
|
-
*
|
|
212
|
-
*
|
|
298
|
+
* // Phase 1: request
|
|
299
|
+
* const req = await beep.payments.requestAndPurchaseAsset({
|
|
300
|
+
* assets: [{ assetId: 'uuid', quantity: 1 }],
|
|
301
|
+
* generateQrCode: true,
|
|
302
|
+
* paymentLabel: 'My Store'
|
|
213
303
|
* });
|
|
304
|
+
* // Show req.paymentUrl/req.qrCode to user; req.referenceKey identifies this payment.
|
|
214
305
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* }
|
|
218
|
-
*
|
|
306
|
+
* // Phase 2: poll status using the same API with the referenceKey
|
|
307
|
+
* const check = await beep.payments.requestAndPurchaseAsset({
|
|
308
|
+
* assets: [{ assetId: 'uuid', quantity: 1 }],
|
|
309
|
+
* paymentReference: req?.referenceKey,
|
|
310
|
+
* generateQrCode: false
|
|
311
|
+
* });
|
|
312
|
+
* const isPaid = !check?.referenceKey; // When no referenceKey is returned, payment is complete
|
|
219
313
|
*/
|
|
220
314
|
async requestAndPurchaseAsset(input) {
|
|
221
315
|
if (!input.paymentReference && !input.assets?.length) {
|
|
@@ -281,6 +375,143 @@ var PaymentsModule = class {
|
|
|
281
375
|
throw new Error(`Failed to sign solana transaction: ${errorMessage}`);
|
|
282
376
|
}
|
|
283
377
|
}
|
|
378
|
+
// --- Streaming Payment Methods ---
|
|
379
|
+
// Note: These methods are ONLY available with BeepClient (secret API keys)
|
|
380
|
+
// They do NOT work with BeepPublicClient (publishable keys)
|
|
381
|
+
/**
|
|
382
|
+
* Issues a payment request for streaming charges with specified asset chunks
|
|
383
|
+
*
|
|
384
|
+
* Creates a new streaming payment session that can be started, paused, and stopped.
|
|
385
|
+
* This is the first step in setting up automatic billing for ongoing services or
|
|
386
|
+
* consumption-based pricing.
|
|
387
|
+
*
|
|
388
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
389
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient` or
|
|
390
|
+
* publishable keys for security reasons.
|
|
391
|
+
*
|
|
392
|
+
* @param payload - Payment request details including assets and merchant information
|
|
393
|
+
* @returns Promise resolving to payment session identifiers
|
|
394
|
+
* @throws {Error} When the request fails or authentication is invalid
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* // Only works with BeepClient (server-side)
|
|
399
|
+
* const beep = new BeepClient({ apiKey: 'your_secret_api_key' });
|
|
400
|
+
*
|
|
401
|
+
* const paymentSession = await beep.payments.issuePayment({
|
|
402
|
+
* apiKey: 'your_secret_api_key',
|
|
403
|
+
* assetChunks: [
|
|
404
|
+
* { assetId: 'video-streaming-uuid', quantity: 1 },
|
|
405
|
+
* { assetId: 'api-calls-uuid', quantity: 100 }
|
|
406
|
+
* ],
|
|
407
|
+
* payingMerchantId: 'merchant_who_will_be_charged',
|
|
408
|
+
* invoiceId: 'optional_existing_invoice_uuid'
|
|
409
|
+
* });
|
|
410
|
+
*
|
|
411
|
+
* console.log('Payment session created:', paymentSession.referenceKey);
|
|
412
|
+
* console.log('Invoice ID for management:', paymentSession.invoiceId);
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
async issuePayment(payload) {
|
|
416
|
+
const response = await this.client.post(
|
|
417
|
+
"/v1/invoices/issue-payment",
|
|
418
|
+
payload
|
|
419
|
+
);
|
|
420
|
+
return response.data;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Starts an active streaming session and begins charging for asset usage
|
|
424
|
+
*
|
|
425
|
+
* Activates a previously issued payment request and begins billing the specified
|
|
426
|
+
* merchant according to the streaming payment configuration. Once started, charges
|
|
427
|
+
* will accumulate based on actual usage.
|
|
428
|
+
*
|
|
429
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
430
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
431
|
+
*
|
|
432
|
+
* @param payload - Streaming session start details
|
|
433
|
+
* @returns Promise resolving to confirmation of the started session
|
|
434
|
+
* @throws {Error} When the invoice is invalid or already active
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* // Start billing for the streaming session
|
|
439
|
+
* const result = await beep.payments.startStreaming({
|
|
440
|
+
* apiKey: 'your_secret_api_key',
|
|
441
|
+
* invoiceId: 'invoice_uuid_from_issuePayment'
|
|
442
|
+
* });
|
|
443
|
+
*
|
|
444
|
+
* console.log('Streaming started for invoice:', result.invoiceId);
|
|
445
|
+
* // Charges will now accumulate based on usage
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
async startStreaming(payload) {
|
|
449
|
+
const response = await this.client.post("/v1/invoices/start", payload);
|
|
450
|
+
return response.data;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Temporarily pauses an active streaming session without terminating it
|
|
454
|
+
*
|
|
455
|
+
* Halts billing for a streaming session while keeping the session alive for later resumption.
|
|
456
|
+
* This is useful for temporary service interruptions or when you want to control billing
|
|
457
|
+
* periods precisely.
|
|
458
|
+
*
|
|
459
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
460
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
461
|
+
*
|
|
462
|
+
* @param payload - Streaming session pause details
|
|
463
|
+
* @returns Promise resolving to pause operation result
|
|
464
|
+
* @throws {Error} When the invoice is not in a valid state for pausing
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* // Temporarily pause billing (can be resumed later)
|
|
469
|
+
* const result = await beep.payments.pauseStreaming({
|
|
470
|
+
* apiKey: 'your_secret_api_key',
|
|
471
|
+
* invoiceId: 'active_streaming_invoice_uuid'
|
|
472
|
+
* });
|
|
473
|
+
*
|
|
474
|
+
* if (result.success) {
|
|
475
|
+
* console.log('Streaming paused - no new charges will accumulate');
|
|
476
|
+
* // Use startStreaming() again to resume
|
|
477
|
+
* }
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
async pauseStreaming(payload) {
|
|
481
|
+
const response = await this.client.post("/v1/invoices/pause", payload);
|
|
482
|
+
return response.data;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Permanently stops a streaming session and finalizes all charges
|
|
486
|
+
*
|
|
487
|
+
* Terminates a streaming session completely, finalizing all accumulated charges.
|
|
488
|
+
* This action cannot be undone - the session cannot be restarted after stopping.
|
|
489
|
+
* Use this when you're completely finished with a service or want to close out billing.
|
|
490
|
+
*
|
|
491
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
492
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
493
|
+
*
|
|
494
|
+
* @param payload - Streaming session stop details
|
|
495
|
+
* @returns Promise resolving to final session details and reference keys
|
|
496
|
+
* @throws {Error} When the invoice cannot be stopped or doesn't exist
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```typescript
|
|
500
|
+
* // Permanently stop and finalize the streaming session
|
|
501
|
+
* const result = await beep.payments.stopStreaming({
|
|
502
|
+
* apiKey: 'your_secret_api_key',
|
|
503
|
+
* invoiceId: 'active_streaming_invoice_uuid'
|
|
504
|
+
* });
|
|
505
|
+
*
|
|
506
|
+
* console.log('Session permanently stopped:', result.invoiceId);
|
|
507
|
+
* console.log('All reference keys for records:', result.referenceKeys);
|
|
508
|
+
* // Session cannot be restarted after this point
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
async stopStreaming(payload) {
|
|
512
|
+
const response = await this.client.post("/v1/invoices/stop", payload);
|
|
513
|
+
return response.data;
|
|
514
|
+
}
|
|
284
515
|
};
|
|
285
516
|
|
|
286
517
|
// src/modules/products.ts
|
|
@@ -418,6 +649,72 @@ var ProductsModule = class {
|
|
|
418
649
|
}
|
|
419
650
|
};
|
|
420
651
|
|
|
652
|
+
// src/modules/widget.ts
|
|
653
|
+
var WidgetModule = class {
|
|
654
|
+
constructor(client, publishableKey) {
|
|
655
|
+
this.client = client;
|
|
656
|
+
this.publishableKey = publishableKey;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Creates a payment session (public, CORS-open) for Checkout Widget
|
|
660
|
+
*/
|
|
661
|
+
async createPaymentSession(input) {
|
|
662
|
+
const body = {
|
|
663
|
+
publishableKey: this.publishableKey,
|
|
664
|
+
assets: input.assets,
|
|
665
|
+
paymentLabel: input.paymentLabel,
|
|
666
|
+
generateQrCode: input.generateQrCode ?? true
|
|
667
|
+
};
|
|
668
|
+
const res = await this.client.post(
|
|
669
|
+
"/v1/widget/payment-session",
|
|
670
|
+
body
|
|
671
|
+
);
|
|
672
|
+
return res.data;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Retrieves payment status for a reference key
|
|
676
|
+
*/
|
|
677
|
+
async getPaymentStatus(referenceKey) {
|
|
678
|
+
const res = await this.client.get(
|
|
679
|
+
`/v1/widget/payment-status/${encodeURIComponent(referenceKey)}`
|
|
680
|
+
);
|
|
681
|
+
return res.data;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Waits for payment completion by polling the public status endpoint until paid or timeout.
|
|
685
|
+
* Designed for browser/public usage (no secret keys).
|
|
686
|
+
*/
|
|
687
|
+
async waitForPaid(options) {
|
|
688
|
+
const baseIntervalMs = options.intervalMs ?? 15e3;
|
|
689
|
+
let currentIntervalMs = baseIntervalMs;
|
|
690
|
+
const timeoutMs = options.timeoutMs ?? 5 * 6e4;
|
|
691
|
+
const deadline = Date.now() + timeoutMs;
|
|
692
|
+
let last;
|
|
693
|
+
while (true) {
|
|
694
|
+
if (options.signal?.aborted) return { paid: false, last };
|
|
695
|
+
try {
|
|
696
|
+
const res = await this.client.get(
|
|
697
|
+
`/v1/widget/payment-status/${encodeURIComponent(options.referenceKey)}`
|
|
698
|
+
);
|
|
699
|
+
last = res.data;
|
|
700
|
+
options.onUpdate?.(last);
|
|
701
|
+
if (last?.paid) return { paid: true, last };
|
|
702
|
+
currentIntervalMs = baseIntervalMs;
|
|
703
|
+
} catch (err) {
|
|
704
|
+
options.onError?.(err);
|
|
705
|
+
const ax = err;
|
|
706
|
+
const status = ax.response?.status;
|
|
707
|
+
if (status && [400, 401, 403, 404, 422].includes(status)) {
|
|
708
|
+
return { paid: false, last };
|
|
709
|
+
}
|
|
710
|
+
currentIntervalMs = Math.min(Math.ceil(currentIntervalMs * 1.5), 6e4);
|
|
711
|
+
}
|
|
712
|
+
if (Date.now() >= deadline) return { paid: false, last };
|
|
713
|
+
await new Promise((r) => setTimeout(r, currentIntervalMs));
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
|
|
421
718
|
// src/index.ts
|
|
422
719
|
var BeepClient = class {
|
|
423
720
|
/**
|
|
@@ -442,6 +739,24 @@ var BeepClient = class {
|
|
|
442
739
|
this.invoices = new InvoicesModule(this.client);
|
|
443
740
|
this.payments = new PaymentsModule(this.client);
|
|
444
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* Initiate a payout from your treasury wallet to an external address.
|
|
744
|
+
* Requires a secret API key (server-side only).
|
|
745
|
+
*
|
|
746
|
+
* Notes:
|
|
747
|
+
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
748
|
+
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
749
|
+
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
750
|
+
*
|
|
751
|
+
* Example:
|
|
752
|
+
* const res = await beep.payments.createPayout({
|
|
753
|
+
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
754
|
+
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
755
|
+
* chain: 'SOLANA',
|
|
756
|
+
* token: 'USDC',
|
|
757
|
+
* });
|
|
758
|
+
*/
|
|
759
|
+
// Deprecated: use beep.payments.createPayout()
|
|
445
760
|
/**
|
|
446
761
|
* Checks the health status of the BEEP API server
|
|
447
762
|
*
|
|
@@ -466,8 +781,30 @@ var BeepClient = class {
|
|
|
466
781
|
}
|
|
467
782
|
}
|
|
468
783
|
};
|
|
784
|
+
var BeepPublicClient = class {
|
|
785
|
+
/**
|
|
786
|
+
* Creates a new BEEP public client instance for browser use
|
|
787
|
+
*
|
|
788
|
+
* @param options - Configuration options including publishable key
|
|
789
|
+
* @throws {Error} When publishable key is missing or invalid
|
|
790
|
+
*/
|
|
791
|
+
constructor(options) {
|
|
792
|
+
if (!options.publishableKey) {
|
|
793
|
+
throw new Error("publishableKey is required to initialize BeepPublicClient");
|
|
794
|
+
}
|
|
795
|
+
this.client = axios.create({
|
|
796
|
+
baseURL: options.serverUrl || "https://api.justbeep.it",
|
|
797
|
+
headers: {
|
|
798
|
+
"Content-Type": "application/json",
|
|
799
|
+
"X-Beep-Client": "beep-sdk"
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
this.widget = new WidgetModule(this.client, options.publishableKey);
|
|
803
|
+
}
|
|
804
|
+
};
|
|
469
805
|
export {
|
|
470
806
|
BeepClient,
|
|
807
|
+
BeepPublicClient,
|
|
471
808
|
SupportedToken,
|
|
472
809
|
TokenUtils
|
|
473
810
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { IssuePaymentPayload, IssuePaymentResponse, PauseStreamingPayload, PauseStreamingResponse, StartStreamingPayload, StartStreamingResponse, StopStreamingPayload, StopStreamingResponse } from '../types';
|
|
3
|
+
import { BeepPurchaseAsset, PaymentRequestData, RequestAndPurchaseAssetRequestParams, SignSolanaTransactionData, SignSolanaTransactionParams } from '../types/payment';
|
|
3
4
|
/**
|
|
4
5
|
* Module for handling payment operations including asset purchases and Solana transactions
|
|
5
6
|
* Provides methods for creating payment requests and signing blockchain transactions
|
|
@@ -8,22 +9,88 @@ export declare class PaymentsModule {
|
|
|
8
9
|
private client;
|
|
9
10
|
constructor(client: AxiosInstance);
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Initiate a payout from your treasury wallet to an external address.
|
|
13
|
+
* Requires a secret API key (server-side only).
|
|
14
|
+
*
|
|
15
|
+
* Notes:
|
|
16
|
+
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
17
|
+
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
18
|
+
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* const res = await beep.payments.createPayout({
|
|
22
|
+
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
23
|
+
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
24
|
+
* chain: 'SOLANA',
|
|
25
|
+
* token: 'USDC',
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
createPayout(params: {
|
|
29
|
+
amount: string;
|
|
30
|
+
destinationWalletAddress: string;
|
|
31
|
+
chain: string;
|
|
32
|
+
token: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
payoutId: string;
|
|
35
|
+
status: 'accepted' | 'rejected';
|
|
36
|
+
message: string;
|
|
37
|
+
withdrawRequestId?: number;
|
|
38
|
+
requestedAmount?: string;
|
|
39
|
+
reservedAmount?: string;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
error?: string;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Waits for a payment to complete by polling the 402 endpoint using a reference key.
|
|
45
|
+
* The request is considered complete when the response no longer includes `referenceKey`.
|
|
46
|
+
*/
|
|
47
|
+
waitForPaymentCompletion(options: {
|
|
48
|
+
assets: BeepPurchaseAsset[];
|
|
49
|
+
paymentReference: string;
|
|
50
|
+
paymentLabel?: string;
|
|
51
|
+
intervalMs?: number;
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
onUpdate?: (response: PaymentRequestData | null) => void;
|
|
55
|
+
onError?: (error: unknown) => void;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
paid: boolean;
|
|
58
|
+
last?: PaymentRequestData | null;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a payment request for purchasing assets using a two‑phase 402 flow.
|
|
62
|
+
*
|
|
63
|
+
* Phase 1 – Request payment (no paymentReference):
|
|
64
|
+
* - Server responds with HTTP 402 Payment Required and a payload containing:
|
|
65
|
+
* referenceKey, paymentUrl (Solana Pay), optional qrCode, amount, expiresAt, status.
|
|
66
|
+
* - The SDK normalizes this by returning the payload (even when status code is 402).
|
|
67
|
+
* - The caller must instruct the user to pay via their wallet using paymentUrl/qrCode.
|
|
68
|
+
*
|
|
69
|
+
* Phase 2 – Check/complete payment (with paymentReference):
|
|
70
|
+
* - Call again with the same assets and paymentReference returned in Phase 1.
|
|
71
|
+
* - If payment is still pending, server may again provide the referenceKey (or return 402).
|
|
72
|
+
* - When payment is complete, server will return success (no referenceKey required). In this SDK
|
|
73
|
+
* we consider the payment complete when the response does NOT include referenceKey.
|
|
12
74
|
*
|
|
13
75
|
* @param input - Parameters for the asset purchase request
|
|
14
|
-
* @returns
|
|
76
|
+
* @returns Payment request data or null when the input is invalid
|
|
15
77
|
*
|
|
16
78
|
* @example
|
|
17
|
-
*
|
|
18
|
-
* const
|
|
19
|
-
*
|
|
20
|
-
*
|
|
79
|
+
* // Phase 1: request
|
|
80
|
+
* const req = await beep.payments.requestAndPurchaseAsset({
|
|
81
|
+
* assets: [{ assetId: 'uuid', quantity: 1 }],
|
|
82
|
+
* generateQrCode: true,
|
|
83
|
+
* paymentLabel: 'My Store'
|
|
21
84
|
* });
|
|
85
|
+
* // Show req.paymentUrl/req.qrCode to user; req.referenceKey identifies this payment.
|
|
22
86
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
87
|
+
* // Phase 2: poll status using the same API with the referenceKey
|
|
88
|
+
* const check = await beep.payments.requestAndPurchaseAsset({
|
|
89
|
+
* assets: [{ assetId: 'uuid', quantity: 1 }],
|
|
90
|
+
* paymentReference: req?.referenceKey,
|
|
91
|
+
* generateQrCode: false
|
|
92
|
+
* });
|
|
93
|
+
* const isPaid = !check?.referenceKey; // When no referenceKey is returned, payment is complete
|
|
27
94
|
*/
|
|
28
95
|
requestAndPurchaseAsset(input: RequestAndPurchaseAssetRequestParams): Promise<PaymentRequestData | null>;
|
|
29
96
|
/**
|
|
@@ -53,5 +120,124 @@ export declare class PaymentsModule {
|
|
|
53
120
|
* ```
|
|
54
121
|
*/
|
|
55
122
|
signSolanaTransaction(input: SignSolanaTransactionParams): Promise<SignSolanaTransactionData | null>;
|
|
123
|
+
/**
|
|
124
|
+
* Issues a payment request for streaming charges with specified asset chunks
|
|
125
|
+
*
|
|
126
|
+
* Creates a new streaming payment session that can be started, paused, and stopped.
|
|
127
|
+
* This is the first step in setting up automatic billing for ongoing services or
|
|
128
|
+
* consumption-based pricing.
|
|
129
|
+
*
|
|
130
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
131
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient` or
|
|
132
|
+
* publishable keys for security reasons.
|
|
133
|
+
*
|
|
134
|
+
* @param payload - Payment request details including assets and merchant information
|
|
135
|
+
* @returns Promise resolving to payment session identifiers
|
|
136
|
+
* @throws {Error} When the request fails or authentication is invalid
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Only works with BeepClient (server-side)
|
|
141
|
+
* const beep = new BeepClient({ apiKey: 'your_secret_api_key' });
|
|
142
|
+
*
|
|
143
|
+
* const paymentSession = await beep.payments.issuePayment({
|
|
144
|
+
* apiKey: 'your_secret_api_key',
|
|
145
|
+
* assetChunks: [
|
|
146
|
+
* { assetId: 'video-streaming-uuid', quantity: 1 },
|
|
147
|
+
* { assetId: 'api-calls-uuid', quantity: 100 }
|
|
148
|
+
* ],
|
|
149
|
+
* payingMerchantId: 'merchant_who_will_be_charged',
|
|
150
|
+
* invoiceId: 'optional_existing_invoice_uuid'
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* console.log('Payment session created:', paymentSession.referenceKey);
|
|
154
|
+
* console.log('Invoice ID for management:', paymentSession.invoiceId);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
issuePayment(payload: IssuePaymentPayload): Promise<IssuePaymentResponse>;
|
|
158
|
+
/**
|
|
159
|
+
* Starts an active streaming session and begins charging for asset usage
|
|
160
|
+
*
|
|
161
|
+
* Activates a previously issued payment request and begins billing the specified
|
|
162
|
+
* merchant according to the streaming payment configuration. Once started, charges
|
|
163
|
+
* will accumulate based on actual usage.
|
|
164
|
+
*
|
|
165
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
166
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
167
|
+
*
|
|
168
|
+
* @param payload - Streaming session start details
|
|
169
|
+
* @returns Promise resolving to confirmation of the started session
|
|
170
|
+
* @throws {Error} When the invoice is invalid or already active
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Start billing for the streaming session
|
|
175
|
+
* const result = await beep.payments.startStreaming({
|
|
176
|
+
* apiKey: 'your_secret_api_key',
|
|
177
|
+
* invoiceId: 'invoice_uuid_from_issuePayment'
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* console.log('Streaming started for invoice:', result.invoiceId);
|
|
181
|
+
* // Charges will now accumulate based on usage
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
startStreaming(payload: StartStreamingPayload): Promise<StartStreamingResponse>;
|
|
185
|
+
/**
|
|
186
|
+
* Temporarily pauses an active streaming session without terminating it
|
|
187
|
+
*
|
|
188
|
+
* Halts billing for a streaming session while keeping the session alive for later resumption.
|
|
189
|
+
* This is useful for temporary service interruptions or when you want to control billing
|
|
190
|
+
* periods precisely.
|
|
191
|
+
*
|
|
192
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
193
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
194
|
+
*
|
|
195
|
+
* @param payload - Streaming session pause details
|
|
196
|
+
* @returns Promise resolving to pause operation result
|
|
197
|
+
* @throws {Error} When the invoice is not in a valid state for pausing
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* // Temporarily pause billing (can be resumed later)
|
|
202
|
+
* const result = await beep.payments.pauseStreaming({
|
|
203
|
+
* apiKey: 'your_secret_api_key',
|
|
204
|
+
* invoiceId: 'active_streaming_invoice_uuid'
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* if (result.success) {
|
|
208
|
+
* console.log('Streaming paused - no new charges will accumulate');
|
|
209
|
+
* // Use startStreaming() again to resume
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
pauseStreaming(payload: PauseStreamingPayload): Promise<PauseStreamingResponse>;
|
|
214
|
+
/**
|
|
215
|
+
* Permanently stops a streaming session and finalizes all charges
|
|
216
|
+
*
|
|
217
|
+
* Terminates a streaming session completely, finalizing all accumulated charges.
|
|
218
|
+
* This action cannot be undone - the session cannot be restarted after stopping.
|
|
219
|
+
* Use this when you're completely finished with a service or want to close out billing.
|
|
220
|
+
*
|
|
221
|
+
* **Important Security Note**: This method requires a secret API key and is only
|
|
222
|
+
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
223
|
+
*
|
|
224
|
+
* @param payload - Streaming session stop details
|
|
225
|
+
* @returns Promise resolving to final session details and reference keys
|
|
226
|
+
* @throws {Error} When the invoice cannot be stopped or doesn't exist
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* // Permanently stop and finalize the streaming session
|
|
231
|
+
* const result = await beep.payments.stopStreaming({
|
|
232
|
+
* apiKey: 'your_secret_api_key',
|
|
233
|
+
* invoiceId: 'active_streaming_invoice_uuid'
|
|
234
|
+
* });
|
|
235
|
+
*
|
|
236
|
+
* console.log('Session permanently stopped:', result.invoiceId);
|
|
237
|
+
* console.log('All reference keys for records:', result.referenceKeys);
|
|
238
|
+
* // Session cannot be restarted after this point
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
stopStreaming(payload: StopStreamingPayload): Promise<StopStreamingResponse>;
|
|
56
242
|
}
|
|
57
243
|
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/modules/payments.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/modules/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,aAAa,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EAGtB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,oCAAoC,EACpC,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,kBAAkB,CAAC;AAE1B;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa;IAIjC;;;;;;;;;;;;;;;;OAgBG;IACU,YAAY,CAAC,MAAM,EAAE;QAChC,MAAM,EAAE,MAAM,CAAC;QACf,wBAAwB,EAAE,MAAM,CAAC;QACjC,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC;QACV,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC;QAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IAKF;;;OAGG;IACU,wBAAwB,CAAC,OAAO,EAAE;QAC7C,MAAM,EAAE,iBAAiB,EAAE,CAAC;QAC5B,gBAAgB,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,KAAK,IAAI,CAAC;QACzD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;KACpC,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAA;KAAE,CAAC;IA+DhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,uBAAuB,CAC3B,KAAK,EAAE,oCAAoC,GAC1C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAuBrC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,qBAAqB,CAChC,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAgC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAQ/E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAKrF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAKrF;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAInF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { PublicPaymentSessionRequest, PublicPaymentSessionResponse, PublicPaymentStatusResponse } from '../types/public';
|
|
3
|
+
export declare class WidgetModule {
|
|
4
|
+
private client;
|
|
5
|
+
private publishableKey;
|
|
6
|
+
constructor(client: AxiosInstance, publishableKey: string);
|
|
7
|
+
/**
|
|
8
|
+
* Creates a payment session (public, CORS-open) for Checkout Widget
|
|
9
|
+
*/
|
|
10
|
+
createPaymentSession(input: Omit<PublicPaymentSessionRequest, 'publishableKey'>): Promise<PublicPaymentSessionResponse>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves payment status for a reference key
|
|
13
|
+
*/
|
|
14
|
+
getPaymentStatus(referenceKey: string): Promise<PublicPaymentStatusResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Waits for payment completion by polling the public status endpoint until paid or timeout.
|
|
17
|
+
* Designed for browser/public usage (no secret keys).
|
|
18
|
+
*/
|
|
19
|
+
waitForPaid(options: {
|
|
20
|
+
referenceKey: string;
|
|
21
|
+
intervalMs?: number;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
onUpdate?: (status: PublicPaymentStatusResponse) => void;
|
|
25
|
+
onError?: (error: unknown) => void;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
paid: boolean;
|
|
28
|
+
last?: PublicPaymentStatusResponse;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=widget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/modules/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,aAAa,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,cAAc,CAAS;gBAEnB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM;IAKzD;;OAEG;IACG,oBAAoB,CACxB,KAAK,EAAE,IAAI,CAAC,2BAA2B,EAAE,gBAAgB,CAAC,GACzD,OAAO,CAAC,4BAA4B,CAAC;IAcxC;;OAEG;IACG,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAOlF;;;OAGG;IACG,WAAW,CAAC,OAAO,EAAE;QACzB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,2BAA2B,KAAK,IAAI,CAAC;QACzD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;KACpC,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,2BAA2B,CAAA;KAAE,CAAC;CAkCnE"}
|