@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 CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  Alright, let's be real. You made something awesome. A game, an app, a digital masterpiece. And now you wanna get paid for it. As you should! But dealing with payments is a whole vibe killer. That's where we come in.
4
4
 
5
+ ## Table of Contents
6
+
7
+ - [What is this?](#-so-like-what-even-is-this)
8
+ - [πŸ–₯️ Server-Side SDK (BeepClient)](#server-side-sdk-beepclient)
9
+ - [Server-Side Setup](#server-side-setup)
10
+ - [Server-Side Making Money](#server-side-making-money)
11
+ - [Server-Side API Reference](#server-side-api-reference)
12
+ - [πŸ“± Frontend SDK (BeepPublicClient)](#frontend-sdk-beeppublicclient)
13
+ - [Frontend Setup](#frontend-setup)
14
+ - [Frontend Making Money](#frontend-making-money)
15
+ - [Frontend API Reference](#frontend-api-reference)
16
+ - [Token Utilities](#token-utilities)
17
+ - [Resources](#resources)
18
+
19
+ ## Which SDK Should I Use?
20
+
21
+ **πŸ–₯️ Backend/Server Code?** β†’ [Server-Side SDK (BeepClient)](#server-side-sdk-beepclient)
22
+
23
+ - Full API access with secret keys
24
+ - Server-side only (Node.js, Express, etc.)
25
+ - Complete payment processing capabilities
26
+ - **Streaming payments support** (issuePayment, startStreaming, etc.)
27
+
28
+ **πŸ“± Frontend/Browser Code?** β†’ [Frontend SDK (BeepPublicClient)](#frontend-sdk-beeppublicclient)
29
+
30
+ - Safe for client-side code
31
+ - Uses publishable keys (not secret)
32
+ - Perfect for React, Vue, or vanilla JS apps
33
+ - **Limited to widget endpoints only** (no streaming payments)
34
+
5
35
  ## πŸ€” So, like, what even _is_ this?
6
36
 
7
37
  Think of this SDK as your personal cheat code for money. It's a box of pre-written code that you can just drop into your project to handle all the boring payment stuff.
@@ -18,56 +48,39 @@ Basically, we're the ✨ unpaid intern ✨ who handles your finances so you can
18
48
 
19
49
  ---
20
50
 
21
- ## πŸš€ Let's Get This Bread: Your 3-Step Setup
51
+ ## Server-Side SDK (BeepClient)
22
52
 
23
- This is probably easier than picking an Instagram filter. No cap.
53
+ Perfect for Node.js, Express servers, Next.js API routes, and any backend code where you can safely store secret keys.
24
54
 
25
- ### Step 1: Download the Magic
55
+ ### Server-Side Setup
26
56
 
27
- In your project's command line thingy (the black box where you type stuff), paste this:
57
+ #### Step 1: Install the SDK
28
58
 
29
59
  ```bash
30
60
  npm install @beep-it/sdk-core
31
61
  ```
32
62
 
33
- This basically downloads our toolkit and puts it in your project's folder.
34
-
35
- ### Step 2: Get Your Secret Handshake (aka API Key)
36
-
37
- An API Key is just a super long, secret password. It's how our system knows it's you. You'll find yours on your BEEP dashboard.
63
+ #### Step 2: Get Your Secret API Key
38
64
 
39
- > **Seriously, don't share this.** It's like giving someone the keys to your house. Don't do it.
65
+ 1. Sign up for a BEEP account at [app.justbeep.it](https://app.justbeep.it)
66
+ 2. Go to your account settings and find your secret API key
67
+ 3. **Never expose this in client-side code!** Keep it on your server only.
40
68
 
41
- ### Step 3: Wake Up the BEEP-Bot
42
-
43
- Time to write, like, one line of code. This tells your project to start using the BEEP toolkit.
69
+ #### Step 3: Initialize BeepClient
44
70
 
45
71
  ```typescript
46
- // This line just says, "Hey, I wanna use that beep-sdk thing I just downloaded."
47
72
  import { BeepClient, SupportedToken } from '@beep-it/sdk-core';
48
73
 
49
- // This line creates your BEEP-Bot. It's now ready for your commands.
50
74
  const beep = new BeepClient({
51
- // Just paste that secret key you got from the dashboard right here.
52
- apiKey: 'your_super_secret_api_key_goes_here',
75
+ apiKey: 'your_secret_api_key_here', // Keep this secure!
53
76
  });
54
-
55
- console.log('Ok, your BEEP-Bot is ready. Slay.');
56
77
  ```
57
78
 
58
- Bet. You're all set up. Now for the fun part.
79
+ ### Server-Side Making Money
59
80
 
60
- ---
61
-
62
- ## βš™οΈ How to Actually Make Money with This
63
-
64
- Let's say you want to charge someone 5 USDT for a pack of 100 magic crystals in your game. Here's how to make that money move! πŸ’Έ
81
+ Let's say you want to charge someone 5 USDT for a pack of 100 magic crystals in your game. Here's the complete server-side flow:
65
82
 
66
- ### Step 1: Ask for the Money
67
-
68
- You just need to tell your BEEP-Bot how much you want to charge and in what currency. We'll generate a unique QR code and a payment link for your customer.
69
-
70
- #### The Whole Payment Flow Explained (as if you were 5... but like, a cool 5-year-old)
83
+ #### The Server-Side Payment Flow
71
84
 
72
85
  1. **You create an invoice** - This is literally just you telling our servers "hey, I want $X for Y reason"
73
86
  2. **We create an invoice** - Think of this as a digital receipt that says "pay this amount pls"
@@ -84,271 +97,252 @@ You just need to tell your BEEP-Bot how much you want to charge and in what curr
84
97
  Seriously, all _you_ need to worry about is step 1. We handle 2-7 because we're nice like that.
85
98
 
86
99
  ```typescript
87
- // Just describe what you're charging for.
100
+ // Server-side invoice creation
88
101
  const invoiceDetails = {
89
102
  description: 'A pack of 100 magic crystals',
90
- amount: '5.00', // Amount as string
91
- token: SupportedToken.USDT, // Much cleaner than a long address, right?
92
- payerType: 'customer_wallet' as const, // Who's paying
103
+ amount: '5.00',
104
+ token: SupportedToken.USDT,
105
+ payerType: 'customer_wallet' as const,
93
106
  };
94
107
 
95
108
  try {
96
- // Tell your BEEP-Bot to create an invoice for payment.
97
- // This creates a bill and gets everything ready behind the scenes.
98
109
  const invoice = await beep.invoices.createInvoice(invoiceDetails);
99
110
 
100
- // Now you have everything you need to get paid!
101
- console.log('QR Code:', invoice.qrCode);
102
- console.log('Payment Link:', invoice.paymentUrl);
103
- console.log('Reference Key:', invoice.referenceKey);
104
-
105
- // What you do next is up to you:
106
- // 1. Render the `qrCode` in your UI for the user to scan.
107
- // 2. Redirect the user to the `paymentUrl`.
108
- // BEEP will handle the rest on the backend once the user approves the transaction.
111
+ // Send this payment info to your frontend
112
+ res.json({
113
+ qrCode: invoice.qrCode,
114
+ paymentUrl: invoice.paymentUrl,
115
+ referenceKey: invoice.referenceKey,
116
+ invoiceId: invoice.id,
117
+ });
118
+
119
+ // Later, check if payment completed
120
+ const updatedInvoice = await beep.invoices.getInvoice(invoice.id!);
121
+ if (updatedInvoice.status === 'paid') {
122
+ // Unlock content for the user!
123
+ }
109
124
  } catch (error) {
110
- console.error('Oof. Something went wrong creating the invoice:', error.message);
125
+ console.error('Invoice creation failed:', error.message);
111
126
  }
112
127
  ```
113
128
 
114
- And that's literally it. Once the user pays, the money appears in your account. You just made money.
115
-
116
- ---
117
-
118
- ## πŸ€“ For the true DIYers (The API Deets)
119
-
120
- If you're the type of person who likes to take things apart just so you can put them back together, this is for you. Here are the technical specs. Everyone else, you can ignore this.
129
+ ### Server-Side API Reference
121
130
 
122
- ### `BeepClient`
123
-
124
- Initializes the client. Takes an `options` object.
131
+ #### Creating Invoices
125
132
 
126
133
  ```typescript
127
- new BeepClient(options: {
128
- apiKey: string; // Required. Your secret API key.
129
- serverUrl?: string; // Optional. For testing. Defaults to production.
130
- })
134
+ const invoice = await beep.invoices.createInvoice({
135
+ amount: '19.99',
136
+ token: SupportedToken.USDT,
137
+ description: 'VIP Battle Pass',
138
+ payerType: 'customer_wallet',
139
+ });
131
140
  ```
132
141
 
133
- **High-Level Methods:**
134
-
135
- #### Creating Invoices for Payment
142
+ #### Managing Products
136
143
 
137
144
  ```typescript
138
- // The money maker - create an invoice for payment!
139
- const invoice = await beep.invoices.createInvoice({
140
- amount: '19.99', // Amount as string
141
- token: SupportedToken.USDT, // Enum magic!
142
- description: 'VIP Battle Pass - Summer Season',
143
- payerType: 'customer_wallet', // Customer pays
145
+ // Create a product
146
+ const product = await beep.products.createProduct({
147
+ name: 'Magic Sword',
148
+ price: '9.99',
149
+ token: SupportedToken.USDT,
150
+ isSubscription: false,
144
151
  });
145
152
 
146
- // Now you have everything you need for the user to pay
147
- console.log('Payment URL:', invoice.paymentUrl);
148
- console.log('Reference Key:', invoice.referenceKey);
149
- console.log('Invoice ID:', invoice.id);
150
-
151
- // IMPORTANT PART: What to do with this info!
152
- // Option 1: Redirect your user to the payment page
153
- window.location.href = invoice.paymentUrl;
154
-
155
- // OR Option 2: Show a QR code on your page
156
- renderQRCode(invoice.qrCode); // Use your favorite QR library
157
-
158
- // OR Option 3: Just give them the link
159
- displayToUser(`Pay here: ${invoice.paymentUrl}`);
160
-
161
- // After payment (could be seconds or minutes later):
162
- // Check if they've paid yet
163
- const updatedInvoice = await beep.invoices.getInvoice(invoice.id);
164
-
165
- if (updatedInvoice.status === 'paid') {
166
- // Woohoo! Give them their digital goodies!
167
- unlockAwesomeContent();
168
- doHappyDance();
169
- } else if (updatedInvoice.status === 'pending') {
170
- // Still waiting for payment
171
- showSpinnyWaitingAnimation();
172
- } else if (updatedInvoice.status === 'expired') {
173
- // Oof, they took too long
174
- showSadTromboneSound();
175
- }
153
+ // List all products
154
+ const products = await beep.products.listProducts();
176
155
  ```
177
156
 
178
- #### Health Check
157
+ #### Payment Processing
179
158
 
180
159
  ```typescript
181
- // Make sure our servers aren't on fire
182
- const health = await beep.healthCheck();
183
- console.log('Server health:', health); // Should return health status
160
+ // Request asset purchase
161
+ const payment = await beep.payments.requestAndPurchaseAsset({
162
+ assets: [{ assetId: 'product-uuid', quantity: 1 }],
163
+ generateQrCode: true,
164
+ });
165
+
166
+ // Wait for payment completion
167
+ const { paid } = await beep.payments.waitForPaymentCompletion({
168
+ assets: [{ assetId: 'product-uuid', quantity: 1 }],
169
+ paymentReference: payment.referenceKey,
170
+ });
184
171
  ```
185
172
 
186
- **Low-Level Modules:**
173
+ #### Streaming Payments (BeepClient Only)
187
174
 
188
- For when you need more control.
175
+ **Important:** Streaming payment methods are only available with `BeepClient` using secret API keys. They do NOT work with `BeepPublicClient` or publishable keys.
189
176
 
190
- ### `SupportedToken`
177
+ ```typescript
178
+ // Issue a streaming payment session
179
+ const session = await beep.payments.issuePayment({
180
+ apiKey: 'your_secret_api_key',
181
+ assetChunks: [
182
+ { assetId: 'video-content-uuid', quantity: 1 },
183
+ { assetId: 'api-access-uuid', quantity: 100 }
184
+ ],
185
+ payingMerchantId: 'merchant_who_pays'
186
+ });
191
187
 
192
- Our shiny new enum for supported tokens! Way easier than remembering addresses.
188
+ // Start charging for usage
189
+ await beep.payments.startStreaming({
190
+ apiKey: 'your_secret_api_key',
191
+ invoiceId: session.invoiceId
192
+ });
193
193
 
194
- ```typescript
195
- // Import it like this
196
- import { SupportedToken } from '@beep-it/sdk-core';
194
+ // Pause billing temporarily
195
+ await beep.payments.pauseStreaming({
196
+ apiKey: 'your_secret_api_key',
197
+ invoiceId: session.invoiceId
198
+ });
197
199
 
198
- // Use it like this
199
- const token = SupportedToken.USDT; // Currently supported
200
- // SupportedToken.USDC coming soon!
200
+ // Stop and finalize charges
201
+ const result = await beep.payments.stopStreaming({
202
+ apiKey: 'your_secret_api_key',
203
+ invoiceId: session.invoiceId
204
+ });
201
205
  ```
202
206
 
203
- ### `beep.invoices`
207
+ ---
204
208
 
205
- Handle invoice operations - create, retrieve, and manage payment invoices.
209
+ ## Frontend SDK (BeepPublicClient)
206
210
 
207
- ```typescript
208
- // Create invoices for payment
209
- const invoice = await beep.invoices.createInvoice({
210
- description: 'Premium service',
211
- amount: '29.99',
212
- token: SupportedToken.USDT,
213
- payerType: 'customer_wallet',
214
- });
211
+ Perfect for React, Vue, vanilla JS, or any client-side code where you can't safely store secret keys.
215
212
 
216
- // Get all your invoices
217
- const invoices = await beep.invoices.listInvoices();
213
+ ### Frontend Setup
218
214
 
219
- // Look up a specific invoice
220
- const invoice = await beep.invoices.getInvoice('inv_123abc');
215
+ #### Step 1: Install the SDK
221
216
 
222
- // Delete an invoice
223
- await beep.invoices.deleteInvoice('inv_123abc');
217
+ ```bash
218
+ npm install @beep-it/sdk-core
224
219
  ```
225
220
 
226
- ### `beep.products`
221
+ #### Step 2: Get Your Publishable Key
227
222
 
228
- Manage your products - create reusable payment configurations with sweet token enum support! πŸŽ‰
223
+ 1. Sign up for a BEEP account at [app.justbeep.it](https://app.justbeep.it)
224
+ 2. Go to your account settings and find your publishable key (starts with `beep_pk_`)
225
+ 3. This is safe to expose in client-side code!
229
226
 
230
- #### Creating Products
227
+ #### Step 3: Initialize BeepPublicClient
231
228
 
232
229
  ```typescript
233
- // Creating a one-time purchase product
234
- const product = await beep.products.createProduct({
235
- name: 'Magic Sword of Destiny',
236
- description: 'Gives +10 attack and looks cool as heck',
237
- price: '9.99', // Just regular numbers as strings
238
- token: SupportedToken.USDT, // So much cleaner than a crazy address
239
- isSubscription: false, // One-time purchase
240
- });
230
+ import { BeepPublicClient, SupportedToken } from '@beep-it/sdk-core';
241
231
 
242
- console.log(`Created product with ID: ${product.id}`);
243
-
244
- // Creating a subscription product
245
- const subscriptionProduct = await beep.products.createProduct({
246
- name: 'Premium Battle Pass',
247
- description: 'Monthly subscription with exclusive skins and perks',
248
- price: '14.99', // Monthly price
249
- token: SupportedToken.USDT,
250
- isSubscription: true, // This makes it recurring - monthly subscription!
232
+ const publicBeep = new BeepPublicClient({
233
+ publishableKey: 'beep_pk_your_publishable_key_here', // Safe for browsers!
251
234
  });
235
+ ```
252
236
 
253
- console.log(`Created subscription with ID: ${subscriptionProduct.id}`);
237
+ ### Frontend Making Money
254
238
 
255
- // Creating a one-time purchase product (pay-per-use)
256
- const oneTimeProduct = await beep.products.createProduct({
257
- name: 'API Usage Credit',
258
- description: 'Credits for API calls',
259
- price: '0.001', // Price per credit
260
- token: SupportedToken.USDT,
261
- isSubscription: false, // One-time purchase
262
- });
239
+ Here's how to create a complete payment flow in your React app:
263
240
 
264
- console.log(`Created one-time product with ID: ${oneTimeProduct.id}`);
265
- ```
266
-
267
- #### Getting a Product
241
+ #### The Frontend Payment Flow
268
242
 
269
243
  ```typescript
270
- // Fetch a product by ID
271
- const product = await beep.products.getProduct('prod_123abc456def');
272
- console.log(`Found product: ${product.name} for ${product.price}`);
244
+ // Create a payment session with mixed assets
245
+ const handlePurchase = async () => {
246
+ try {
247
+ const session = await publicBeep.widget.createPaymentSession({
248
+ assets: [
249
+ // Use existing products
250
+ { assetId: 'existing-product-uuid', quantity: 1 },
251
+ // Or create items on-the-fly
252
+ {
253
+ name: 'Custom Magic Potion',
254
+ price: '12.50',
255
+ quantity: 2,
256
+ description: 'Instant health boost',
257
+ },
258
+ ],
259
+ paymentLabel: 'My Awesome Game Store',
260
+ });
261
+
262
+ // Show payment URL/QR to user
263
+ setPaymentUrl(session.paymentUrl);
264
+ setReferenceKey(session.referenceKey);
265
+
266
+ // Start polling for payment completion
267
+ const { paid } = await publicBeep.widget.waitForPaid({
268
+ referenceKey: session.referenceKey,
269
+ intervalMs: 5000, // Check every 5 seconds
270
+ timeoutMs: 5 * 60 * 1000, // 5 minute timeout
271
+ });
272
+
273
+ if (paid) {
274
+ // Payment successful! Unlock content
275
+ setShowSuccessMessage(true);
276
+ unlockPremiumFeatures();
277
+ }
278
+ } catch (error) {
279
+ console.error('Payment failed:', error);
280
+ }
281
+ };
273
282
  ```
274
283
 
275
- #### Listing All Products
284
+ ### Frontend API Reference
276
285
 
277
- ```typescript
278
- // Get all your amazing products
279
- const products = await beep.products.listProducts();
280
- console.log(`You have ${products.length} products`);
286
+ #### Creating Payment Sessions
281
287
 
282
- // Loop through them if you're feeling fancy
283
- products.forEach((product) => {
284
- console.log(`${product.name}: ${product.price} ${product.token || 'tokens'}`);
288
+ ```typescript
289
+ const session = await publicBeep.widget.createPaymentSession({
290
+ assets: [
291
+ { assetId: 'existing-product', quantity: 1 },
292
+ { name: 'Custom Item', price: '5.99', quantity: 1 },
293
+ ],
294
+ paymentLabel: 'Your Store Name',
285
295
  });
286
296
  ```
287
297
 
288
- #### Updating a Product
298
+ #### Checking Payment Status
289
299
 
290
300
  ```typescript
291
- // Change your mind about pricing? No problemo!
292
- const updatedProduct = await beep.products.updateProduct('prod_123abc456def', {
293
- price: '14.99', // Price increase! Cha-ching!
294
- description: 'Now with extra sparkles ✨',
295
- token: SupportedToken.USDT,
296
- });
297
-
298
- console.log('Product updated with new price:', updatedProduct.price);
301
+ const status = await publicBeep.widget.getPaymentStatus(referenceKey);
302
+ console.log('Payment completed:', status.paid);
299
303
  ```
300
304
 
301
- #### Deleting a Product
305
+ #### Waiting for Payment (with polling)
302
306
 
303
307
  ```typescript
304
- // That product is so last season - delete it!
305
- await beep.products.deleteProduct('prod_123abc456def');
306
- console.log('Poof! Product deleted.');
308
+ const { paid, timedOut } = await publicBeep.widget.waitForPaid({
309
+ referenceKey: session.referenceKey,
310
+ intervalMs: 5000,
311
+ timeoutMs: 300000, // 5 minutes
312
+ });
307
313
  ```
308
314
 
309
- ### `beep.payments`
315
+ ---
316
+
317
+ ## πŸ€“ Advanced API Reference
310
318
 
311
- Handle low-level payment operations like asset purchasing and transaction signing.
319
+ ## Token Utilities
320
+
321
+ ### `SupportedToken`
322
+
323
+ Clean token enum instead of remembering addresses:
312
324
 
313
325
  ```typescript
314
- // Request payment for assets
315
- const payment = await beep.payments.requestAndPurchaseAsset({
316
- paymentReference: 'premium_subscription_123',
317
- assetIds: ['asset_1', 'asset_2'],
318
- });
326
+ import { SupportedToken } from '@beep-it/sdk-core';
319
327
 
320
- // Sign Solana transactions directly
321
- const signedTx = await beep.payments.signSolanaTransaction({
322
- senderAddress: 'sender_wallet_address',
323
- recipientAddress: 'recipient_wallet_address',
324
- tokenMintAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
325
- amount: 1000000, // 1.0 USDT in base units
326
- decimals: 6,
327
- });
328
+ const token = SupportedToken.USDT; // Much cleaner!
328
329
  ```
329
330
 
330
331
  ### `TokenUtils`
331
332
 
332
- For the super nerds who want to play with token addresses:
333
+ Advanced token utilities:
333
334
 
334
335
  ```typescript
335
336
  import { TokenUtils, SupportedToken } from '@beep-it/sdk-core';
336
337
 
337
338
  // Get the address from a token enum
338
339
  const address = TokenUtils.getTokenAddress(SupportedToken.USDT);
339
- console.log(address); // 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
340
340
 
341
341
  // Check if we support a token
342
- const isSupported = TokenUtils.isTokenSupported(SupportedToken.USDT); // true
343
- const isUsdtSupported = TokenUtils.isTokenSupported('USDT'); // false (coming soonβ„’)
342
+ const isSupported = TokenUtils.isTokenSupported(SupportedToken.USDT);
344
343
 
345
344
  // Get a token enum from an address (reverse lookup)
346
345
  const token = TokenUtils.getTokenFromAddress('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB');
347
- console.log(token); // SupportedToken.USDT
348
-
349
- // Get the default token if none specified
350
- const defaultToken = TokenUtils.getDefaultToken();
351
- console.log(defaultToken); // SupportedToken.USDT
352
346
  ```
353
347
 
354
348
  ---
@@ -362,3 +356,27 @@ console.log(defaultToken); // SupportedToken.USDT
362
356
  ## License
363
357
 
364
358
  MIT. Go wild.
359
+ #### Payouts (BeepClient Only)
360
+
361
+ Initiate a payout from your treasury wallet to an external address. Requires a secret API key and must be called server-side.
362
+
363
+ Notes:
364
+ - The server derives the source wallet from your API key's merchant and the requested chain; you do not provide a walletId.
365
+ - `amount` must be provided in the token's smallest units (integer as a string). For USDC with 6 decimals, 1.00 USDC = "1000000".
366
+ - The response indicates acceptance or rejection. Execution happens asynchronously after treasury funds are reserved.
367
+
368
+ Example:
369
+ ```ts
370
+ import { BeepClient } from '@beep-it/sdk-core';
371
+
372
+ const beep = new BeepClient({ apiKey: process.env.BEEP_API_KEY! });
373
+
374
+ const result = await beep.createPayout({
375
+ amount: '1000000', // 1.00 USDC (6 decimals)
376
+ destinationWalletAddress: 'DESTINATION_ADDRESS',
377
+ chain: 'SOLANA',
378
+ token: 'USDC',
379
+ });
380
+
381
+ console.log(result.status, result.message);
382
+ ```