@paddle/paddle-node-sdk 2.7.1 → 2.7.3
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 +1935 -70
- package/dist/cjs/notifications/entities/shared/transaction-payout-totals-notification.js +2 -0
- package/dist/cjs/resources/businesses/index.js +2 -2
- package/dist/cjs/version.js +1 -1
- package/dist/esm/notifications/entities/shared/transaction-payout-totals-notification.js +2 -0
- package/dist/esm/resources/businesses/index.js +2 -2
- package/dist/esm/version.js +1 -1
- package/dist/types/notifications/entities/shared/transaction-payout-totals-notification.d.ts +2 -0
- package/dist/types/notifications/types/shared/transaction-payout-totals-notification-response.d.ts +2 -0
- package/dist/types/resources/businesses/index.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,133 +81,1867 @@ Properties in the Paddle API use `snake_case`. To follow JavaScript conventions,
|
|
|
81
81
|
|
|
82
82
|
### List entities
|
|
83
83
|
|
|
84
|
-
You can list supported entities with the `list` function in the resource.
|
|
84
|
+
You can list supported entities with the `list` function in the resource.
|
|
85
|
+
|
|
86
|
+
When you call a list function, it returns an iterator object. This object doesn't fetch any data from the API right away.
|
|
87
|
+
|
|
88
|
+
**You must call the `next()` method** on this iterator to retrieve the first page of results (e.g., `await productCollection.next()`). Calling `next()` again will fetch the subsequent page.
|
|
89
|
+
|
|
90
|
+
<details open>
|
|
91
|
+
<summary style="font-size: 1.1rem;">Products (products.list())</summary>
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { Paddle, Product, ProductCollection } from '@paddle/paddle-node-sdk'
|
|
95
|
+
|
|
96
|
+
const paddle = new Paddle('API_KEY')
|
|
97
|
+
|
|
98
|
+
async function getPaginatedProducts() {
|
|
99
|
+
try {
|
|
100
|
+
// Returns an iterator instance
|
|
101
|
+
const productCollection: ProductCollection = paddle.products.list()
|
|
102
|
+
|
|
103
|
+
// Call `next()` to retrieve the first page of the dataset.
|
|
104
|
+
const firstPage: Product[] = await productCollection.next()
|
|
105
|
+
console.log("First page of products:", firstPage)
|
|
106
|
+
|
|
107
|
+
if (productCollection.hasMore) {
|
|
108
|
+
// Calling `next()` again will retrieve subsequent pages.
|
|
109
|
+
const secondPage: Product[] = await productCollection.next()
|
|
110
|
+
console.log("Second page of products:", secondPage)
|
|
111
|
+
} else {
|
|
112
|
+
console.log("No more pages of products available after the first page.")
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.error("Error fetching paginated products:", e)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getPaginatedProducts()
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
async function getAllProducts(): Promise<Product[]> {
|
|
126
|
+
const productCollection: ProductCollection = paddle.products.list()
|
|
127
|
+
const allItems: Product[] = []
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
for await (const product of productCollection) {
|
|
131
|
+
allItems.push(product)
|
|
132
|
+
}
|
|
133
|
+
if (allItems.length === 0) {
|
|
134
|
+
console.log('No products were found.')
|
|
135
|
+
}
|
|
136
|
+
return allItems
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.error('Error within getAllProducts:', e)
|
|
139
|
+
throw e // If you want to propagate the error
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary style="font-size: 1.1rem;">Subscriptions (subscriptions.list())</summary>
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { Paddle, Subscription, SubscriptionCollection } from '@paddle/paddle-node-sdk'
|
|
151
|
+
|
|
152
|
+
const paddle = new Paddle('API_KEY')
|
|
153
|
+
|
|
154
|
+
async function getPaginatedSubscriptions() {
|
|
155
|
+
try {
|
|
156
|
+
const subscriptionCollection: SubscriptionCollection = paddle.subscriptions.list()
|
|
157
|
+
|
|
158
|
+
const firstPage: Subscription[] = await subscriptionCollection.next()
|
|
159
|
+
console.log("First page of subscriptions:", firstPage)
|
|
160
|
+
|
|
161
|
+
if (subscriptionCollection.hasMore) {
|
|
162
|
+
const secondPage: Subscription[] = await subscriptionCollection.next()
|
|
163
|
+
console.log("Second page of subscriptions:", secondPage)
|
|
164
|
+
} else {
|
|
165
|
+
console.log("No more pages of subscriptions available after the first page.")
|
|
166
|
+
}
|
|
167
|
+
} catch (e) {
|
|
168
|
+
console.error("Error fetching paginated subscriptions:", e)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getPaginatedSubscriptions()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
async function getAllSubscriptions(): Promise<Subscription[]> {
|
|
179
|
+
const subscriptionCollection: SubscriptionCollection = paddle.subscriptions.list()
|
|
180
|
+
const allItems: Subscription[] = []
|
|
181
|
+
try {
|
|
182
|
+
for await (const subscription of subscriptionCollection) {
|
|
183
|
+
allItems.push(subscription)
|
|
184
|
+
}
|
|
185
|
+
if (allItems.length === 0) {
|
|
186
|
+
console.log('No subscriptions were found.')
|
|
187
|
+
}
|
|
188
|
+
return allItems
|
|
189
|
+
} catch (e) {
|
|
190
|
+
console.error('Error within getAllSubscriptions:', e)
|
|
191
|
+
throw e // If you want to propagate the error
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
</details>
|
|
197
|
+
|
|
198
|
+
<details>
|
|
199
|
+
<summary style="font-size: 1.1rem;">Customers (customers.list())</summary>
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { Paddle, Customer, CustomerCollection } from '@paddle/paddle-node-sdk'
|
|
203
|
+
|
|
204
|
+
const paddle = new Paddle('API_KEY')
|
|
205
|
+
|
|
206
|
+
async function getPaginatedCustomers() {
|
|
207
|
+
try {
|
|
208
|
+
const customerCollection: CustomerCollection = paddle.customers.list()
|
|
209
|
+
|
|
210
|
+
const firstPage: Customer[] = await customerCollection.next()
|
|
211
|
+
console.log("First page of customers:", firstPage)
|
|
212
|
+
|
|
213
|
+
if (customerCollection.hasMore) {
|
|
214
|
+
const secondPage: Customer[] = await customerCollection.next()
|
|
215
|
+
console.log("Second page of customers:", secondPage)
|
|
216
|
+
} else {
|
|
217
|
+
console.log("No more pages of customers available after the first page.")
|
|
218
|
+
}
|
|
219
|
+
} catch (e) {
|
|
220
|
+
console.error("Error fetching paginated customers:", e)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
getPaginatedCustomers()
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
async function getAllCustomers(): Promise<Customer[]> {
|
|
231
|
+
const customerCollection: CustomerCollection = paddle.customers.list()
|
|
232
|
+
const allItems: Customer[] = []
|
|
233
|
+
try {
|
|
234
|
+
for await (const customer of customerCollection) {
|
|
235
|
+
allItems.push(customer)
|
|
236
|
+
}
|
|
237
|
+
if (allItems.length === 0) {
|
|
238
|
+
console.log('No customers were found.')
|
|
239
|
+
}
|
|
240
|
+
return allItems
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.error('Error within getAllCustomers:', e)
|
|
243
|
+
throw e
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
</details>
|
|
249
|
+
|
|
250
|
+
<details>
|
|
251
|
+
<summary style="font-size: 1.1rem;">Addresses (addresses.list())</summary>
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { Paddle, Address, AddressCollection } from '@paddle/paddle-node-sdk'
|
|
255
|
+
|
|
256
|
+
const paddle = new Paddle('API_KEY')
|
|
257
|
+
|
|
258
|
+
async function getPaginatedAddresses(customerId: string) {
|
|
259
|
+
try {
|
|
260
|
+
// Note: addresses.list() requires a customerId
|
|
261
|
+
const addressCollection: AddressCollection = paddle.addresses.list(customerId)
|
|
262
|
+
|
|
263
|
+
const firstPage: Address[] = await addressCollection.next()
|
|
264
|
+
console.log(`First page of addresses for customer ${customerId}:`, firstPage)
|
|
265
|
+
|
|
266
|
+
if (addressCollection.hasMore) {
|
|
267
|
+
const secondPage: Address[] = await addressCollection.next()
|
|
268
|
+
console.log(`Second page of addresses for customer ${customerId}:`, secondPage)
|
|
269
|
+
} else {
|
|
270
|
+
console.log(`No more pages of addresses available for customer ${customerId} after the first page.`)
|
|
271
|
+
}
|
|
272
|
+
} catch (e) {
|
|
273
|
+
console.error(`Error fetching paginated addresses for customer ${customerId}:`, e)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
getPaginatedAddresses('ctm_01grnn4zta5a1mf02jjze7y2ys')
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
async function getAllAddresses(customerId: string): Promise<Address[]> {
|
|
284
|
+
// Note: addresses.list() requires a customerId
|
|
285
|
+
const addressCollection: AddressCollection = paddle.addresses.list(customerId)
|
|
286
|
+
const allItems: Address[] = []
|
|
287
|
+
try {
|
|
288
|
+
for await (const address of addressCollection) {
|
|
289
|
+
allItems.push(address)
|
|
290
|
+
}
|
|
291
|
+
if (allItems.length === 0) {
|
|
292
|
+
console.log(`No addresses were found for customer ${customerId}.`)
|
|
293
|
+
}
|
|
294
|
+
return allItems
|
|
295
|
+
} catch (e) {
|
|
296
|
+
console.error(`Error within getAllAddresses for customer ${customerId}:`, e)
|
|
297
|
+
throw e // If you want to propagate the error
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
</details>
|
|
303
|
+
|
|
304
|
+
<details>
|
|
305
|
+
<summary style="font-size: 1.1rem;">Adjustments (adjustments.list())</summary>
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { Paddle, Adjustment, AdjustmentCollection } from '@paddle/paddle-node-sdk'
|
|
309
|
+
|
|
310
|
+
const paddle = new Paddle('API_KEY')
|
|
311
|
+
|
|
312
|
+
async function getPaginatedAdjustments() {
|
|
313
|
+
try {
|
|
314
|
+
const adjustmentCollection: AdjustmentCollection = paddle.adjustments.list()
|
|
315
|
+
|
|
316
|
+
const firstPage: Adjustment[] = await adjustmentCollection.next()
|
|
317
|
+
console.log("First page of adjustments:", firstPage)
|
|
318
|
+
|
|
319
|
+
if (adjustmentCollection.hasMore) {
|
|
320
|
+
const secondPage: Adjustment[] = await adjustmentCollection.next()
|
|
321
|
+
console.log("Second page of adjustments:", secondPage)
|
|
322
|
+
} else {
|
|
323
|
+
console.log("No more pages of adjustments available after the first page.")
|
|
324
|
+
}
|
|
325
|
+
} catch (e) {
|
|
326
|
+
console.error("Error fetching paginated adjustments:", e)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
getPaginatedAdjustments()
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
async function getAllAdjustments(): Promise<Adjustment[]> {
|
|
336
|
+
const adjustmentCollection: AdjustmentCollection = paddle.adjustments.list()
|
|
337
|
+
const allItems: Adjustment[] = []
|
|
338
|
+
try {
|
|
339
|
+
for await (const adjustment of adjustmentCollection) {
|
|
340
|
+
allItems.push(adjustment)
|
|
341
|
+
}
|
|
342
|
+
if (allItems.length === 0) {
|
|
343
|
+
console.log('No adjustments were found.')
|
|
344
|
+
}
|
|
345
|
+
return allItems
|
|
346
|
+
} catch (e) {
|
|
347
|
+
console.error('Error within getAllAdjustments:', e)
|
|
348
|
+
throw e // If you want to propagate the error
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
</details>
|
|
354
|
+
|
|
355
|
+
<details>
|
|
356
|
+
<summary style="font-size: 1.1rem;">Businesses (businesses.list())</summary>
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
import { Paddle, Business, BusinessCollection } from '@paddle/paddle-node-sdk'
|
|
360
|
+
|
|
361
|
+
const paddle = new Paddle('API_KEY')
|
|
362
|
+
|
|
363
|
+
async function getPaginatedBusinesses(customerId: string) {
|
|
364
|
+
try {
|
|
365
|
+
// Note: businesses.list() requires a customerId
|
|
366
|
+
const businessCollection: BusinessCollection = paddle.businesses.list(customerId)
|
|
367
|
+
|
|
368
|
+
const firstPage: Business[] = await businessCollection.next()
|
|
369
|
+
console.log(`First page of businesses for customer ${customerId}:`, firstPage)
|
|
370
|
+
|
|
371
|
+
if (businessCollection.hasMore) {
|
|
372
|
+
const secondPage: Business[] = await businessCollection.next()
|
|
373
|
+
console.log(`Second page of businesses for customer ${customerId}:`, secondPage)
|
|
374
|
+
} else {
|
|
375
|
+
console.log(`No more pages of businesses available for customer ${customerId} after the first page.`)
|
|
376
|
+
}
|
|
377
|
+
} catch (e) {
|
|
378
|
+
console.error(`Error fetching paginated businesses for customer ${customerId}:`, e)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
getPaginatedBusinesses('ctm_01grnn4zta5a1mf02jjze7y2ys')
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
async function getAllBusinesses(customerId: string): Promise<Business[]> {
|
|
388
|
+
// Note: businesses.list() requires a customerId
|
|
389
|
+
const businessCollection: BusinessCollection = paddle.businesses.list(customerId)
|
|
390
|
+
const allItems: Business[] = []
|
|
391
|
+
try {
|
|
392
|
+
for await (const business of businessCollection) {
|
|
393
|
+
allItems.push(business)
|
|
394
|
+
}
|
|
395
|
+
if (allItems.length === 0) {
|
|
396
|
+
console.log(`No businesses were found for customer ${customerId}.`)
|
|
397
|
+
}
|
|
398
|
+
return allItems
|
|
399
|
+
} catch (e) {
|
|
400
|
+
console.error(`Error within getAllBusinesses for customer ${customerId}:`, e)
|
|
401
|
+
throw e
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
</details>
|
|
407
|
+
|
|
408
|
+
<details>
|
|
409
|
+
<summary style="font-size: 1.1rem;">Discounts (discounts.list())</summary>
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
import { Paddle, Discount, DiscountCollection } from '@paddle/paddle-node-sdk'
|
|
413
|
+
|
|
414
|
+
const paddle = new Paddle('API_KEY')
|
|
415
|
+
|
|
416
|
+
async function getPaginatedDiscounts() {
|
|
417
|
+
try {
|
|
418
|
+
const discountCollection: DiscountCollection = paddle.discounts.list()
|
|
419
|
+
|
|
420
|
+
const firstPage: Discount[] = await discountCollection.next()
|
|
421
|
+
console.log("First page of discounts:", firstPage)
|
|
422
|
+
|
|
423
|
+
if (discountCollection.hasMore) {
|
|
424
|
+
const secondPage: Discount[] = await discountCollection.next()
|
|
425
|
+
console.log("Second page of discounts:", secondPage)
|
|
426
|
+
} else {
|
|
427
|
+
console.log("No more pages of discounts available after the first page.")
|
|
428
|
+
}
|
|
429
|
+
} catch (e) {
|
|
430
|
+
console.error("Error fetching paginated discounts:", e)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
getPaginatedDiscounts()
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
437
|
+
|
|
438
|
+
```typescript
|
|
439
|
+
async function getAllDiscounts(): Promise<Discount[]> {
|
|
440
|
+
const discountCollection: DiscountCollection = paddle.discounts.list()
|
|
441
|
+
const allItems: Discount[] = []
|
|
442
|
+
try {
|
|
443
|
+
for await (const discount of discountCollection) {
|
|
444
|
+
allItems.push(discount)
|
|
445
|
+
}
|
|
446
|
+
if (allItems.length === 0) {
|
|
447
|
+
console.log('No discounts were found.')
|
|
448
|
+
}
|
|
449
|
+
return allItems
|
|
450
|
+
} catch (e) {
|
|
451
|
+
console.error('Error within getAllDiscounts:', e)
|
|
452
|
+
throw e
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
</details>
|
|
458
|
+
|
|
459
|
+
<details>
|
|
460
|
+
<summary style="font-size: 1.1rem;">Prices (prices.list())</summary>
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
import { Paddle, Price, PriceCollection } from '@paddle/paddle-node-sdk'
|
|
464
|
+
|
|
465
|
+
const paddle = new Paddle('API_KEY')
|
|
466
|
+
|
|
467
|
+
async function getPaginatedPrices() {
|
|
468
|
+
try {
|
|
469
|
+
const priceCollection: PriceCollection = paddle.prices.list()
|
|
470
|
+
|
|
471
|
+
const firstPage: Price[] = await priceCollection.next()
|
|
472
|
+
console.log("First page of prices:", firstPage)
|
|
473
|
+
|
|
474
|
+
if (priceCollection.hasMore) {
|
|
475
|
+
const secondPage: Price[] = await priceCollection.next()
|
|
476
|
+
console.log("Second page of prices:", secondPage)
|
|
477
|
+
} else {
|
|
478
|
+
console.log("No more pages of prices available after the first page.")
|
|
479
|
+
}
|
|
480
|
+
} catch (e) {
|
|
481
|
+
console.error("Error fetching paginated prices:", e)
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
getPaginatedPrices()
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
async function getAllPrices(): Promise<Price[]> {
|
|
491
|
+
const priceCollection: PriceCollection = paddle.prices.list()
|
|
492
|
+
const allItems: Price[] = []
|
|
493
|
+
try {
|
|
494
|
+
for await (const price of priceCollection) {
|
|
495
|
+
allItems.push(price)
|
|
496
|
+
}
|
|
497
|
+
if (allItems.length === 0) {
|
|
498
|
+
console.log('No prices were found.')
|
|
499
|
+
}
|
|
500
|
+
return allItems
|
|
501
|
+
} catch (e) {
|
|
502
|
+
console.error('Error within getAllPrices:', e)
|
|
503
|
+
throw e
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
</details>
|
|
509
|
+
|
|
510
|
+
<details>
|
|
511
|
+
<summary style="font-size: 1.1rem;">Transactions (transactions.list())</summary>
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
import { Paddle, Transaction, TransactionCollection } from '@paddle/paddle-node-sdk'
|
|
515
|
+
|
|
516
|
+
const paddle = new Paddle('API_KEY')
|
|
517
|
+
|
|
518
|
+
async function getPaginatedTransactions() {
|
|
519
|
+
try {
|
|
520
|
+
const transactionCollection: TransactionCollection = paddle.transactions.list()
|
|
521
|
+
|
|
522
|
+
const firstPage: Transaction[] = await transactionCollection.next()
|
|
523
|
+
console.log("First page of transactions:", firstPage)
|
|
524
|
+
|
|
525
|
+
if (transactionCollection.hasMore) {
|
|
526
|
+
const secondPage: Transaction[] = await transactionCollection.next()
|
|
527
|
+
console.log("Second page of transactions:", secondPage)
|
|
528
|
+
} else {
|
|
529
|
+
console.log("No more pages of transactions available after the first page.")
|
|
530
|
+
}
|
|
531
|
+
} catch (e) {
|
|
532
|
+
console.error("Error fetching paginated transactions:", e)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
getPaginatedTransactions()
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
539
|
+
|
|
540
|
+
```typescript
|
|
541
|
+
async function getAllTransactions(): Promise<Transaction[]> {
|
|
542
|
+
const transactionCollection: TransactionCollection = paddle.transactions.list()
|
|
543
|
+
const allItems: Transaction[] = []
|
|
544
|
+
try {
|
|
545
|
+
for await (const transaction of transactionCollection) {
|
|
546
|
+
allItems.push(transaction)
|
|
547
|
+
}
|
|
548
|
+
if (allItems.length === 0) {
|
|
549
|
+
console.log('No transactions were found.')
|
|
550
|
+
}
|
|
551
|
+
return allItems
|
|
552
|
+
} catch (e) {
|
|
553
|
+
console.error('Error within getAllTransactions:', e)
|
|
554
|
+
throw e // If you want to propagate the error
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
</details>
|
|
560
|
+
|
|
561
|
+
<details>
|
|
562
|
+
<summary style="font-size: 1.1rem;">Payment Methods (paymentMethods.list())</summary>
|
|
563
|
+
|
|
564
|
+
```typescript
|
|
565
|
+
import { Paddle, PaymentMethod, PaymentMethodCollection } from '@paddle/paddle-node-sdk'
|
|
566
|
+
|
|
567
|
+
const paddle = new Paddle('API_KEY')
|
|
568
|
+
|
|
569
|
+
async function getPaginatedPaymentMethods(customerId: string) {
|
|
570
|
+
try {
|
|
571
|
+
// Note: paymentMethods.list() requires a customerId
|
|
572
|
+
const paymentMethodCollection: PaymentMethodCollection = paddle.paymentMethods.list(customerId)
|
|
573
|
+
|
|
574
|
+
const firstPage: PaymentMethod[] = await paymentMethodCollection.next()
|
|
575
|
+
console.log(`First page of payment methods for customer ${customerId}:`, firstPage)
|
|
576
|
+
|
|
577
|
+
if (paymentMethodCollection.hasMore) {
|
|
578
|
+
const secondPage: PaymentMethod[] = await paymentMethodCollection.next()
|
|
579
|
+
console.log(`Second page of payment methods for customer ${customerId}:`, secondPage)
|
|
580
|
+
} else {
|
|
581
|
+
console.log(`No more pages of payment methods available for customer ${customerId} after the first page.`)
|
|
582
|
+
}
|
|
583
|
+
} catch (e) {
|
|
584
|
+
console.error(`Error fetching paginated payment methods for customer ${customerId}:`, e)
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
getPaginatedPaymentMethods('ctm_01grnn4zta5a1mf02jjze7y2ys')
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
async function getAllPaymentMethods(customerId: string): Promise<PaymentMethod[]> {
|
|
594
|
+
// Note: paymentMethods.list() requires a customerId
|
|
595
|
+
const paymentMethodCollection: PaymentMethodCollection = paddle.paymentMethods.list(customerId)
|
|
596
|
+
const allItems: PaymentMethod[] = []
|
|
597
|
+
try {
|
|
598
|
+
for await (const paymentMethod of paymentMethodCollection) {
|
|
599
|
+
allItems.push(paymentMethod)
|
|
600
|
+
}
|
|
601
|
+
if (allItems.length === 0) {
|
|
602
|
+
console.log(`No payment methods were found for customer ${customerId}.`)
|
|
603
|
+
}
|
|
604
|
+
return allItems
|
|
605
|
+
} catch (e) {
|
|
606
|
+
console.error(`Error within getAllPaymentMethods for customer ${customerId}:`, e)
|
|
607
|
+
throw e // If you want to propagate the error
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
</details>
|
|
613
|
+
|
|
614
|
+
<details>
|
|
615
|
+
<summary style="font-size: 1.1rem;">Notifications (notifications.list())</summary>
|
|
616
|
+
|
|
617
|
+
```typescript
|
|
618
|
+
import { Paddle, Notification, NotificationCollection } from '@paddle/paddle-node-sdk'
|
|
619
|
+
|
|
620
|
+
const paddle = new Paddle('API_KEY')
|
|
621
|
+
|
|
622
|
+
async function getPaginatedNotifications() {
|
|
623
|
+
try {
|
|
624
|
+
const notificationCollection: NotificationCollection = paddle.notifications.list()
|
|
625
|
+
|
|
626
|
+
const firstPage: Notification[] = await notificationCollection.next()
|
|
627
|
+
console.log("First page of notifications:", firstPage)
|
|
628
|
+
|
|
629
|
+
if (notificationCollection.hasMore) {
|
|
630
|
+
const secondPage: Notification[] = await notificationCollection.next()
|
|
631
|
+
console.log("Second page of notifications:", secondPage)
|
|
632
|
+
} else {
|
|
633
|
+
console.log("No more pages of notifications available after the first page.")
|
|
634
|
+
}
|
|
635
|
+
} catch (e) {
|
|
636
|
+
console.error("Error fetching paginated notifications:", e)
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
getPaginatedNotifications()
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
643
|
+
|
|
644
|
+
```typescript
|
|
645
|
+
async function getAllNotifications(): Promise<Notification[]> {
|
|
646
|
+
const notificationCollection: NotificationCollection = paddle.notifications.list()
|
|
647
|
+
const allItems: Notification[] = []
|
|
648
|
+
try {
|
|
649
|
+
for await (const notification of notificationCollection) {
|
|
650
|
+
allItems.push(notification)
|
|
651
|
+
}
|
|
652
|
+
if (allItems.length === 0) {
|
|
653
|
+
console.log('No notifications were found.')
|
|
654
|
+
}
|
|
655
|
+
return allItems
|
|
656
|
+
} catch (e) {
|
|
657
|
+
console.error('Error within getAllNotifications:', e)
|
|
658
|
+
throw e // If you want to propagate the error
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
</details>
|
|
664
|
+
|
|
665
|
+
<details>
|
|
666
|
+
<summary style="font-size: 1.1rem;">Reports (reports.list())</summary>
|
|
667
|
+
|
|
668
|
+
```typescript
|
|
669
|
+
import { Paddle, Report, ReportCollection } from '@paddle/paddle-node-sdk'
|
|
670
|
+
|
|
671
|
+
const paddle = new Paddle('API_KEY')
|
|
672
|
+
|
|
673
|
+
async function getPaginatedReports() {
|
|
674
|
+
try {
|
|
675
|
+
const reportCollection: ReportCollection = paddle.reports.list()
|
|
676
|
+
|
|
677
|
+
const firstPage: Report[] = await reportCollection.next()
|
|
678
|
+
console.log("First page of reports:", firstPage)
|
|
679
|
+
|
|
680
|
+
if (reportCollection.hasMore) {
|
|
681
|
+
const secondPage: Report[] = await reportCollection.next()
|
|
682
|
+
console.log("Second page of reports:", secondPage)
|
|
683
|
+
} else {
|
|
684
|
+
console.log("No more pages of reports available after the first page.")
|
|
685
|
+
}
|
|
686
|
+
} catch (e) {
|
|
687
|
+
console.error("Error fetching paginated reports:", e)
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
getPaginatedReports()
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
694
|
+
|
|
695
|
+
```typescript
|
|
696
|
+
async function getAllReports(): Promise<Report[]> {
|
|
697
|
+
const reportCollection: ReportCollection = paddle.reports.list()
|
|
698
|
+
const allItems: Report[] = []
|
|
699
|
+
try {
|
|
700
|
+
for await (const report of reportCollection) {
|
|
701
|
+
allItems.push(report)
|
|
702
|
+
}
|
|
703
|
+
if (allItems.length === 0) {
|
|
704
|
+
console.log('No reports were found.')
|
|
705
|
+
}
|
|
706
|
+
return allItems
|
|
707
|
+
} catch (e) {
|
|
708
|
+
console.error('Error within getAllReports:', e)
|
|
709
|
+
throw e // If you want to propagate the error
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
</details>
|
|
715
|
+
|
|
716
|
+
<details>
|
|
717
|
+
<summary style="font-size: 1.1rem;">Simulations (simulations.list())</summary>
|
|
718
|
+
|
|
719
|
+
```typescript
|
|
720
|
+
import { Paddle, Simulation, SimulationCollection } from '@paddle/paddle-node-sdk'
|
|
721
|
+
|
|
722
|
+
const paddle = new Paddle('API_KEY')
|
|
723
|
+
|
|
724
|
+
async function getPaginatedSimulations() {
|
|
725
|
+
try {
|
|
726
|
+
const simulationCollection: SimulationCollection = paddle.simulations.list()
|
|
727
|
+
|
|
728
|
+
const firstPage: Simulation[] = await simulationCollection.next()
|
|
729
|
+
console.log("First page of simulations:", firstPage)
|
|
730
|
+
|
|
731
|
+
if (simulationCollection.hasMore) {
|
|
732
|
+
const secondPage: Simulation[] = await simulationCollection.next()
|
|
733
|
+
console.log("Second page of simulations:", secondPage)
|
|
734
|
+
} else {
|
|
735
|
+
console.log("No more pages of simulations available after the first page.")
|
|
736
|
+
}
|
|
737
|
+
} catch (e) {
|
|
738
|
+
console.error("Error fetching paginated simulations:", e)
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
getPaginatedSimulations()
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
745
|
+
|
|
746
|
+
```typescript
|
|
747
|
+
async function getAllSimulations(): Promise<Simulation[]> {
|
|
748
|
+
const simulationCollection: SimulationCollection = paddle.simulations.list()
|
|
749
|
+
const allItems: Simulation[] = []
|
|
750
|
+
try {
|
|
751
|
+
for await (const simulation of simulationCollection) {
|
|
752
|
+
allItems.push(simulation)
|
|
753
|
+
}
|
|
754
|
+
if (allItems.length === 0) {
|
|
755
|
+
console.log('No simulations were found.')
|
|
756
|
+
}
|
|
757
|
+
return allItems
|
|
758
|
+
} catch (e) {
|
|
759
|
+
console.error('Error within getAllSimulations:', e)
|
|
760
|
+
throw e // If you want to propagate the error
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
</details>
|
|
766
|
+
|
|
767
|
+
<details>
|
|
768
|
+
<summary style="font-size: 1.1rem;">Simulation Runs (simulationRuns.list())</summary>
|
|
769
|
+
|
|
770
|
+
```typescript
|
|
771
|
+
import { Paddle, SimulationRun, SimulationRunCollection } from '@paddle/paddle-node-sdk'
|
|
772
|
+
|
|
773
|
+
const paddle = new Paddle('API_KEY')
|
|
774
|
+
|
|
775
|
+
async function getPaginatedSimulationRuns(simulationId: string) {
|
|
776
|
+
console.log(`Attempting to fetch paginated simulation runs for simulation ${simulationId}...`)
|
|
777
|
+
try {
|
|
778
|
+
// Note: simulationRuns.list() requires a simulationId
|
|
779
|
+
const simulationRunCollection: SimulationRunCollection = paddle.simulationRuns.list(simulationId)
|
|
780
|
+
|
|
781
|
+
const firstPage: SimulationRun[] = await simulationRunCollection.next()
|
|
782
|
+
console.log(`First page of simulation runs for simulation ${simulationId}:`, firstPage)
|
|
783
|
+
|
|
784
|
+
if (simulationRunCollection.hasMore) {
|
|
785
|
+
const secondPage: SimulationRun[] = await simulationRunCollection.next()
|
|
786
|
+
console.log(`Second page of simulation runs for simulation ${simulationId}:`, secondPage)
|
|
787
|
+
} else {
|
|
788
|
+
console.log(`No more pages of simulation runs available for simulation ${simulationId} after the first page.`)
|
|
789
|
+
}
|
|
790
|
+
} catch (e) {
|
|
791
|
+
console.error(`Error fetching paginated simulation runs for simulation ${simulationId}:`, e)
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
getPaginatedSimulationRuns('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk')
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
798
|
+
|
|
799
|
+
```typescript
|
|
800
|
+
async function getAllSimulationRuns(simulationId: string): Promise<SimulationRun[]> {
|
|
801
|
+
const simulationRunCollection: SimulationRunCollection = paddle.simulationRuns.list(simulationId)
|
|
802
|
+
const allItems: SimulationRun[] = []
|
|
803
|
+
try {
|
|
804
|
+
for await (const simulationRun of simulationRunCollection) {
|
|
805
|
+
allItems.push(simulationRun)
|
|
806
|
+
}
|
|
807
|
+
if (allItems.length === 0) {
|
|
808
|
+
console.log(`No simulation runs were found for simulation ${simulationId}.`)
|
|
809
|
+
}
|
|
810
|
+
return allItems
|
|
811
|
+
} catch (e) {
|
|
812
|
+
console.error(`Error within getAllSimulationRuns for simulation ${simulationId}:`, e)
|
|
813
|
+
throw e // If you want to propagate the error
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
</details>
|
|
819
|
+
|
|
820
|
+
<details>
|
|
821
|
+
<summary style="font-size: 1.1rem;">Simulation Run Events (simulationRunEvents.list())</summary>
|
|
822
|
+
|
|
823
|
+
```typescript
|
|
824
|
+
import { Paddle, SimulationRunEvent, SimulationRunEventCollection } from '@paddle/paddle-node-sdk'
|
|
825
|
+
|
|
826
|
+
const paddle = new Paddle('API_KEY')
|
|
827
|
+
|
|
828
|
+
async function getPaginatedSimulationRunEvents(simulationId: string, simulationRunId: string) {
|
|
829
|
+
try {
|
|
830
|
+
// Note: simulationRunEvents.list() requires simulationId and simulationRunId
|
|
831
|
+
const collection: SimulationRunEventCollection = paddle.simulationRunEvents.list(simulationId, simulationRunId)
|
|
832
|
+
|
|
833
|
+
const firstPage: SimulationRunEvent[] = await collection.next()
|
|
834
|
+
console.log(`First page of events for sim ${simulationId}, run ${simulationRunId}:`, firstPage)
|
|
835
|
+
|
|
836
|
+
if (collection.hasMore) {
|
|
837
|
+
const secondPage: SimulationRunEvent[] = await collection.next()
|
|
838
|
+
console.log(`Second page of events for sim ${simulationId}, run ${simulationRunId}:`, secondPage)
|
|
839
|
+
} else {
|
|
840
|
+
console.log(`No more pages of events for sim ${simulationId}, run ${simulationRunId} after the first page.`)
|
|
841
|
+
}
|
|
842
|
+
} catch (e) {
|
|
843
|
+
console.error(`Error fetching paginated events for sim ${simulationId}, run ${simulationRunId}:`, e)
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
getPaginatedSimulationRunEvents('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk', 'ntfsimrun_01ghbkd0frb9k95cnhwd1bxpvk')
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
You can optionally use these iterators with a `for await...of` loop to iterate over all items across all available pages.
|
|
850
|
+
|
|
851
|
+
```typescript
|
|
852
|
+
async function getAllSimulationRunEvents(simulationId: string, simulationRunId: string): Promise<SimulationRunEvent[]> {
|
|
853
|
+
const collection: SimulationRunEventCollection = paddle.simulationRunEvents.list(simulationId, simulationRunId)
|
|
854
|
+
const allItems: SimulationRunEvent[] = []
|
|
855
|
+
try {
|
|
856
|
+
for await (const event of collection) {
|
|
857
|
+
allItems.push(event)
|
|
858
|
+
}
|
|
859
|
+
if (allItems.length === 0) {
|
|
860
|
+
console.log(`No events found for sim ${simulationId}, run ${simulationRunId}.`)
|
|
861
|
+
}
|
|
862
|
+
return allItems
|
|
863
|
+
} catch (e) {
|
|
864
|
+
console.error(`Error within getAllSimulationRunEvents for sim ${simulationId}, run ${simulationRunId}:`, e)
|
|
865
|
+
throw e // If you want to propagate the error
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
</details>
|
|
871
|
+
|
|
872
|
+
### Create an entity
|
|
873
|
+
|
|
874
|
+
You can create a supported entity with the `create` function in the resource. It accepts the body to be created. The created entity is returned.
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
<details open>
|
|
878
|
+
<summary style="font-size: 1.1rem;">Products (products.create())</summary>
|
|
879
|
+
|
|
880
|
+
``` typescript
|
|
881
|
+
import { Paddle, CreateProductRequestBody } from '@paddle/paddle-node-sdk'
|
|
882
|
+
|
|
883
|
+
const paddle = new Paddle('API_KEY')
|
|
884
|
+
|
|
885
|
+
async function createProduct(requestBody: CreateProductRequestBody) {
|
|
886
|
+
try {
|
|
887
|
+
const product = await paddle.products.create(requestBody)
|
|
888
|
+
// Returns a product entity
|
|
889
|
+
return product
|
|
890
|
+
} catch (e) {
|
|
891
|
+
// Handle Network/API errors
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
const product = await createProduct({ name: 'ChatApp Education', taxCategory: 'standard' })
|
|
896
|
+
console.log("Product", product)
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
</details>
|
|
900
|
+
|
|
901
|
+
<details>
|
|
902
|
+
<summary style="font-size: 1.1rem;">Transactions (transactions.create())</summary>
|
|
903
|
+
|
|
904
|
+
``` typescript
|
|
905
|
+
import { Paddle, CreateTransactionRequestBody, Transaction } from '@paddle/paddle-node-sdk' // Assuming types
|
|
906
|
+
|
|
907
|
+
const paddle = new Paddle('API_KEY')
|
|
908
|
+
|
|
909
|
+
async function createTransaction(requestBody: CreateTransactionRequestBody): Promise<Transaction | undefined> { // Assuming types
|
|
910
|
+
try {
|
|
911
|
+
const transaction = await paddle.transactions.create(requestBody)
|
|
912
|
+
// Returns a transaction entity
|
|
913
|
+
return transaction
|
|
914
|
+
} catch (e) {
|
|
915
|
+
// Handle Network/API errors
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
const newTransaction = await createTransaction({
|
|
920
|
+
items: [{ priceId: 'pri_01gsz8z1q1n00f12qt82y31smh', quantity: 1 }],
|
|
921
|
+
customerId: 'ctm_01grnn4zta5a1mf02jjze7y2ys'
|
|
922
|
+
})
|
|
923
|
+
console.log("Transaction", newTransaction)
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
</details>
|
|
927
|
+
|
|
928
|
+
<details>
|
|
929
|
+
<summary style="font-size: 1.1rem;">Addresses (addresses.create())</summary>
|
|
930
|
+
|
|
931
|
+
```typescript
|
|
932
|
+
import { Paddle, CreateAddressRequestBody, Address } from '@paddle/paddle-node-sdk'
|
|
933
|
+
|
|
934
|
+
const paddle = new Paddle('API_KEY')
|
|
935
|
+
|
|
936
|
+
async function createAddress(customerId: string, requestBody: CreateAddressRequestBody): Promise<Address | undefined> {
|
|
937
|
+
try {
|
|
938
|
+
const address = await paddle.addresses.create(customerId, requestBody)
|
|
939
|
+
return address
|
|
940
|
+
// Returns an address entity
|
|
941
|
+
} catch (e) {
|
|
942
|
+
console.error('Error creating address:', e)
|
|
943
|
+
// Handle Network/API errors
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const newAddress = await createAddress('ctm_01grnn4zta5a1mf02jjze7y2ys', { countryCode: 'US', description: 'Primary Address' })
|
|
948
|
+
console.log("New Address:", newAddress)
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
</details>
|
|
952
|
+
|
|
953
|
+
<details>
|
|
954
|
+
<summary style="font-size: 1.1rem;">Adjustments (adjustments.create())</summary>
|
|
955
|
+
|
|
956
|
+
```typescript
|
|
957
|
+
import { Paddle, CreateAdjustmentRequestBody, Adjustment } from '@paddle/paddle-node-sdk'
|
|
958
|
+
|
|
959
|
+
const paddle = new Paddle('API_KEY')
|
|
960
|
+
|
|
961
|
+
async function createAdjustment(requestBody: CreateAdjustmentRequestBody): Promise<Adjustment | undefined> {
|
|
962
|
+
try {
|
|
963
|
+
const adjustment = await paddle.adjustments.create(requestBody)
|
|
964
|
+
return adjustment
|
|
965
|
+
// Returns an adjustment entity
|
|
966
|
+
} catch (e) {
|
|
967
|
+
console.error('Error creating adjustment:', e)
|
|
968
|
+
// Handle Network/API errors
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const newAdjustment = await createAdjustment({ transactionId: 'txn_01h04vsbhqc62t8hmd4z3b578c', items: [{ itemId: 'txnitm_01hvcc94b7qgz60qmrqmbm19zw', amount: '1000', type: 'partial' }], action: 'credit', reason: 'Refund for customer support' })
|
|
973
|
+
console.log("New Adjustment:", newAdjustment)
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
</details>
|
|
977
|
+
|
|
978
|
+
<details>
|
|
979
|
+
<summary style="font-size: 1.1rem;">Businesses (businesses.create())</summary>
|
|
980
|
+
|
|
981
|
+
```typescript
|
|
982
|
+
import { Paddle, CreateBusinessRequestBody, Business } from '@paddle/paddle-node-sdk'
|
|
983
|
+
|
|
984
|
+
const paddle = new Paddle('API_KEY')
|
|
985
|
+
|
|
986
|
+
async function createBusiness(customerId: string, requestBody: CreateBusinessRequestBody): Promise<Business | undefined> {
|
|
987
|
+
try {
|
|
988
|
+
const business = await paddle.businesses.create(customerId, requestBody)
|
|
989
|
+
return business
|
|
990
|
+
// Returns a business entity
|
|
991
|
+
} catch (e) {
|
|
992
|
+
console.error('Error creating business:', e)
|
|
993
|
+
// Handle Network/API errors
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const newBusiness = await createBusiness('ctm_01grnn4zta5a1mf02jjze7y2ys', { name: 'Sample Inc.', companyNumber: '12345AB' })
|
|
998
|
+
console.log("New Business:", newBusiness)
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
</details>
|
|
1002
|
+
|
|
1003
|
+
<details>
|
|
1004
|
+
<summary style="font-size: 1.1rem;">Customers (customers.create())</summary>
|
|
1005
|
+
|
|
1006
|
+
```typescript
|
|
1007
|
+
import { Paddle, CreateCustomerRequestBody, Customer } from '@paddle/paddle-node-sdk'
|
|
1008
|
+
|
|
1009
|
+
const paddle = new Paddle('API_KEY')
|
|
1010
|
+
|
|
1011
|
+
async function createCustomer(requestBody: CreateCustomerRequestBody): Promise<Customer | undefined> {
|
|
1012
|
+
try {
|
|
1013
|
+
const customer = await paddle.customers.create(requestBody)
|
|
1014
|
+
return customer
|
|
1015
|
+
// Returns a customer entity
|
|
1016
|
+
} catch (e) {
|
|
1017
|
+
console.error('Error creating customer:', e)
|
|
1018
|
+
// Handle Network/API errors
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const newCustomer = await createCustomer({ email: 'customer@example.com', name: 'John Doe' })
|
|
1023
|
+
console.log("New Customer:", newCustomer)
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
</details>
|
|
1027
|
+
|
|
1028
|
+
<details>
|
|
1029
|
+
<summary style="font-size: 1.1rem;">Customer Portal Sessions (customerPortalSessions.create())</summary>
|
|
1030
|
+
|
|
1031
|
+
```typescript
|
|
1032
|
+
import { Paddle, CustomerPortalSession } from '@paddle/paddle-node-sdk'
|
|
1033
|
+
|
|
1034
|
+
const paddle = new Paddle('API_KEY')
|
|
1035
|
+
|
|
1036
|
+
async function createCustomerPortalSession(customerId: string, subscriptionIds: string[]): Promise<CustomerPortalSession | undefined> {
|
|
1037
|
+
try {
|
|
1038
|
+
const session = await paddle.customerPortalSessions.create(customerId, subscriptionIds)
|
|
1039
|
+
return session
|
|
1040
|
+
// Returns a customer portal session entity
|
|
1041
|
+
} catch (e) {
|
|
1042
|
+
console.error('Error creating customer portal session:', e)
|
|
1043
|
+
// Handle Network/API errors
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
const newSession = await createCustomerPortalSession('ctm_01grnn4zta5a1mf02jjze7y2ys', ['sub_01h04vsc0qhwtsbsxh3422wjs4'])
|
|
1048
|
+
console.log("New Customer Portal Session:", newSession)
|
|
1049
|
+
```
|
|
1050
|
+
|
|
1051
|
+
</details>
|
|
1052
|
+
|
|
1053
|
+
<details>
|
|
1054
|
+
<summary style="font-size: 1.1rem;">Discounts (discounts.create())</summary>
|
|
1055
|
+
|
|
1056
|
+
```typescript
|
|
1057
|
+
import { Paddle, CreateDiscountRequestBody, Discount } from '@paddle/paddle-node-sdk'
|
|
1058
|
+
|
|
1059
|
+
const paddle = new Paddle('API_KEY')
|
|
1060
|
+
|
|
1061
|
+
async function createDiscount(requestBody: CreateDiscountRequestBody): Promise<Discount | undefined> {
|
|
1062
|
+
try {
|
|
1063
|
+
const discount = await paddle.discounts.create(requestBody)
|
|
1064
|
+
return discount
|
|
1065
|
+
// Returns a discount entity
|
|
1066
|
+
} catch (e) {
|
|
1067
|
+
console.error('Error creating discount:', e)
|
|
1068
|
+
// Handle Network/API errors
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
const newDiscount = await createDiscount({ amount: '1000', type: 'flat', description: '10 USD Off Coupon', currencyCode: 'USD', enabledForCheckout: true, code: 'SAVE10NOW' })
|
|
1073
|
+
console.log("New Discount:", newDiscount)
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
</details>
|
|
1077
|
+
|
|
1078
|
+
<details>
|
|
1079
|
+
<summary style="font-size: 1.1rem;">Prices (prices.create())</summary>
|
|
1080
|
+
|
|
1081
|
+
```typescript
|
|
1082
|
+
import { Paddle, CreatePriceRequestBody, Price } from '@paddle/paddle-node-sdk'
|
|
1083
|
+
|
|
1084
|
+
const paddle = new Paddle('API_KEY')
|
|
1085
|
+
|
|
1086
|
+
async function createPrice(requestBody: CreatePriceRequestBody): Promise<Price | undefined> {
|
|
1087
|
+
try {
|
|
1088
|
+
const price = await paddle.prices.create(requestBody)
|
|
1089
|
+
return price
|
|
1090
|
+
// Returns a price entity
|
|
1091
|
+
} catch (e) {
|
|
1092
|
+
console.error('Error creating price:', e)
|
|
1093
|
+
// Handle Network/API errors
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
const newPrice = await createPrice({ description: 'Premium Plan Monthly', productId: 'pro_01gsz97mq9pa4fkyy0wqenepkz', unitPrice: { amount: '2000', currencyCode: 'USD' }, billingCycle: { interval: 'month', frequency: 1 }, taxMode: 'account_setting' })
|
|
1098
|
+
console.log("New Price:", newPrice)
|
|
1099
|
+
```
|
|
1100
|
+
|
|
1101
|
+
</details>
|
|
1102
|
+
|
|
1103
|
+
<details>
|
|
1104
|
+
<summary style="font-size: 1.1rem;">Notification Settings (notificationSettings.create())</summary>
|
|
1105
|
+
|
|
1106
|
+
```typescript
|
|
1107
|
+
import { Paddle, CreateNotificationSettingsRequestBody, NotificationSettings } from '@paddle/paddle-node-sdk'
|
|
1108
|
+
|
|
1109
|
+
const paddle = new Paddle('API_KEY')
|
|
1110
|
+
|
|
1111
|
+
async function createNotificationSetting(requestBody: CreateNotificationSettingsRequestBody): Promise<NotificationSettings | undefined> {
|
|
1112
|
+
try {
|
|
1113
|
+
const notificationSetting = await paddle.notificationSettings.create(requestBody)
|
|
1114
|
+
return notificationSetting
|
|
1115
|
+
// Returns a notification setting entity
|
|
1116
|
+
} catch (e) {
|
|
1117
|
+
console.error('Error creating notification setting:', e)
|
|
1118
|
+
// Handle Network/API errors
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
const newNotificationSetting = await createNotificationSetting({ description: 'Subscription Updates Webhook', type: 'url', destination: 'https://example.com/webhook/subscription-updates', subscribedEvents: ['subscription.updated', 'subscription.activated'], includeSensitiveFields: false })
|
|
1123
|
+
console.log("New Notification Setting:", newNotificationSetting)
|
|
1124
|
+
```
|
|
1125
|
+
|
|
1126
|
+
</details>
|
|
1127
|
+
|
|
1128
|
+
<details>
|
|
1129
|
+
<summary style="font-size: 1.1rem;">Reports (reports.create())</summary>
|
|
1130
|
+
|
|
1131
|
+
```typescript
|
|
1132
|
+
import { Paddle, CreateReportRequestBody, Report } from '@paddle/paddle-node-sdk'
|
|
1133
|
+
|
|
1134
|
+
const paddle = new Paddle('API_KEY')
|
|
1135
|
+
|
|
1136
|
+
async function createReport(requestBody: CreateReportRequestBody): Promise<Report | undefined> {
|
|
1137
|
+
try {
|
|
1138
|
+
const report = await paddle.reports.create(requestBody)
|
|
1139
|
+
return report
|
|
1140
|
+
// Returns a report entity
|
|
1141
|
+
} catch (e) {
|
|
1142
|
+
console.error('Error creating report:', e)
|
|
1143
|
+
// Handle Network/API errors
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const newReport = await createReport({ type: 'transaction_line_items' }) // See ReportType for other options
|
|
1148
|
+
console.log("New Report:", newReport)
|
|
1149
|
+
```
|
|
1150
|
+
|
|
1151
|
+
</details>
|
|
1152
|
+
|
|
1153
|
+
<details>
|
|
1154
|
+
<summary style="font-size: 1.1rem;">Simulations (simulations.create())</summary>
|
|
1155
|
+
|
|
1156
|
+
```typescript
|
|
1157
|
+
import { Paddle, CreateSimulationRequestBody, Simulation } from '@paddle/paddle-node-sdk'
|
|
1158
|
+
|
|
1159
|
+
const paddle = new Paddle('API_KEY')
|
|
1160
|
+
|
|
1161
|
+
// Example 1: Creating a simulation for a single event (e.g., 'discount.created')
|
|
1162
|
+
async function createDiscountEventSimulation() {
|
|
1163
|
+
try {
|
|
1164
|
+
// Base fields required for any simulation
|
|
1165
|
+
const name = 'Simulate Discount Creation Event'
|
|
1166
|
+
const notificationSettingId = 'ntfset_01gt21c5pdx9q1e4mh1xrsjjn6'
|
|
1167
|
+
|
|
1168
|
+
const requestBody: CreateSimulationRequestBody = {
|
|
1169
|
+
name,
|
|
1170
|
+
notificationSettingId,
|
|
1171
|
+
type: 'discount.created', // See IEventName for all possible event types
|
|
1172
|
+
payload: {
|
|
1173
|
+
// These fields come from the DiscountNotification entity to provide partial data relevant to the 'discount.created' event
|
|
1174
|
+
description: 'End of Summer Sale - 10% Off',
|
|
1175
|
+
code: 'SUMMER10',
|
|
1176
|
+
type: 'percentage',
|
|
1177
|
+
amount: '10',
|
|
1178
|
+
enabledForCheckout: true,
|
|
1179
|
+
recur: false,
|
|
1180
|
+
},
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const simulation = await paddle.simulations.create(requestBody)
|
|
1184
|
+
return simulation
|
|
1185
|
+
// Returns a simulation entity
|
|
1186
|
+
} catch (e) {
|
|
1187
|
+
console.error('Error creating discount.created simulation:', e)
|
|
1188
|
+
// Handle Network/API errors
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
createDiscountEventSimulation()
|
|
1193
|
+
|
|
1194
|
+
// Example 2: Creating a simulation for a scenario (e.g., 'subscription_pause')
|
|
1195
|
+
async function createSubscriptionPauseScenarioSimulation() {
|
|
1196
|
+
try {
|
|
1197
|
+
// Base fields required for any simulation
|
|
1198
|
+
const name = 'Simulate Subscription Pause Scenario'
|
|
1199
|
+
const notificationSettingId = 'ntfset_01gt21c5pdx9q1e4mh1xrsjjn6'
|
|
1200
|
+
|
|
1201
|
+
const requestBody: CreateSimulationRequestBody = {
|
|
1202
|
+
name,
|
|
1203
|
+
notificationSettingId,
|
|
1204
|
+
type: 'subscription_pause', // See SimulationScenarioType for all possible scenario types
|
|
1205
|
+
config: {
|
|
1206
|
+
subscriptionPause: {
|
|
1207
|
+
entities: {
|
|
1208
|
+
subscriptionId: 'sub_01h04vsc0qhwtsbsxh3422wjs4'
|
|
1209
|
+
},
|
|
1210
|
+
options: {
|
|
1211
|
+
effectiveFrom: 'next_billing_period', // See EffectiveFromType for all possible options
|
|
1212
|
+
hasPastDueTransaction: false,
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
const simulation = await paddle.simulations.create(requestBody)
|
|
1219
|
+
return simulation
|
|
1220
|
+
// Returns a simulation entity
|
|
1221
|
+
} catch (e) {
|
|
1222
|
+
console.error('Error creating subscription_pause simulation:', e)
|
|
1223
|
+
// Handle Network/API errors
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
createSubscriptionPauseScenarioSimulation()
|
|
1228
|
+
```
|
|
1229
|
+
|
|
1230
|
+
</details>
|
|
1231
|
+
|
|
1232
|
+
<details>
|
|
1233
|
+
<summary style="font-size: 1.1rem;">Simulation Runs (simulationRuns.create())</summary>
|
|
1234
|
+
|
|
1235
|
+
```typescript
|
|
1236
|
+
import { Paddle, SimulationRun } from '@paddle/paddle-node-sdk' // No specific CreateRequestBody for this simple case
|
|
1237
|
+
|
|
1238
|
+
const paddle = new Paddle('API_KEY')
|
|
1239
|
+
|
|
1240
|
+
async function createSimulationRun(simulationId: string): Promise<SimulationRun | undefined> {
|
|
1241
|
+
try {
|
|
1242
|
+
const simulationRun = await paddle.simulationRuns.create(simulationId)
|
|
1243
|
+
return simulationRun
|
|
1244
|
+
// Returns a simulation run entity
|
|
1245
|
+
} catch (e) {
|
|
1246
|
+
console.error('Error creating simulation run:', e)
|
|
1247
|
+
// Handle Network/API errors
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
const newSimulationRun = await createSimulationRun('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk')
|
|
1252
|
+
console.log("New Simulation Run:", newSimulationRun)
|
|
1253
|
+
```
|
|
1254
|
+
|
|
1255
|
+
</details>
|
|
1256
|
+
|
|
1257
|
+
### Update an entity
|
|
1258
|
+
You can update a supported entity with the `update` function in the resource. It accepts the `id` of the entity to update and an object with the attributes to be updated. The updated entity is returned.
|
|
1259
|
+
|
|
1260
|
+
Where operations require more than one `id`, like for addresses and businesses, the `update` function accepts multiple arguments. For example, to update an address for a customer, pass the `customerId` and the `addressId`.
|
|
1261
|
+
|
|
1262
|
+
<details open>
|
|
1263
|
+
<summary style="font-size: 1.1rem;">Products (products.update())</summary>
|
|
1264
|
+
|
|
1265
|
+
``` typescript
|
|
1266
|
+
import { Paddle, UpdateProductRequestBody } from '@paddle/paddle-node-sdk'
|
|
1267
|
+
|
|
1268
|
+
const paddle = new Paddle('API_KEY')
|
|
1269
|
+
|
|
1270
|
+
async function updateProduct(productId: string, requestBody: UpdateProductRequestBody) {
|
|
1271
|
+
try {
|
|
1272
|
+
// Pass the product id and request body with the attributes to update
|
|
1273
|
+
const product = await paddle.products.update(productId, requestBody)
|
|
1274
|
+
// Returns an updated product entity
|
|
1275
|
+
return product
|
|
1276
|
+
} catch (e) {
|
|
1277
|
+
// Handle Network/API errors
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
const product = await updateProduct('pro_01gsz97mq9pa4fkyy0wqenepkz', { name: 'ChatApp for Schools' })
|
|
1282
|
+
console.log('Updated product', product)
|
|
1283
|
+
```
|
|
1284
|
+
|
|
1285
|
+
</details>
|
|
1286
|
+
|
|
1287
|
+
<details>
|
|
1288
|
+
<summary style="font-size: 1.1rem;">Subscriptions (subscriptions.update())</summary>
|
|
1289
|
+
|
|
1290
|
+
``` typescript
|
|
1291
|
+
import { Paddle, UpdateSubscriptionRequestBody, Subscription } from '@paddle/paddle-node-sdk' // Assuming types
|
|
1292
|
+
|
|
1293
|
+
const paddle = new Paddle('API_KEY')
|
|
1294
|
+
|
|
1295
|
+
async function updateSubscription(subscriptionId: string, requestBody: UpdateSubscriptionRequestBody): Promise<Subscription | undefined> { // Assuming types
|
|
1296
|
+
try {
|
|
1297
|
+
// Pass the subscription id and request body with the attributes to update
|
|
1298
|
+
const subscription = await paddle.subscriptions.update(subscriptionId, requestBody)
|
|
1299
|
+
// Returns an updated subscription entity
|
|
1300
|
+
return subscription
|
|
1301
|
+
} catch (e) {
|
|
1302
|
+
// Handle Network/API errors
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
const updatedSubscription = await updateSubscription('sub_01h04vsc0qhwtsbsxh3422wjs4', { collectionMode: 'manual' })
|
|
1307
|
+
console.log('Updated subscription', updatedSubscription)
|
|
1308
|
+
```
|
|
1309
|
+
|
|
1310
|
+
</details>
|
|
1311
|
+
|
|
1312
|
+
<details>
|
|
1313
|
+
<summary style="font-size: 1.1rem;">Transactions (transactions.update())</summary>
|
|
1314
|
+
|
|
1315
|
+
(Note: Transaction updates might be limited to specific fields like customData or specific actions not covered by a generic update).
|
|
1316
|
+
|
|
1317
|
+
``` typescript
|
|
1318
|
+
import { Paddle, UpdateTransactionRequestBody, Transaction } from '@paddle/paddle-node-sdk' // Assuming types
|
|
1319
|
+
|
|
1320
|
+
const paddle = new Paddle('API_KEY')
|
|
1321
|
+
|
|
1322
|
+
async function updateTransaction(transactionId: string, requestBody: UpdateTransactionRequestBody): Promise<Transaction | undefined> { // Assuming types
|
|
1323
|
+
try {
|
|
1324
|
+
// Pass the transaction id and request body with the attributes to update
|
|
1325
|
+
const transaction = await paddle.transactions.update(transactionId, requestBody)
|
|
1326
|
+
// Returns an updated transaction entity
|
|
1327
|
+
return transaction
|
|
1328
|
+
} catch (e) {
|
|
1329
|
+
// Handle Network/API errors
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
const updatedTransaction = await updateTransaction('txn_01h04vsbhqc62t8hmd4z3b578c', { customData: { internal_reference: 'ref_abc123' } })
|
|
1334
|
+
console.log('Updated transaction', updatedTransaction)
|
|
1335
|
+
```
|
|
1336
|
+
|
|
1337
|
+
</details>
|
|
1338
|
+
|
|
1339
|
+
<details>
|
|
1340
|
+
<summary style="font-size: 1.1rem;">Addresses (addresses.update())</summary>
|
|
1341
|
+
|
|
1342
|
+
```typescript
|
|
1343
|
+
import { Paddle, UpdateAddressRequestBody, Address } from '@paddle/paddle-node-sdk' // Assuming types
|
|
1344
|
+
|
|
1345
|
+
const paddle = new Paddle('API_KEY')
|
|
1346
|
+
|
|
1347
|
+
async function updateAddress(customerId: string, addressId: string, requestBody: UpdateAddressRequestBody): Promise<Address | undefined> { // Assuming types
|
|
1348
|
+
try {
|
|
1349
|
+
// Pass the customer id, address id and request body with the attributes to update
|
|
1350
|
+
const address = await paddle.addresses.update(customerId, addressId, requestBody)
|
|
1351
|
+
// Returns an updated address entity
|
|
1352
|
+
return address
|
|
1353
|
+
} catch (e) {
|
|
1354
|
+
// Handle Network/API errors
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
```
|
|
1358
|
+
|
|
1359
|
+
</details>
|
|
1360
|
+
|
|
1361
|
+
<details>
|
|
1362
|
+
<summary style="font-size: 1.1rem;">Businesses (businesses.update())</summary>
|
|
1363
|
+
|
|
1364
|
+
```typescript
|
|
1365
|
+
import { Paddle, UpdateBusinessRequestBody, Business } from '@paddle/paddle-node-sdk'
|
|
1366
|
+
|
|
1367
|
+
const paddle = new Paddle('API_KEY')
|
|
1368
|
+
|
|
1369
|
+
async function updateBusiness(customerId: string, businessId: string, requestBody: UpdateBusinessRequestBody): Promise<Business | undefined> {
|
|
1370
|
+
try {
|
|
1371
|
+
// Pass the customer id, business id and request body with the attributes to update
|
|
1372
|
+
const business = await paddle.businesses.update(customerId, businessId, requestBody)
|
|
1373
|
+
// Returns an updated business entity
|
|
1374
|
+
return business
|
|
1375
|
+
} catch (e) {
|
|
1376
|
+
console.error(`Error updating business ${businessId} for customer ${customerId}:`, e)
|
|
1377
|
+
// Handle Network/API errors
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
const updatedBusiness = await updateBusiness('ctm_01grnn4zta5a1mf02jjze7y2ys', 'biz_01grrebrzaee2qj2fqqhmcyzaj', { name: 'Sample Corp Updated', contacts: [{name: 'Jane Doe', email: 'jane.doe@example.com'}] })
|
|
1382
|
+
console.log('Updated Business:', updatedBusiness)
|
|
1383
|
+
```
|
|
1384
|
+
|
|
1385
|
+
</details>
|
|
1386
|
+
|
|
1387
|
+
<details>
|
|
1388
|
+
<summary style="font-size: 1.1rem;">Customers (customers.update())</summary>
|
|
1389
|
+
|
|
1390
|
+
```typescript
|
|
1391
|
+
import { Paddle, UpdateCustomerRequestBody, Customer } from '@paddle/paddle-node-sdk'
|
|
1392
|
+
|
|
1393
|
+
const paddle = new Paddle('API_KEY')
|
|
1394
|
+
|
|
1395
|
+
async function updateCustomer(customerId: string, requestBody: UpdateCustomerRequestBody): Promise<Customer | undefined> {
|
|
1396
|
+
try {
|
|
1397
|
+
// Pass the customer id and request body with the attributes to update
|
|
1398
|
+
const customer = await paddle.customers.update(customerId, requestBody)
|
|
1399
|
+
// Returns an updated customer entity
|
|
1400
|
+
return customer
|
|
1401
|
+
} catch (e) {
|
|
1402
|
+
console.error(`Error updating customer ${customerId}:`, e)
|
|
1403
|
+
// Handle Network/API errors
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
const updatedCustomer = await updateCustomer('ctm_01grnn4zta5a1mf02jjze7y2ys', { email: 'john.doe.updated@example.com', name: 'Johnathan Doe' })
|
|
1408
|
+
console.log('Updated Customer:', updatedCustomer)
|
|
1409
|
+
```
|
|
1410
|
+
|
|
1411
|
+
</details>
|
|
1412
|
+
|
|
1413
|
+
<details>
|
|
1414
|
+
<summary style="font-size: 1.1rem;">Discounts (discounts.update())</summary>
|
|
1415
|
+
|
|
1416
|
+
```typescript
|
|
1417
|
+
import { Paddle, UpdateDiscountRequestBody, Discount } from '@paddle/paddle-node-sdk'
|
|
1418
|
+
|
|
1419
|
+
const paddle = new Paddle('API_KEY')
|
|
1420
|
+
|
|
1421
|
+
async function updateDiscount(discountId: string, requestBody: UpdateDiscountRequestBody): Promise<Discount | undefined> {
|
|
1422
|
+
try {
|
|
1423
|
+
// Pass the discount id and request body with the attributes to update
|
|
1424
|
+
const discount = await paddle.discounts.update(discountId, requestBody)
|
|
1425
|
+
// Returns an updated discount entity
|
|
1426
|
+
return discount
|
|
1427
|
+
} catch (e) {
|
|
1428
|
+
console.error(`Error updating discount ${discountId}:`, e)
|
|
1429
|
+
// Handle Network/API errors
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
const updatedDiscount = await updateDiscount('dsc_01gv5kpg05xp104ek2fmgjwttf', { description: '15 USD Off Coupon - Extended', amount: '1500' })
|
|
1434
|
+
console.log('Updated Discount:', updatedDiscount)
|
|
1435
|
+
```
|
|
1436
|
+
|
|
1437
|
+
</details>
|
|
1438
|
+
|
|
1439
|
+
<details>
|
|
1440
|
+
<summary style="font-size: 1.1rem;">Prices (prices.update())</summary>
|
|
1441
|
+
|
|
1442
|
+
```typescript
|
|
1443
|
+
import { Paddle, UpdatePriceRequestBody, Price } from '@paddle/paddle-node-sdk'
|
|
1444
|
+
|
|
1445
|
+
const paddle = new Paddle('API_KEY')
|
|
1446
|
+
|
|
1447
|
+
async function updatePrice(priceId: string, requestBody: UpdatePriceRequestBody): Promise<Price | undefined> {
|
|
1448
|
+
try {
|
|
1449
|
+
// Pass the price id and request body with the attributes to update
|
|
1450
|
+
const price = await paddle.prices.update(priceId, requestBody)
|
|
1451
|
+
// Returns an updated price entity
|
|
1452
|
+
return price
|
|
1453
|
+
} catch (e) {
|
|
1454
|
+
console.error(`Error updating price ${priceId}:`, e)
|
|
1455
|
+
// Handle Network/API errors
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
const updatedPrice = await updatePrice('pri_01gsz8z1q1n00f12qt82y31smh', { description: 'Premium Plan Monthly (New Name)', unitPrice: { amount: '2200', currencyCode: 'USD' } })
|
|
1460
|
+
console.log('Updated Price:', updatedPrice)
|
|
1461
|
+
```
|
|
1462
|
+
|
|
1463
|
+
</details>
|
|
1464
|
+
|
|
1465
|
+
<details>
|
|
1466
|
+
<summary style="font-size: 1.1rem;">Notification Settings (notificationSettings.update())</summary>
|
|
1467
|
+
|
|
1468
|
+
```typescript
|
|
1469
|
+
import { Paddle, UpdateNotificationSettingsRequestBody, NotificationSettings } from '@paddle/paddle-node-sdk'
|
|
1470
|
+
|
|
1471
|
+
const paddle = new Paddle('API_KEY')
|
|
1472
|
+
|
|
1473
|
+
async function updateNotificationSetting(notificationSettingId: string, requestBody: UpdateNotificationSettingsRequestBody): Promise<NotificationSettings | undefined> {
|
|
1474
|
+
try {
|
|
1475
|
+
// Pass the notification setting id and request body with the attributes to update
|
|
1476
|
+
const notificationSetting = await paddle.notificationSettings.update(notificationSettingId, requestBody)
|
|
1477
|
+
// Returns an updated notification setting entity
|
|
1478
|
+
return notificationSetting
|
|
1479
|
+
} catch (e) {
|
|
1480
|
+
console.error(`Error updating notification setting ${notificationSettingId}:`, e)
|
|
1481
|
+
// Handle Network/API errors
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
const updatedNs = await updateNotificationSetting('ntfset_01gt21c5pdx9q1e4mh1xrsjjn6', { destination: 'https://example.com/webhook/updated-endpoint', subscribedEvents: ['transaction.completed', 'subscription.canceled'] })
|
|
1486
|
+
console.log('Updated Notification Setting:', updatedNs)
|
|
1487
|
+
```
|
|
1488
|
+
|
|
1489
|
+
</details>
|
|
1490
|
+
|
|
1491
|
+
<details>
|
|
1492
|
+
<summary style="font-size: 1.1rem;">Simulations (simulations.update())</summary>
|
|
1493
|
+
|
|
1494
|
+
```typescript
|
|
1495
|
+
import { Paddle, UpdateSimulationRequestBody, Simulation } from '@paddle/paddle-node-sdk'
|
|
1496
|
+
|
|
1497
|
+
const paddle = new Paddle('API_KEY')
|
|
1498
|
+
|
|
1499
|
+
async function updateSimulation(simulationId: string, requestBody: UpdateSimulationRequestBody): Promise<Simulation | undefined> {
|
|
1500
|
+
try {
|
|
1501
|
+
// Pass the simulation id and request body with the attributes to update
|
|
1502
|
+
const simulation = await paddle.simulations.update(simulationId, requestBody)
|
|
1503
|
+
// Returns an updated simulation entity
|
|
1504
|
+
return simulation
|
|
1505
|
+
} catch (e) {
|
|
1506
|
+
console.error(`Error updating simulation ${simulationId}:`, e)
|
|
1507
|
+
// Handle Network/API errors
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// Example: Updating the payload of a single event simulation
|
|
1512
|
+
const updatedEventSimulation = await updateSimulation('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk', { payload: { code: 'NEWDISCOUNTCODE' } })
|
|
1513
|
+
console.log('Updated Event Simulation:', updatedEventSimulation)
|
|
1514
|
+
|
|
1515
|
+
// Example: Updating the config of a scenario simulation
|
|
1516
|
+
const updatedScenarioSimulation = await updateSimulation('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk', { config: { subscriptionPause: { options: { effectiveFrom: 'immediately' } } } })
|
|
1517
|
+
console.log('Updated Scenario Simulation:', updatedScenarioSimulation)
|
|
1518
|
+
```
|
|
1519
|
+
|
|
1520
|
+
</details>
|
|
1521
|
+
|
|
1522
|
+
### Get an entity
|
|
1523
|
+
|
|
1524
|
+
You can get an entity with the `get` function in the resource. It accepts the `id` of the entity to get. The entity is returned.
|
|
1525
|
+
|
|
1526
|
+
Where operations require more than one `id`, like for addresses and businesses, the `get` function accepts multiple arguments. For example, to get an address for a customer, pass the `customerId` and the `addressId`.
|
|
1527
|
+
|
|
1528
|
+
<details open>
|
|
1529
|
+
<summary style="font-size: 1.1rem;">Products (products.get())</summary>
|
|
1530
|
+
|
|
1531
|
+
``` typescript
|
|
1532
|
+
import { Paddle, Product, GetProductQueryParameters } from '@paddle/paddle-node-sdk'
|
|
1533
|
+
|
|
1534
|
+
const paddle = new Paddle('API_KEY')
|
|
1535
|
+
|
|
1536
|
+
async function getProduct(productId: string, queryParams?: GetProductQueryParameters): Promise<Product | undefined> {
|
|
1537
|
+
try {
|
|
1538
|
+
// Pass the product id get
|
|
1539
|
+
const product = await paddle.products.get(productId, queryParams)
|
|
1540
|
+
// Returns a product entity
|
|
1541
|
+
return product
|
|
1542
|
+
} catch (e) {
|
|
1543
|
+
// Handle Network/API errors
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
// Optionally include additional data in the returned object
|
|
1548
|
+
// See GetProductQueryParameters for more in which data you can include
|
|
1549
|
+
const queryParams: GetProductQueryParameters = { include: ['prices'] }
|
|
1550
|
+
|
|
1551
|
+
const product = await getProduct('pro_01gsz97mq9pa4fkyy0wqenepkz', queryParams)
|
|
1552
|
+
console.log('Product', product)
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
</details>
|
|
1556
|
+
|
|
1557
|
+
<details>
|
|
1558
|
+
<summary style="font-size: 1.1rem;">Subscriptions (subscriptions.get())</summary>
|
|
85
1559
|
|
|
86
1560
|
``` typescript
|
|
87
|
-
import { Paddle } from '@paddle/paddle-node-sdk'
|
|
1561
|
+
import { Paddle, Subscription, GetSubscriptionQueryParameters } from '@paddle/paddle-node-sdk'
|
|
88
1562
|
|
|
89
1563
|
const paddle = new Paddle('API_KEY')
|
|
90
1564
|
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1565
|
+
async function getSubscription(subscriptionId: string, queryParams?: GetSubscriptionQueryParameters): Promise<Subscription | undefined> {
|
|
1566
|
+
try {
|
|
1567
|
+
// Pass the subscription id to get
|
|
1568
|
+
const subscription = await paddle.subscriptions.get(subscriptionId, queryParams)
|
|
1569
|
+
// Returns a subscription entity
|
|
1570
|
+
return subscription
|
|
1571
|
+
} catch (e) {
|
|
1572
|
+
// Handle Network/API errors
|
|
1573
|
+
}
|
|
95
1574
|
}
|
|
96
1575
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const firstPage = await productCollection.next()
|
|
104
|
-
console.log("First page data", firstPage)
|
|
105
|
-
|
|
106
|
-
// Calling `next()` again will retrieve subsequent pages.
|
|
107
|
-
const secondPage = await productCollection.next()
|
|
108
|
-
console.log("Second page data", secondPage)
|
|
109
|
-
} catch (e) {
|
|
110
|
-
// Handle Network/API errors
|
|
111
|
-
}
|
|
1576
|
+
// Optionally include additional data in the returned object
|
|
1577
|
+
// See GetSubscriptionQueryParameters for more in which data you can include
|
|
1578
|
+
const queryParams: GetSubscriptionQueryParameters = { include: ['next_transaction', 'recurring_transaction_details'] }
|
|
1579
|
+
|
|
1580
|
+
const subscription = await getSubscription('sub_01h04vsc0qhwtsbsxh3422wjs4', queryParams)
|
|
1581
|
+
console.log('Subscription', subscription)
|
|
112
1582
|
```
|
|
113
1583
|
|
|
114
|
-
|
|
1584
|
+
</details>
|
|
115
1585
|
|
|
116
|
-
|
|
1586
|
+
<details>
|
|
1587
|
+
<summary style="font-size: 1.1rem;">Transactions (transactions.get())</summary>
|
|
117
1588
|
|
|
118
1589
|
``` typescript
|
|
119
|
-
import { Paddle,
|
|
1590
|
+
import { Paddle, Transaction, GetTransactionQueryParameters } from '@paddle/paddle-node-sdk'
|
|
120
1591
|
|
|
121
1592
|
const paddle = new Paddle('API_KEY')
|
|
122
1593
|
|
|
123
|
-
async function
|
|
1594
|
+
async function getTransaction(transactionId: string, queryParams?: GetTransactionQueryParameters): Promise<Transaction | undefined> {
|
|
124
1595
|
try {
|
|
125
|
-
// Pass the
|
|
126
|
-
const
|
|
127
|
-
// Returns a
|
|
128
|
-
return
|
|
1596
|
+
// Pass the transaction id to get
|
|
1597
|
+
const transaction = await paddle.transactions.get(transactionId, queryParams)
|
|
1598
|
+
// Returns a transaction entity
|
|
1599
|
+
return transaction
|
|
129
1600
|
} catch (e) {
|
|
130
1601
|
// Handle Network/API errors
|
|
131
1602
|
}
|
|
132
1603
|
}
|
|
133
1604
|
|
|
134
|
-
|
|
135
|
-
|
|
1605
|
+
// Optionally include additional data in the returned object
|
|
1606
|
+
// See GetTransactionQueryParameters for more in which data you can include
|
|
1607
|
+
const queryParams: GetTransactionQueryParameters = { include: ['customer', 'discount'] }
|
|
1608
|
+
|
|
1609
|
+
const transaction = await getTransaction('txn_01h04vsbhqc62t8hmd4z3b578c', queryParams)
|
|
1610
|
+
console.log('Transaction', transaction)
|
|
136
1611
|
```
|
|
137
1612
|
|
|
138
|
-
|
|
1613
|
+
</details>
|
|
139
1614
|
|
|
140
|
-
|
|
1615
|
+
<details>
|
|
1616
|
+
<summary style="font-size: 1.1rem;">Addresses (addresses.get())</summary>
|
|
141
1617
|
|
|
142
|
-
```
|
|
143
|
-
import { Paddle,
|
|
1618
|
+
```typescript
|
|
1619
|
+
import { Paddle, Address } from '@paddle/paddle-node-sdk'
|
|
144
1620
|
|
|
145
1621
|
const paddle = new Paddle('API_KEY')
|
|
146
1622
|
|
|
147
|
-
async function
|
|
1623
|
+
async function getAddress(customerId: string, addressId: string): Promise<Address | undefined> {
|
|
148
1624
|
try {
|
|
149
|
-
// Pass the
|
|
150
|
-
const
|
|
151
|
-
// Returns an
|
|
152
|
-
return
|
|
1625
|
+
// Pass the customer_id and address_id to get
|
|
1626
|
+
const address = await paddle.addresses.get(customerId, addressId)
|
|
1627
|
+
// Returns an address entity
|
|
1628
|
+
return address
|
|
153
1629
|
} catch (e) {
|
|
154
1630
|
// Handle Network/API errors
|
|
1631
|
+
console.error(`Error fetching address ${addressId} for customer ${customerId}:`, e)
|
|
155
1632
|
}
|
|
156
1633
|
}
|
|
157
1634
|
|
|
158
|
-
const
|
|
159
|
-
console.log('
|
|
1635
|
+
const address = await getAddress('ctm_01grnn4zta5a1mf02jjze7y2ys', 'add_01gm302t81w94gyjpjpqypkzkf')
|
|
1636
|
+
console.log('Address:', address)
|
|
1637
|
+
```
|
|
1638
|
+
|
|
1639
|
+
</details>
|
|
1640
|
+
|
|
1641
|
+
<details>
|
|
1642
|
+
<summary style="font-size: 1.1rem;">Businesses (businesses.get())</summary>
|
|
1643
|
+
|
|
1644
|
+
```typescript
|
|
1645
|
+
import { Paddle, Business } from '@paddle/paddle-node-sdk'
|
|
1646
|
+
|
|
1647
|
+
const paddle = new Paddle('API_KEY')
|
|
1648
|
+
|
|
1649
|
+
async function getBusiness(customerId: string, businessId: string): Promise<Business | undefined> {
|
|
1650
|
+
try {
|
|
1651
|
+
// Pass the customer_id and business_id to get
|
|
1652
|
+
const business = await paddle.businesses.get(customerId, businessId)
|
|
1653
|
+
// Returns a business entity
|
|
1654
|
+
return business
|
|
1655
|
+
} catch (e) {
|
|
1656
|
+
// Handle Network/API errors
|
|
1657
|
+
console.error(`Error fetching business ${businessId} for customer ${customerId}:`, e)
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
const business = await getBusiness('ctm_01grnn4zta5a1mf02jjze7y2ys', 'biz_01grrebrzaee2qj2fqqhmcyzaj')
|
|
1662
|
+
console.log('Business:', business)
|
|
160
1663
|
```
|
|
161
1664
|
|
|
162
|
-
|
|
1665
|
+
</details>
|
|
1666
|
+
|
|
1667
|
+
<details>
|
|
1668
|
+
<summary style="font-size: 1.1rem;">Customers (customers.get())</summary>
|
|
163
1669
|
|
|
164
1670
|
```typescript
|
|
165
|
-
|
|
1671
|
+
import { Paddle, Customer } from '@paddle/paddle-node-sdk'
|
|
1672
|
+
|
|
1673
|
+
const paddle = new Paddle('API_KEY')
|
|
1674
|
+
|
|
1675
|
+
async function getCustomer(customerId: string): Promise<Customer | undefined> {
|
|
1676
|
+
try {
|
|
1677
|
+
// Pass the customer_id to get
|
|
1678
|
+
const customer = await paddle.customers.get(customerId)
|
|
1679
|
+
// Returns a customer entity
|
|
1680
|
+
return customer
|
|
1681
|
+
} catch (e) {
|
|
1682
|
+
// Handle Network/API errors
|
|
1683
|
+
console.error(`Error fetching customer ${customerId}:`, e)
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
const customer = await getCustomer('ctm_01grnn4zta5a1mf02jjze7y2ys')
|
|
1688
|
+
console.log('Customer:', customer)
|
|
166
1689
|
```
|
|
167
1690
|
|
|
168
|
-
|
|
1691
|
+
</details>
|
|
169
1692
|
|
|
170
|
-
|
|
1693
|
+
<details>
|
|
1694
|
+
<summary style="font-size: 1.1rem;">Discounts (discounts.get())</summary>
|
|
171
1695
|
|
|
172
|
-
```
|
|
173
|
-
import { Paddle } from '@paddle/paddle-node-sdk'
|
|
1696
|
+
```typescript
|
|
1697
|
+
import { Paddle, Discount } from '@paddle/paddle-node-sdk'
|
|
174
1698
|
|
|
175
1699
|
const paddle = new Paddle('API_KEY')
|
|
176
1700
|
|
|
177
|
-
async function
|
|
1701
|
+
async function getDiscount(discountId: string): Promise<Discount | undefined> {
|
|
178
1702
|
try {
|
|
179
|
-
// Pass the
|
|
180
|
-
const
|
|
181
|
-
// Returns a
|
|
182
|
-
return
|
|
1703
|
+
// Pass the discount_id to get
|
|
1704
|
+
const discount = await paddle.discounts.get(discountId)
|
|
1705
|
+
// Returns a discount entity
|
|
1706
|
+
return discount
|
|
183
1707
|
} catch (e) {
|
|
184
1708
|
// Handle Network/API errors
|
|
1709
|
+
console.error(`Error fetching discount ${discountId}:`, e)
|
|
185
1710
|
}
|
|
186
1711
|
}
|
|
187
1712
|
|
|
188
|
-
const
|
|
189
|
-
console.log('
|
|
1713
|
+
const discount = await getDiscount('dsc_01gv5kpg05xp104ek2fmgjwttf')
|
|
1714
|
+
console.log('Discount:', discount)
|
|
1715
|
+
```
|
|
1716
|
+
|
|
1717
|
+
</details>
|
|
1718
|
+
|
|
1719
|
+
<details>
|
|
1720
|
+
<summary style="font-size: 1.1rem;">Prices (prices.get())</summary>
|
|
1721
|
+
|
|
1722
|
+
```typescript
|
|
1723
|
+
import { Paddle, Price, GetPriceQueryParameters } from '@paddle/paddle-node-sdk'
|
|
1724
|
+
|
|
1725
|
+
const paddle = new Paddle('API_KEY')
|
|
1726
|
+
|
|
1727
|
+
async function getPrice(priceId: string, queryParams?: GetPriceQueryParameters): Promise<Price | undefined> {
|
|
1728
|
+
try {
|
|
1729
|
+
// Pass the price_id to get
|
|
1730
|
+
const price = await paddle.prices.get(priceId, queryParams)
|
|
1731
|
+
// Returns a price entity
|
|
1732
|
+
return price
|
|
1733
|
+
} catch (e) {
|
|
1734
|
+
// Handle Network/API errors
|
|
1735
|
+
console.error(`Error fetching price ${priceId}:`, e)
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
// Optionally include additional data in the returned object
|
|
1740
|
+
// See GetPriceQueryParameters for more in which data you can include
|
|
1741
|
+
const queryParams: GetPriceQueryParameters = { include: ['product'] }
|
|
1742
|
+
|
|
1743
|
+
const price = await getPrice('pri_01gsz8z1q1n00f12qt82y31smh', queryParams)
|
|
1744
|
+
console.log('Price:', price)
|
|
1745
|
+
```
|
|
1746
|
+
|
|
1747
|
+
</details>
|
|
1748
|
+
|
|
1749
|
+
<details>
|
|
1750
|
+
<summary style="font-size: 1.1rem;">Payment Methods (paymentMethods.get())</summary>
|
|
1751
|
+
|
|
1752
|
+
```typescript
|
|
1753
|
+
import { Paddle, PaymentMethod } from '@paddle/paddle-node-sdk'
|
|
1754
|
+
|
|
1755
|
+
const paddle = new Paddle('API_KEY')
|
|
1756
|
+
|
|
1757
|
+
async function getPaymentMethod(customerId: string, paymentMethodId: string): Promise<PaymentMethod | undefined> {
|
|
1758
|
+
try {
|
|
1759
|
+
// Pass the customer_id and payment_method_id to get
|
|
1760
|
+
const paymentMethod = await paddle.paymentMethods.get(customerId, paymentMethodId)
|
|
1761
|
+
// Returns a payment method entity
|
|
1762
|
+
return paymentMethod
|
|
1763
|
+
} catch (e) {
|
|
1764
|
+
// Handle Network/API errors
|
|
1765
|
+
console.error(`Error fetching payment method ${paymentMethodId} for customer ${customerId}:`, e)
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
const paymentMethod = await getPaymentMethod('ctm_01grnn4zta5a1mf02jjze7y2ys', 'paymtd_01hkm9xwqpbbpr1ksmvg3sx3v1')
|
|
1770
|
+
console.log('Payment Method:', paymentMethod)
|
|
1771
|
+
```
|
|
1772
|
+
|
|
1773
|
+
</details>
|
|
1774
|
+
|
|
1775
|
+
<details>
|
|
1776
|
+
<summary style="font-size: 1.1rem;">Notification Settings (notificationSettings.get())</summary>
|
|
1777
|
+
|
|
1778
|
+
```typescript
|
|
1779
|
+
import { Paddle, NotificationSettings } from '@paddle/paddle-node-sdk'
|
|
1780
|
+
|
|
1781
|
+
const paddle = new Paddle('API_KEY')
|
|
1782
|
+
|
|
1783
|
+
async function getNotificationSetting(notificationSettingId: string): Promise<NotificationSettings | undefined> {
|
|
1784
|
+
try {
|
|
1785
|
+
// Pass the notification_setting_id (referred to as notificationId in the SDK method) to get
|
|
1786
|
+
const notificationSetting = await paddle.notificationSettings.get(notificationSettingId)
|
|
1787
|
+
// Returns a notification setting entity
|
|
1788
|
+
return notificationSetting
|
|
1789
|
+
} catch (e) {
|
|
1790
|
+
// Handle Network/API errors
|
|
1791
|
+
console.error(`Error fetching notification setting ${notificationSettingId}:`, e)
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
const notificationSetting = await getNotificationSetting('ntfset_01gt21c5pdx9q1e4mh1xrsjjn6')
|
|
1796
|
+
console.log('Notification Setting:', notificationSetting)
|
|
1797
|
+
```
|
|
1798
|
+
|
|
1799
|
+
</details>
|
|
1800
|
+
|
|
1801
|
+
<details>
|
|
1802
|
+
<summary style="font-size: 1.1rem;">Notifications (notifications.get())</summary>
|
|
1803
|
+
|
|
1804
|
+
```typescript
|
|
1805
|
+
import { Paddle, Notification } from '@paddle/paddle-node-sdk'
|
|
1806
|
+
|
|
1807
|
+
const paddle = new Paddle('API_KEY')
|
|
1808
|
+
|
|
1809
|
+
async function getNotification(notificationId: string): Promise<Notification | undefined> {
|
|
1810
|
+
try {
|
|
1811
|
+
// Pass the notification_id to get
|
|
1812
|
+
const notification = await paddle.notifications.get(notificationId)
|
|
1813
|
+
// Returns a notification entity
|
|
1814
|
+
return notification
|
|
1815
|
+
} catch (e) {
|
|
1816
|
+
// Handle Network/API errors
|
|
1817
|
+
console.error(`Error fetching notification ${notificationId}:`, e)
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
const notification = await getNotification('ntf_01ghbkd0frb9k95cnhwd1bxpvk')
|
|
1822
|
+
console.log('Notification:', notification)
|
|
1823
|
+
```
|
|
1824
|
+
|
|
1825
|
+
</details>
|
|
1826
|
+
|
|
1827
|
+
<details>
|
|
1828
|
+
<summary style="font-size: 1.1rem;">Reports (reports.get())</summary>
|
|
1829
|
+
|
|
1830
|
+
```typescript
|
|
1831
|
+
import { Paddle, Report } from '@paddle/paddle-node-sdk'
|
|
1832
|
+
|
|
1833
|
+
const paddle = new Paddle('API_KEY')
|
|
1834
|
+
|
|
1835
|
+
async function getReport(reportId: string): Promise<Report | undefined> {
|
|
1836
|
+
try {
|
|
1837
|
+
// Pass the report_id to get
|
|
1838
|
+
const report = await paddle.reports.get(reportId)
|
|
1839
|
+
// Returns a report entity
|
|
1840
|
+
return report
|
|
1841
|
+
} catch (e) {
|
|
1842
|
+
// Handle Network/API errors
|
|
1843
|
+
console.error(`Error fetching report ${reportId}:`, e)
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
const report = await getReport('rep_01h9apkx1d320kpvvfyezr96k0')
|
|
1848
|
+
console.log('Report:', report)
|
|
1849
|
+
```
|
|
1850
|
+
|
|
1851
|
+
</details>
|
|
1852
|
+
|
|
1853
|
+
<details>
|
|
1854
|
+
<summary style="font-size: 1.1rem;">Simulations (simulations.get())</summary>
|
|
1855
|
+
|
|
1856
|
+
```typescript
|
|
1857
|
+
import { Paddle, Simulation } from '@paddle/paddle-node-sdk'
|
|
1858
|
+
|
|
1859
|
+
const paddle = new Paddle('API_KEY')
|
|
1860
|
+
|
|
1861
|
+
async function getSimulation(simulationId: string): Promise<Simulation | undefined> {
|
|
1862
|
+
try {
|
|
1863
|
+
// Pass the simulation_id to get
|
|
1864
|
+
const simulation = await paddle.simulations.get(simulationId)
|
|
1865
|
+
// Returns a simulation entity
|
|
1866
|
+
return simulation
|
|
1867
|
+
} catch (e) {
|
|
1868
|
+
// Handle Network/API errors
|
|
1869
|
+
console.error(`Error fetching simulation ${simulationId}:`, e)
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
const simulation = await getSimulation('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk')
|
|
1874
|
+
console.log('Simulation:', simulation)
|
|
1875
|
+
```
|
|
1876
|
+
|
|
1877
|
+
</details>
|
|
1878
|
+
|
|
1879
|
+
<details>
|
|
1880
|
+
<summary style="font-size: 1.1rem;">Simulation Runs (simulationRuns.get())</summary>
|
|
1881
|
+
|
|
1882
|
+
```typescript
|
|
1883
|
+
import { Paddle, SimulationRun, GetSimulationRunQueryParameters } from '@paddle/paddle-node-sdk'
|
|
1884
|
+
|
|
1885
|
+
const paddle = new Paddle('API_KEY')
|
|
1886
|
+
|
|
1887
|
+
async function getSimulationRun(simulationId: string, simulationRunId: string, queryParams?: GetSimulationRunQueryParameters): Promise<SimulationRun | undefined> {
|
|
1888
|
+
try {
|
|
1889
|
+
// Pass the simulation_id and simulation_run_id to get
|
|
1890
|
+
const simulationRun = await paddle.simulationRuns.get(simulationId, simulationRunId, queryParams)
|
|
1891
|
+
// Returns a simulation run entity
|
|
1892
|
+
return simulationRun
|
|
1893
|
+
} catch (e) {
|
|
1894
|
+
// Handle Network/API errors
|
|
1895
|
+
console.error(`Error fetching simulation run ${simulationRunId} for simulation ${simulationId}:`, e)
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
// Optionally include additional data in the returned object
|
|
1900
|
+
// See GetSimulationRunQueryParameters for more in which data you can include
|
|
1901
|
+
const queryParams: GetSimulationRunQueryParameters = { include: ['events'] }
|
|
1902
|
+
|
|
1903
|
+
const simulationRun = await getSimulationRun('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk', 'ntfsimrun_01ghbkd0frb9k95cnhwd1bxpvk', queryParams)
|
|
1904
|
+
console.log('Simulation Run:', simulationRun)
|
|
1905
|
+
```
|
|
1906
|
+
|
|
1907
|
+
</details>
|
|
1908
|
+
|
|
1909
|
+
<details>
|
|
1910
|
+
<summary style="font-size: 1.1rem;">Simulation Run Events (simulationRunEvents.get())</summary>
|
|
1911
|
+
|
|
1912
|
+
```typescript
|
|
1913
|
+
import { Paddle, SimulationRunEvent } from '@paddle/paddle-node-sdk'
|
|
1914
|
+
|
|
1915
|
+
const paddle = new Paddle('API_KEY')
|
|
1916
|
+
|
|
1917
|
+
async function getSimulationRunEvent(simulationId: string, simulationRunId: string, simulationEventId: string): Promise<SimulationRunEvent | undefined> {
|
|
1918
|
+
try {
|
|
1919
|
+
// Pass the simulation_id, simulation_run_id, and simulation_event_id, and optional query parameters to get
|
|
1920
|
+
const simulationRunEvent = await paddle.simulationRunEvents.get(simulationId, simulationRunId, simulationEventId)
|
|
1921
|
+
// Returns a simulation run event entity
|
|
1922
|
+
return simulationRunEvent
|
|
1923
|
+
} catch (e) {
|
|
1924
|
+
// Handle Network/API errors
|
|
1925
|
+
console.error(`Error fetching event ${simulationEventId} for run ${simulationRunId}, simulation ${simulationId}:`, e)
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
const simulationRunEvent = await getSimulationRunEvent('ntfsim_01ghbkd0frb9k95cnhwd1bxpvk', 'ntfsimrun_01ghbkd0frb9k95cnhwd1bxpvk', 'ntfsimevt_01hvg8ykjrcdr4jvv9rqcbkhfa')
|
|
1930
|
+
console.log('Simulation Run Event:', simulationRunEvent)
|
|
190
1931
|
```
|
|
191
1932
|
|
|
1933
|
+
</details>
|
|
1934
|
+
|
|
192
1935
|
### Archive an entity
|
|
193
1936
|
|
|
194
1937
|
You can archive an entity with the `archive` function in the resource. It accepts the `id` of the entity to archive. The entity is returned.
|
|
195
1938
|
|
|
196
|
-
#### Entities that support archival
|
|
197
|
-
|
|
198
|
-
- Products
|
|
199
|
-
- Prices
|
|
200
|
-
- Discounts
|
|
201
|
-
- Customers
|
|
202
|
-
- Addresses
|
|
203
|
-
- Businesses
|
|
204
|
-
|
|
205
1939
|
``` typescript
|
|
206
1940
|
import { Paddle } from '@paddle/paddle-node-sdk'
|
|
207
1941
|
|
|
208
1942
|
const paddle = new Paddle('API_KEY')
|
|
209
1943
|
|
|
210
|
-
async function archiveProduct(productId: string) {
|
|
1944
|
+
async function archiveProduct(productId: string): Promise<Product | undefined> {
|
|
211
1945
|
try {
|
|
212
1946
|
// Pass the product id archive
|
|
213
1947
|
const product = await paddle.products.archive(productId)
|
|
@@ -215,13 +1949,146 @@ async function archiveProduct(productId: string) {
|
|
|
215
1949
|
return product
|
|
216
1950
|
} catch (e) {
|
|
217
1951
|
// Handle Network/API errors
|
|
1952
|
+
console.error(`Error archiving product ${productId}:`, e)
|
|
218
1953
|
}
|
|
219
1954
|
}
|
|
220
1955
|
|
|
221
|
-
const
|
|
222
|
-
console.log('Product',
|
|
1956
|
+
const archivedProduct = await archiveProduct('pro_01gsz97mq9pa4fkyy0wqenepkz')
|
|
1957
|
+
console.log('Archived Product:', archivedProduct)
|
|
1958
|
+
```
|
|
1959
|
+
|
|
1960
|
+
<details>
|
|
1961
|
+
<summary style="font-size: 1.1rem;">Prices (prices.archive())</summary>
|
|
1962
|
+
|
|
1963
|
+
```typescript
|
|
1964
|
+
import { Paddle, Price } from '@paddle/paddle-node-sdk'
|
|
1965
|
+
|
|
1966
|
+
const paddle = new Paddle('API_KEY')
|
|
1967
|
+
|
|
1968
|
+
async function archivePrice(priceId: string): Promise<Price | undefined> {
|
|
1969
|
+
try {
|
|
1970
|
+
// Pass the price id to archive
|
|
1971
|
+
const price = await paddle.prices.archive(priceId)
|
|
1972
|
+
// Returns an archived price entity
|
|
1973
|
+
return price
|
|
1974
|
+
} catch (e) {
|
|
1975
|
+
// Handle Network/API errors
|
|
1976
|
+
console.error(`Error archiving price ${priceId}:`, e)
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
const archivedPrice = await archivePrice('pri_01gsz8z1q1n00f12qt82y31smh')
|
|
1981
|
+
console.log('Archived Price:', archivedPrice)
|
|
1982
|
+
```
|
|
1983
|
+
|
|
1984
|
+
</details>
|
|
1985
|
+
|
|
1986
|
+
<details>
|
|
1987
|
+
<summary style="font-size: 1.1rem;">Discounts (discounts.archive())</summary>
|
|
1988
|
+
|
|
1989
|
+
```typescript
|
|
1990
|
+
import { Paddle, Discount } from '@paddle/paddle-node-sdk'
|
|
1991
|
+
|
|
1992
|
+
const paddle = new Paddle('API_KEY')
|
|
1993
|
+
|
|
1994
|
+
async function archiveDiscount(discountId: string): Promise<Discount | undefined> {
|
|
1995
|
+
try {
|
|
1996
|
+
// Pass the discount id to archive
|
|
1997
|
+
const discount = await paddle.discounts.archive(discountId)
|
|
1998
|
+
// Returns an archived discount entity
|
|
1999
|
+
return discount
|
|
2000
|
+
} catch (e) {
|
|
2001
|
+
// Handle Network/API errors
|
|
2002
|
+
console.error(`Error archiving discount ${discountId}:`, e)
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
const archivedDiscount = await archiveDiscount('dsc_01gv5kpg05xp104ek2fmgjwttf')
|
|
2007
|
+
console.log('Archived Discount:', archivedDiscount)
|
|
2008
|
+
```
|
|
2009
|
+
|
|
2010
|
+
</details>
|
|
2011
|
+
|
|
2012
|
+
<details>
|
|
2013
|
+
<summary style="font-size: 1.1rem;">Customers (customers.archive())</summary>
|
|
2014
|
+
|
|
2015
|
+
```typescript
|
|
2016
|
+
import { Paddle, Customer } from '@paddle/paddle-node-sdk'
|
|
2017
|
+
|
|
2018
|
+
const paddle = new Paddle('API_KEY')
|
|
2019
|
+
|
|
2020
|
+
async function archiveCustomer(customerId: string): Promise<Customer | undefined> {
|
|
2021
|
+
try {
|
|
2022
|
+
// Pass the customer id to archive
|
|
2023
|
+
const customer = await paddle.customers.archive(customerId)
|
|
2024
|
+
// Returns an archived customer entity
|
|
2025
|
+
return customer
|
|
2026
|
+
} catch (e) {
|
|
2027
|
+
// Handle Network/API errors
|
|
2028
|
+
console.error(`Error archiving customer ${customerId}:`, e)
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
const archivedCustomer = await archiveCustomer('ctm_01grnn4zta5a1mf02jjze7y2ys')
|
|
2033
|
+
console.log('Archived Customer:', archivedCustomer)
|
|
2034
|
+
```
|
|
2035
|
+
|
|
2036
|
+
</details>
|
|
2037
|
+
|
|
2038
|
+
<details>
|
|
2039
|
+
<summary style="font-size: 1.1rem;">Addresses (addresses.archive())</summary>
|
|
2040
|
+
|
|
2041
|
+
```typescript
|
|
2042
|
+
import { Paddle, Address } from '@paddle/paddle-node-sdk'
|
|
2043
|
+
|
|
2044
|
+
const paddle = new Paddle('API_KEY')
|
|
2045
|
+
|
|
2046
|
+
async function archiveAddress(customerId: string, addressId: string): Promise<Address | undefined> {
|
|
2047
|
+
try {
|
|
2048
|
+
// Pass the customer id and address id to archive
|
|
2049
|
+
const address = await paddle.addresses.archive(customerId, addressId)
|
|
2050
|
+
// Returns an archived address entity
|
|
2051
|
+
return address
|
|
2052
|
+
} catch (e) {
|
|
2053
|
+
// Handle Network/API errors
|
|
2054
|
+
console.error(`Error archiving address ${addressId} for customer ${customerId}:`, e)
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
const archivedAddress = await archiveAddress('ctm_01grnn4zta5a1mf02jjze7y2ys', 'add_01gm302t81w94gyjpjpqypkzkf')
|
|
2059
|
+
console.log('Archived Address:', archivedAddress)
|
|
2060
|
+
```
|
|
2061
|
+
|
|
2062
|
+
</details>
|
|
2063
|
+
|
|
2064
|
+
<details>
|
|
2065
|
+
<summary style="font-size: 1.1rem;">Businesses (businesses.archive())</summary>
|
|
2066
|
+
|
|
2067
|
+
```typescript
|
|
2068
|
+
import { Paddle, Business } from '@paddle/paddle-node-sdk'
|
|
2069
|
+
|
|
2070
|
+
const paddle = new Paddle('API_KEY')
|
|
2071
|
+
|
|
2072
|
+
async function archiveBusiness(customerId: string, businessId: string): Promise<Business | undefined> {
|
|
2073
|
+
try {
|
|
2074
|
+
// Pass the customer id and business id to archive
|
|
2075
|
+
const business = await paddle.businesses.archive(customerId, businessId)
|
|
2076
|
+
// Returns an archived business entity
|
|
2077
|
+
return business
|
|
2078
|
+
} catch (e) {
|
|
2079
|
+
// Handle Network/API errors
|
|
2080
|
+
console.error(`Error archiving business ${businessId} for customer ${customerId}:`, e)
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
const archivedBusiness = await archiveBusiness('ctm_01grnn4zta5a1mf02jjze7y2ys', 'biz_01grrebrzaee2qj2fqqhmcyzaj')
|
|
2085
|
+
console.log('Archived Business:', archivedBusiness)
|
|
223
2086
|
```
|
|
224
2087
|
|
|
2088
|
+
</details>
|
|
2089
|
+
|
|
2090
|
+
## Resources
|
|
2091
|
+
|
|
225
2092
|
### Error Handling
|
|
226
2093
|
|
|
227
2094
|
If a request fails, Paddle returns an `error` object that contains the same information as [errors returned by the API](https://developer.paddle.com/api-reference/about/errors?utm_source=dx&utm_medium=paddle-node-sdk). You can use the `code` attribute to search an error in [the error reference](https://developer.paddle.com/errors/overview?utm_source=dx&utm_medium=paddle-node-sdk) and to handle the error in your app. Validation errors also return an array of `errors` that tell you which fields failed validation.
|
|
@@ -242,9 +2109,7 @@ try {
|
|
|
242
2109
|
}
|
|
243
2110
|
```
|
|
244
2111
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
### Webhook signature verification
|
|
2112
|
+
### Webhook signature verification
|
|
248
2113
|
|
|
249
2114
|
The SDK includes a helper function to verify webhook signatures sent by Notifications from Paddle.
|
|
250
2115
|
|