@beep-it/sdk-core 0.1.2-beta.2 β 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 -197
- 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/payment.d.ts +0 -211
- package/dist/types/payment.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,36 +2,6 @@
|
|
|
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
|
-
|
|
35
5
|
## π€ So, like, what even _is_ this?
|
|
36
6
|
|
|
37
7
|
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.
|
|
@@ -48,39 +18,56 @@ Basically, we're the β¨ unpaid intern β¨ who handles your finances so you can
|
|
|
48
18
|
|
|
49
19
|
---
|
|
50
20
|
|
|
51
|
-
##
|
|
21
|
+
## π Let's Get This Bread: Your 3-Step Setup
|
|
52
22
|
|
|
53
|
-
|
|
23
|
+
This is probably easier than picking an Instagram filter. No cap.
|
|
54
24
|
|
|
55
|
-
###
|
|
25
|
+
### Step 1: Download the Magic
|
|
56
26
|
|
|
57
|
-
|
|
27
|
+
In your project's command line thingy (the black box where you type stuff), paste this:
|
|
58
28
|
|
|
59
29
|
```bash
|
|
60
30
|
npm install @beep-it/sdk-core
|
|
61
31
|
```
|
|
62
32
|
|
|
63
|
-
|
|
33
|
+
This basically downloads our toolkit and puts it in your project's folder.
|
|
64
34
|
|
|
65
|
-
|
|
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.
|
|
35
|
+
### Step 2: Get Your Secret Handshake (aka API Key)
|
|
68
36
|
|
|
69
|
-
|
|
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.
|
|
38
|
+
|
|
39
|
+
> **Seriously, don't share this.** It's like giving someone the keys to your house. Don't do it.
|
|
40
|
+
|
|
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.
|
|
70
44
|
|
|
71
45
|
```typescript
|
|
46
|
+
// This line just says, "Hey, I wanna use that beep-sdk thing I just downloaded."
|
|
72
47
|
import { BeepClient, SupportedToken } from '@beep-it/sdk-core';
|
|
73
48
|
|
|
49
|
+
// This line creates your BEEP-Bot. It's now ready for your commands.
|
|
74
50
|
const beep = new BeepClient({
|
|
75
|
-
|
|
51
|
+
// Just paste that secret key you got from the dashboard right here.
|
|
52
|
+
apiKey: 'your_super_secret_api_key_goes_here',
|
|
76
53
|
});
|
|
54
|
+
|
|
55
|
+
console.log('Ok, your BEEP-Bot is ready. Slay.');
|
|
77
56
|
```
|
|
78
57
|
|
|
79
|
-
|
|
58
|
+
Bet. You're all set up. Now for the fun part.
|
|
59
|
+
|
|
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! πΈ
|
|
80
65
|
|
|
81
|
-
|
|
66
|
+
### Step 1: Ask for the Money
|
|
82
67
|
|
|
83
|
-
|
|
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)
|
|
84
71
|
|
|
85
72
|
1. **You create an invoice** - This is literally just you telling our servers "hey, I want $X for Y reason"
|
|
86
73
|
2. **We create an invoice** - Think of this as a digital receipt that says "pay this amount pls"
|
|
@@ -97,286 +84,309 @@ Let's say you want to charge someone 5 USDT for a pack of 100 magic crystals in
|
|
|
97
84
|
Seriously, all _you_ need to worry about is step 1. We handle 2-7 because we're nice like that.
|
|
98
85
|
|
|
99
86
|
```typescript
|
|
100
|
-
//
|
|
87
|
+
// Just describe what you're charging for.
|
|
101
88
|
const invoiceDetails = {
|
|
102
89
|
description: 'A pack of 100 magic crystals',
|
|
103
|
-
amount: '5.00',
|
|
104
|
-
token: SupportedToken.USDT,
|
|
105
|
-
payerType: 'customer_wallet' as const,
|
|
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
|
|
106
93
|
};
|
|
107
94
|
|
|
108
95
|
try {
|
|
96
|
+
// Tell your BEEP-Bot to create an invoice for payment.
|
|
97
|
+
// This creates a bill and gets everything ready behind the scenes.
|
|
109
98
|
const invoice = await beep.invoices.createInvoice(invoiceDetails);
|
|
110
99
|
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
const updatedInvoice = await beep.invoices.getInvoice(invoice.id!);
|
|
121
|
-
if (updatedInvoice.status === 'paid') {
|
|
122
|
-
// Unlock content for the user!
|
|
123
|
-
}
|
|
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.
|
|
124
109
|
} catch (error) {
|
|
125
|
-
console.error('
|
|
110
|
+
console.error('Oof. Something went wrong creating the invoice:', error.message);
|
|
126
111
|
}
|
|
127
112
|
```
|
|
128
113
|
|
|
129
|
-
|
|
114
|
+
And that's literally it. Once the user pays, the money appears in your account. You just made money.
|
|
115
|
+
|
|
116
|
+
---
|
|
130
117
|
|
|
131
|
-
|
|
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.
|
|
121
|
+
|
|
122
|
+
### `BeepClient` (server-side, secret key)
|
|
123
|
+
|
|
124
|
+
Initializes the client. Takes an `options` object.
|
|
132
125
|
|
|
133
126
|
```typescript
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
payerType: 'customer_wallet',
|
|
139
|
-
});
|
|
127
|
+
new BeepClient(options: {
|
|
128
|
+
apiKey: string; // Required. Your secret API key.
|
|
129
|
+
serverUrl?: string; // Optional. For testing. Defaults to production.
|
|
130
|
+
})
|
|
140
131
|
```
|
|
141
132
|
|
|
142
|
-
|
|
133
|
+
**High-Level Methods:**
|
|
134
|
+
|
|
135
|
+
#### Creating Invoices for Payment
|
|
143
136
|
|
|
144
137
|
```typescript
|
|
145
|
-
//
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
151
144
|
});
|
|
152
145
|
|
|
153
|
-
//
|
|
154
|
-
|
|
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
|
+
}
|
|
155
176
|
```
|
|
156
177
|
|
|
157
|
-
####
|
|
178
|
+
#### Health Check
|
|
158
179
|
|
|
159
180
|
```typescript
|
|
160
|
-
//
|
|
161
|
-
const
|
|
162
|
-
|
|
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
|
-
});
|
|
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
|
|
171
184
|
```
|
|
172
185
|
|
|
173
|
-
|
|
186
|
+
**Low-Level Modules:**
|
|
174
187
|
|
|
175
|
-
|
|
188
|
+
For when you need more control.
|
|
176
189
|
|
|
177
|
-
|
|
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
|
-
});
|
|
190
|
+
### `SupportedToken`
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
await beep.payments.startStreaming({
|
|
190
|
-
apiKey: 'your_secret_api_key',
|
|
191
|
-
invoiceId: session.invoiceId
|
|
192
|
-
});
|
|
192
|
+
Our shiny new enum for supported tokens! Way easier than remembering addresses.
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
invoiceId: session.invoiceId
|
|
198
|
-
});
|
|
194
|
+
```typescript
|
|
195
|
+
// Import it like this
|
|
196
|
+
import { SupportedToken } from '@beep-it/sdk-core';
|
|
199
197
|
|
|
200
|
-
//
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
invoiceId: session.invoiceId
|
|
204
|
-
});
|
|
198
|
+
// Use it like this
|
|
199
|
+
const token = SupportedToken.USDT; // Currently supported
|
|
200
|
+
// SupportedToken.USDC coming soon!
|
|
205
201
|
```
|
|
206
202
|
|
|
207
|
-
|
|
203
|
+
### `beep.invoices`
|
|
208
204
|
|
|
209
|
-
|
|
205
|
+
Handle invoice operations - create, retrieve, and manage payment invoices.
|
|
210
206
|
|
|
211
|
-
|
|
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
|
+
});
|
|
212
215
|
|
|
213
|
-
|
|
216
|
+
// Get all your invoices
|
|
217
|
+
const invoices = await beep.invoices.listInvoices();
|
|
214
218
|
|
|
215
|
-
|
|
219
|
+
// Look up a specific invoice
|
|
220
|
+
const invoice = await beep.invoices.getInvoice('inv_123abc');
|
|
216
221
|
|
|
217
|
-
|
|
218
|
-
|
|
222
|
+
// Delete an invoice
|
|
223
|
+
await beep.invoices.deleteInvoice('inv_123abc');
|
|
219
224
|
```
|
|
220
225
|
|
|
221
|
-
|
|
226
|
+
### `beep.products`
|
|
222
227
|
|
|
223
|
-
|
|
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!
|
|
228
|
+
Manage your products - create reusable payment configurations with sweet token enum support! π
|
|
226
229
|
|
|
227
|
-
####
|
|
230
|
+
#### Creating Products
|
|
228
231
|
|
|
229
232
|
```typescript
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
|
234
240
|
});
|
|
235
|
-
```
|
|
236
241
|
|
|
237
|
-
|
|
242
|
+
console.log(`Created product with ID: ${product.id}`);
|
|
238
243
|
|
|
239
|
-
|
|
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!
|
|
251
|
+
});
|
|
240
252
|
|
|
241
|
-
|
|
253
|
+
console.log(`Created subscription with ID: ${subscriptionProduct.id}`);
|
|
242
254
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
};
|
|
282
|
-
```
|
|
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
|
+
});
|
|
283
263
|
|
|
284
|
-
|
|
264
|
+
console.log(`Created one-time product with ID: ${oneTimeProduct.id}`);
|
|
265
|
+
```
|
|
285
266
|
|
|
286
|
-
####
|
|
267
|
+
#### Getting a Product
|
|
287
268
|
|
|
288
269
|
```typescript
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
{ name: 'Custom Item', price: '5.99', quantity: 1 },
|
|
293
|
-
],
|
|
294
|
-
paymentLabel: 'Your Store Name',
|
|
295
|
-
});
|
|
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}`);
|
|
296
273
|
```
|
|
297
274
|
|
|
298
|
-
####
|
|
275
|
+
#### Listing All Products
|
|
299
276
|
|
|
300
277
|
```typescript
|
|
301
|
-
|
|
302
|
-
|
|
278
|
+
// Get all your amazing products
|
|
279
|
+
const products = await beep.products.listProducts();
|
|
280
|
+
console.log(`You have ${products.length} products`);
|
|
281
|
+
|
|
282
|
+
// Loop through them if you're feeling fancy
|
|
283
|
+
products.forEach((product) => {
|
|
284
|
+
console.log(`${product.name}: ${product.price} ${product.token || 'tokens'}`);
|
|
285
|
+
});
|
|
303
286
|
```
|
|
304
287
|
|
|
305
|
-
####
|
|
288
|
+
#### Updating a Product
|
|
306
289
|
|
|
307
290
|
```typescript
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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,
|
|
312
296
|
});
|
|
313
|
-
```
|
|
314
297
|
|
|
315
|
-
|
|
298
|
+
console.log('Product updated with new price:', updatedProduct.price);
|
|
299
|
+
```
|
|
316
300
|
|
|
317
|
-
|
|
301
|
+
#### Deleting a Product
|
|
318
302
|
|
|
319
|
-
|
|
303
|
+
```typescript
|
|
304
|
+
// That product is so last season - delete it!
|
|
305
|
+
await beep.products.deleteProduct('prod_123abc456def');
|
|
306
|
+
console.log('Poof! Product deleted.');
|
|
307
|
+
```
|
|
320
308
|
|
|
321
|
-
### `
|
|
309
|
+
### `beep.payments`
|
|
322
310
|
|
|
323
|
-
|
|
311
|
+
Handle low-level payment operations like asset purchasing and transaction signing.
|
|
324
312
|
|
|
325
313
|
```typescript
|
|
326
|
-
|
|
314
|
+
// Request payment for assets
|
|
315
|
+
const payment = await beep.payments.requestAndPurchaseAsset({
|
|
316
|
+
paymentReference: 'premium_subscription_123',
|
|
317
|
+
assetIds: ['asset_1', 'asset_2'],
|
|
318
|
+
});
|
|
327
319
|
|
|
328
|
-
|
|
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
|
+
});
|
|
329
328
|
```
|
|
330
329
|
|
|
331
330
|
### `TokenUtils`
|
|
332
331
|
|
|
333
|
-
|
|
332
|
+
For the super nerds who want to play with token addresses:
|
|
334
333
|
|
|
335
334
|
```typescript
|
|
336
335
|
import { TokenUtils, SupportedToken } from '@beep-it/sdk-core';
|
|
337
336
|
|
|
338
337
|
// Get the address from a token enum
|
|
339
338
|
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);
|
|
342
|
+
const isSupported = TokenUtils.isTokenSupported(SupportedToken.USDT); // true
|
|
343
|
+
const isUsdtSupported = TokenUtils.isTokenSupported('USDT'); // false (coming soonβ’)
|
|
343
344
|
|
|
344
345
|
// Get a token enum from an address (reverse lookup)
|
|
345
346
|
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
|
|
346
352
|
```
|
|
347
353
|
|
|
348
|
-
|
|
354
|
+
### `BeepPublicClient` (browser, publishable key)
|
|
349
355
|
|
|
350
|
-
|
|
356
|
+
Use this in browsers or anywhere you canβt safely keep a secret key. It talks only to the public, CORS-open widget endpoints.
|
|
351
357
|
|
|
352
|
-
|
|
358
|
+
```typescript
|
|
359
|
+
import { BeepPublicClient } from '@beep-it/sdk-core';
|
|
353
360
|
|
|
354
|
-
|
|
361
|
+
const publicClient = new BeepPublicClient({
|
|
362
|
+
publishableKey: 'beep_pk_...',
|
|
363
|
+
serverUrl: 'https://api.justbeep.it', // optional
|
|
364
|
+
});
|
|
355
365
|
|
|
356
|
-
|
|
366
|
+
// Create a payment session with mixed assets (existing + ephemeral)
|
|
367
|
+
const session = await publicClient.widget.createPaymentSession({
|
|
368
|
+
assets: [
|
|
369
|
+
{ assetId: 'existing-product-uuid', quantity: 1 },
|
|
370
|
+
{ name: 'Custom Item', price: '12.50', quantity: 2, description: 'On-the-fly item' },
|
|
371
|
+
],
|
|
372
|
+
paymentLabel: 'My Store',
|
|
373
|
+
});
|
|
357
374
|
|
|
358
|
-
|
|
359
|
-
#### Payouts (BeepClient Only)
|
|
375
|
+
console.log(session.paymentUrl, session.referenceKey);
|
|
360
376
|
|
|
361
|
-
|
|
377
|
+
// Poll payment status
|
|
378
|
+
const status = await publicClient.widget.getPaymentStatus(session.referenceKey);
|
|
379
|
+
console.log('paid:', status.paid);
|
|
380
|
+
```
|
|
362
381
|
|
|
363
|
-
|
|
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.
|
|
382
|
+
---
|
|
367
383
|
|
|
368
|
-
|
|
369
|
-
```ts
|
|
370
|
-
import { BeepClient } from '@beep-it/sdk-core';
|
|
384
|
+
## Resources
|
|
371
385
|
|
|
372
|
-
|
|
386
|
+
[Beep llms.txt](https://www.justbeep.it/llms.txt)
|
|
373
387
|
|
|
374
|
-
|
|
375
|
-
amount: '1000000', // 1.00 USDC (6 decimals)
|
|
376
|
-
destinationWalletAddress: 'DESTINATION_ADDRESS',
|
|
377
|
-
chain: 'SOLANA',
|
|
378
|
-
token: 'USDC',
|
|
379
|
-
});
|
|
388
|
+
---
|
|
380
389
|
|
|
381
|
-
|
|
382
|
-
|
|
390
|
+
## License
|
|
391
|
+
|
|
392
|
+
MIT. Go wild.
|