@beep-it/sdk-core 0.1.2-beta.3 → 0.1.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 +238 -228
- package/dist/index.d.ts +6 -98
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -298
- package/dist/index.mjs +10 -298
- package/dist/modules/payments.d.ts +11 -196
- package/dist/modules/payments.d.ts.map +1 -1
- package/dist/modules/widget.d.ts +0 -15
- package/dist/modules/widget.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/payment.d.ts +0 -211
- package/dist/types/payment.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -200,116 +200,22 @@ var PaymentsModule = class {
|
|
|
200
200
|
this.client = client;
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
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.
|
|
203
|
+
* Creates a payment request for purchasing assets
|
|
293
204
|
*
|
|
294
205
|
* @param input - Parameters for the asset purchase request
|
|
295
|
-
* @returns
|
|
206
|
+
* @returns Promise that resolves to payment request data, or null if validation fails
|
|
296
207
|
*
|
|
297
208
|
* @example
|
|
298
|
-
*
|
|
299
|
-
* const
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* paymentLabel: 'My Store'
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const payment = await beep.payments.requestAndPurchaseAsset({
|
|
211
|
+
* paymentReference: 'premium_subscription_123',
|
|
212
|
+
* assetIds: ['asset_1', 'asset_2']
|
|
303
213
|
* });
|
|
304
|
-
* // Show req.paymentUrl/req.qrCode to user; req.referenceKey identifies this payment.
|
|
305
214
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* generateQrCode: false
|
|
311
|
-
* });
|
|
312
|
-
* const isPaid = !check?.referenceKey; // When no referenceKey is returned, payment is complete
|
|
215
|
+
* if (payment) {
|
|
216
|
+
* console.log('Payment URL:', payment.paymentUrl);
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
313
219
|
*/
|
|
314
220
|
async requestAndPurchaseAsset(input) {
|
|
315
221
|
if (!input.paymentReference && !input.assets?.length) {
|
|
@@ -375,143 +281,6 @@ var PaymentsModule = class {
|
|
|
375
281
|
throw new Error(`Failed to sign solana transaction: ${errorMessage}`);
|
|
376
282
|
}
|
|
377
283
|
}
|
|
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
|
-
}
|
|
515
284
|
};
|
|
516
285
|
|
|
517
286
|
// src/modules/products.ts
|
|
@@ -680,39 +449,6 @@ var WidgetModule = class {
|
|
|
680
449
|
);
|
|
681
450
|
return res.data;
|
|
682
451
|
}
|
|
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
452
|
};
|
|
717
453
|
|
|
718
454
|
// src/index.ts
|
|
@@ -739,24 +475,6 @@ var BeepClient = class {
|
|
|
739
475
|
this.invoices = new InvoicesModule(this.client);
|
|
740
476
|
this.payments = new PaymentsModule(this.client);
|
|
741
477
|
}
|
|
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()
|
|
760
478
|
/**
|
|
761
479
|
* Checks the health status of the BEEP API server
|
|
762
480
|
*
|
|
@@ -782,12 +500,6 @@ var BeepClient = class {
|
|
|
782
500
|
}
|
|
783
501
|
};
|
|
784
502
|
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
503
|
constructor(options) {
|
|
792
504
|
if (!options.publishableKey) {
|
|
793
505
|
throw new Error("publishableKey is required to initialize BeepPublicClient");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { PaymentRequestData, RequestAndPurchaseAssetRequestParams, SignSolanaTransactionData, SignSolanaTransactionParams } from '../types/payment';
|
|
3
3
|
/**
|
|
4
4
|
* Module for handling payment operations including asset purchases and Solana transactions
|
|
5
5
|
* Provides methods for creating payment requests and signing blockchain transactions
|
|
@@ -8,88 +8,22 @@ export declare class PaymentsModule {
|
|
|
8
8
|
private client;
|
|
9
9
|
constructor(client: AxiosInstance);
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Requires a secret API key (server-side only).
|
|
13
|
-
*
|
|
14
|
-
* Notes:
|
|
15
|
-
* - Do not pass walletId. The server derives the wallet based on your API key's merchant and requested chain.
|
|
16
|
-
* - amount must be in smallest units for the token (e.g., 6‑decimals USDC amount as an integer string).
|
|
17
|
-
* - This endpoint responds immediately with acceptance/rejection. Actual transfer executes asynchronously after funds are reserved.
|
|
18
|
-
*
|
|
19
|
-
* Example:
|
|
20
|
-
* const res = await beep.payments.createPayout({
|
|
21
|
-
* amount: '1000000', // 1.0 USDC with 6 decimals
|
|
22
|
-
* destinationWalletAddress: 'DEST_ADDRESS',
|
|
23
|
-
* chain: 'SOLANA',
|
|
24
|
-
* token: 'USDC',
|
|
25
|
-
* });
|
|
26
|
-
*/
|
|
27
|
-
createPayout(params: {
|
|
28
|
-
amount: string;
|
|
29
|
-
destinationWalletAddress: string;
|
|
30
|
-
chain: string;
|
|
31
|
-
token: string;
|
|
32
|
-
}): Promise<{
|
|
33
|
-
payoutId: string;
|
|
34
|
-
status: 'accepted' | 'rejected';
|
|
35
|
-
message: string;
|
|
36
|
-
withdrawRequestId?: number;
|
|
37
|
-
requestedAmount?: string;
|
|
38
|
-
reservedAmount?: string;
|
|
39
|
-
createdAt: string;
|
|
40
|
-
error?: string;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* Waits for a payment to complete by polling the 402 endpoint using a reference key.
|
|
44
|
-
* The request is considered complete when the response no longer includes `referenceKey`.
|
|
45
|
-
*/
|
|
46
|
-
waitForPaymentCompletion(options: {
|
|
47
|
-
assets: BeepPurchaseAsset[];
|
|
48
|
-
paymentReference: string;
|
|
49
|
-
paymentLabel?: string;
|
|
50
|
-
intervalMs?: number;
|
|
51
|
-
timeoutMs?: number;
|
|
52
|
-
signal?: AbortSignal;
|
|
53
|
-
onUpdate?: (response: PaymentRequestData | null) => void;
|
|
54
|
-
onError?: (error: unknown) => void;
|
|
55
|
-
}): Promise<{
|
|
56
|
-
paid: boolean;
|
|
57
|
-
last?: PaymentRequestData | null;
|
|
58
|
-
}>;
|
|
59
|
-
/**
|
|
60
|
-
* Creates a payment request for purchasing assets using a two‑phase 402 flow.
|
|
61
|
-
*
|
|
62
|
-
* Phase 1 – Request payment (no paymentReference):
|
|
63
|
-
* - Server responds with HTTP 402 Payment Required and a payload containing:
|
|
64
|
-
* referenceKey, paymentUrl (Solana Pay), optional qrCode, amount, expiresAt, status.
|
|
65
|
-
* - The SDK normalizes this by returning the payload (even when status code is 402).
|
|
66
|
-
* - The caller must instruct the user to pay via their wallet using paymentUrl/qrCode.
|
|
67
|
-
*
|
|
68
|
-
* Phase 2 – Check/complete payment (with paymentReference):
|
|
69
|
-
* - Call again with the same assets and paymentReference returned in Phase 1.
|
|
70
|
-
* - If payment is still pending, server may again provide the referenceKey (or return 402).
|
|
71
|
-
* - When payment is complete, server will return success (no referenceKey required). In this SDK
|
|
72
|
-
* we consider the payment complete when the response does NOT include referenceKey.
|
|
11
|
+
* Creates a payment request for purchasing assets
|
|
73
12
|
*
|
|
74
13
|
* @param input - Parameters for the asset purchase request
|
|
75
|
-
* @returns
|
|
14
|
+
* @returns Promise that resolves to payment request data, or null if validation fails
|
|
76
15
|
*
|
|
77
16
|
* @example
|
|
78
|
-
*
|
|
79
|
-
* const
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* paymentLabel: 'My Store'
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const payment = await beep.payments.requestAndPurchaseAsset({
|
|
19
|
+
* paymentReference: 'premium_subscription_123',
|
|
20
|
+
* assetIds: ['asset_1', 'asset_2']
|
|
83
21
|
* });
|
|
84
|
-
* // Show req.paymentUrl/req.qrCode to user; req.referenceKey identifies this payment.
|
|
85
22
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* generateQrCode: false
|
|
91
|
-
* });
|
|
92
|
-
* const isPaid = !check?.referenceKey; // When no referenceKey is returned, payment is complete
|
|
23
|
+
* if (payment) {
|
|
24
|
+
* console.log('Payment URL:', payment.paymentUrl);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
93
27
|
*/
|
|
94
28
|
requestAndPurchaseAsset(input: RequestAndPurchaseAssetRequestParams): Promise<PaymentRequestData | null>;
|
|
95
29
|
/**
|
|
@@ -119,124 +53,5 @@ export declare class PaymentsModule {
|
|
|
119
53
|
* ```
|
|
120
54
|
*/
|
|
121
55
|
signSolanaTransaction(input: SignSolanaTransactionParams): Promise<SignSolanaTransactionData | null>;
|
|
122
|
-
/**
|
|
123
|
-
* Issues a payment request for streaming charges with specified asset chunks
|
|
124
|
-
*
|
|
125
|
-
* Creates a new streaming payment session that can be started, paused, and stopped.
|
|
126
|
-
* This is the first step in setting up automatic billing for ongoing services or
|
|
127
|
-
* consumption-based pricing.
|
|
128
|
-
*
|
|
129
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
130
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient` or
|
|
131
|
-
* publishable keys for security reasons.
|
|
132
|
-
*
|
|
133
|
-
* @param payload - Payment request details including assets and merchant information
|
|
134
|
-
* @returns Promise resolving to payment session identifiers
|
|
135
|
-
* @throws {Error} When the request fails or authentication is invalid
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* // Only works with BeepClient (server-side)
|
|
140
|
-
* const beep = new BeepClient({ apiKey: 'your_secret_api_key' });
|
|
141
|
-
*
|
|
142
|
-
* const paymentSession = await beep.payments.issuePayment({
|
|
143
|
-
* apiKey: 'your_secret_api_key',
|
|
144
|
-
* assetChunks: [
|
|
145
|
-
* { assetId: 'video-streaming-uuid', quantity: 1 },
|
|
146
|
-
* { assetId: 'api-calls-uuid', quantity: 100 }
|
|
147
|
-
* ],
|
|
148
|
-
* payingMerchantId: 'merchant_who_will_be_charged',
|
|
149
|
-
* invoiceId: 'optional_existing_invoice_uuid'
|
|
150
|
-
* });
|
|
151
|
-
*
|
|
152
|
-
* console.log('Payment session created:', paymentSession.referenceKey);
|
|
153
|
-
* console.log('Invoice ID for management:', paymentSession.invoiceId);
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
issuePayment(payload: IssuePaymentPayload): Promise<IssuePaymentResponse>;
|
|
157
|
-
/**
|
|
158
|
-
* Starts an active streaming session and begins charging for asset usage
|
|
159
|
-
*
|
|
160
|
-
* Activates a previously issued payment request and begins billing the specified
|
|
161
|
-
* merchant according to the streaming payment configuration. Once started, charges
|
|
162
|
-
* will accumulate based on actual usage.
|
|
163
|
-
*
|
|
164
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
165
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
166
|
-
*
|
|
167
|
-
* @param payload - Streaming session start details
|
|
168
|
-
* @returns Promise resolving to confirmation of the started session
|
|
169
|
-
* @throws {Error} When the invoice is invalid or already active
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
* // Start billing for the streaming session
|
|
174
|
-
* const result = await beep.payments.startStreaming({
|
|
175
|
-
* apiKey: 'your_secret_api_key',
|
|
176
|
-
* invoiceId: 'invoice_uuid_from_issuePayment'
|
|
177
|
-
* });
|
|
178
|
-
*
|
|
179
|
-
* console.log('Streaming started for invoice:', result.invoiceId);
|
|
180
|
-
* // Charges will now accumulate based on usage
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
startStreaming(payload: StartStreamingPayload): Promise<StartStreamingResponse>;
|
|
184
|
-
/**
|
|
185
|
-
* Temporarily pauses an active streaming session without terminating it
|
|
186
|
-
*
|
|
187
|
-
* Halts billing for a streaming session while keeping the session alive for later resumption.
|
|
188
|
-
* This is useful for temporary service interruptions or when you want to control billing
|
|
189
|
-
* periods precisely.
|
|
190
|
-
*
|
|
191
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
192
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
193
|
-
*
|
|
194
|
-
* @param payload - Streaming session pause details
|
|
195
|
-
* @returns Promise resolving to pause operation result
|
|
196
|
-
* @throws {Error} When the invoice is not in a valid state for pausing
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```typescript
|
|
200
|
-
* // Temporarily pause billing (can be resumed later)
|
|
201
|
-
* const result = await beep.payments.pauseStreaming({
|
|
202
|
-
* apiKey: 'your_secret_api_key',
|
|
203
|
-
* invoiceId: 'active_streaming_invoice_uuid'
|
|
204
|
-
* });
|
|
205
|
-
*
|
|
206
|
-
* if (result.success) {
|
|
207
|
-
* console.log('Streaming paused - no new charges will accumulate');
|
|
208
|
-
* // Use startStreaming() again to resume
|
|
209
|
-
* }
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
pauseStreaming(payload: PauseStreamingPayload): Promise<PauseStreamingResponse>;
|
|
213
|
-
/**
|
|
214
|
-
* Permanently stops a streaming session and finalizes all charges
|
|
215
|
-
*
|
|
216
|
-
* Terminates a streaming session completely, finalizing all accumulated charges.
|
|
217
|
-
* This action cannot be undone - the session cannot be restarted after stopping.
|
|
218
|
-
* Use this when you're completely finished with a service or want to close out billing.
|
|
219
|
-
*
|
|
220
|
-
* **Important Security Note**: This method requires a secret API key and is only
|
|
221
|
-
* available when using `BeepClient`. It will NOT work with `BeepPublicClient`.
|
|
222
|
-
*
|
|
223
|
-
* @param payload - Streaming session stop details
|
|
224
|
-
* @returns Promise resolving to final session details and reference keys
|
|
225
|
-
* @throws {Error} When the invoice cannot be stopped or doesn't exist
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* ```typescript
|
|
229
|
-
* // Permanently stop and finalize the streaming session
|
|
230
|
-
* const result = await beep.payments.stopStreaming({
|
|
231
|
-
* apiKey: 'your_secret_api_key',
|
|
232
|
-
* invoiceId: 'active_streaming_invoice_uuid'
|
|
233
|
-
* });
|
|
234
|
-
*
|
|
235
|
-
* console.log('Session permanently stopped:', result.invoiceId);
|
|
236
|
-
* console.log('All reference keys for records:', result.referenceKeys);
|
|
237
|
-
* // Session cannot be restarted after this point
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
stopStreaming(payload: StopStreamingPayload): Promise<StopStreamingResponse>;
|
|
241
56
|
}
|
|
242
57
|
//# 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,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EACL,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;;;;;;;;;;;;;;;;;OAiBG;IACG,uBAAuB,CAC3B,KAAK,EAAE,oCAAoC,GAC1C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAqBrC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,qBAAqB,CAChC,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;CA2B7C"}
|
package/dist/modules/widget.d.ts
CHANGED
|
@@ -12,20 +12,5 @@ export declare class WidgetModule {
|
|
|
12
12
|
* Retrieves payment status for a reference key
|
|
13
13
|
*/
|
|
14
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
15
|
}
|
|
31
16
|
//# sourceMappingURL=widget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/modules/widget.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/modules/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,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;CAMnF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export * from './invoice';
|
|
2
|
-
export * from './payment';
|
|
3
2
|
export * from './product';
|
|
4
3
|
export * from './token';
|
|
5
|
-
|
|
4
|
+
export * from './payment';
|
|
6
5
|
/**
|
|
7
6
|
* Standard response wrapper for BEEP API endpoints
|
|
8
7
|
* All API responses follow this structure
|
|
@@ -29,4 +28,5 @@ export interface SignSolanaTransactionResponse extends BeepResponse {
|
|
|
29
28
|
/** Signed transaction data and associated invoice information */
|
|
30
29
|
data: SignSolanaTransactionData;
|
|
31
30
|
}
|
|
31
|
+
import { PaymentRequestData, SignSolanaTransactionData } from './payment';
|
|
32
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAE1B;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,+BAAgC,SAAQ,YAAY;IACnE,uEAAuE;IACvE,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,6BAA8B,SAAQ,YAAY;IACjE,iEAAiE;IACjE,IAAI,EAAE,yBAAyB,CAAC;CACjC;AAGD,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC"}
|