@delopay/sdk 0.30.0 → 0.32.0
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 +10 -4
- package/dist/{chunk-INP6UXMJ.js → chunk-ML3Z6JBP.js} +92 -37
- package/dist/chunk-ML3Z6JBP.js.map +1 -0
- package/dist/index.cjs +91 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +372 -56
- package/dist/index.d.ts +372 -56
- package/dist/index.js +1 -1
- package/dist/internal.cjs +91 -36
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/package.json +16 -16
- package/dist/chunk-INP6UXMJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -118,14 +118,16 @@ const customer = await delopay.customers.create({
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
// List saved payment methods
|
|
121
|
-
const
|
|
121
|
+
const { customer_payment_methods } = await delopay.paymentMethods.listForCustomer(
|
|
122
|
+
customer.customer_id,
|
|
123
|
+
);
|
|
122
124
|
|
|
123
125
|
// Use a saved method on a new payment
|
|
124
126
|
const payment = await delopay.payments.create({
|
|
125
127
|
amount: 1000,
|
|
126
128
|
currency: 'EUR',
|
|
127
129
|
customer_id: customer.customer_id,
|
|
128
|
-
payment_token:
|
|
130
|
+
payment_token: customer_payment_methods[0]?.payment_token,
|
|
129
131
|
confirm: true,
|
|
130
132
|
});
|
|
131
133
|
```
|
|
@@ -133,11 +135,15 @@ const payment = await delopay.payments.create({
|
|
|
133
135
|
### Handle disputes
|
|
134
136
|
|
|
135
137
|
```typescript
|
|
136
|
-
|
|
138
|
+
// Disputes for one payment come from the payment object:
|
|
139
|
+
const payment = await delopay.payments.retrieve('pay_abc123');
|
|
137
140
|
|
|
138
|
-
for (const dispute of disputes) {
|
|
141
|
+
for (const dispute of payment.disputes ?? []) {
|
|
139
142
|
console.log(dispute.dispute_id, dispute.dispute_stage, dispute.dispute_status);
|
|
140
143
|
}
|
|
144
|
+
|
|
145
|
+
// Or list disputes across the account, filtered by status:
|
|
146
|
+
const open = await delopay.disputes.list({ dispute_status: 'dispute_opened' });
|
|
141
147
|
```
|
|
142
148
|
|
|
143
149
|
### Manage shops and gateways
|
|
@@ -936,19 +936,21 @@ var Payments = class {
|
|
|
936
936
|
* Create a new payment intent.
|
|
937
937
|
*
|
|
938
938
|
* @param params - Payment creation parameters including amount and currency.
|
|
939
|
+
* @param options - Optional per-call extras: extra `headers` (e.g. an
|
|
940
|
+
* `Idempotency-Key` to make the create safe to retry), a `timeout` override,
|
|
941
|
+
* and an `AbortSignal`.
|
|
939
942
|
* @returns The created payment intent.
|
|
940
943
|
*
|
|
941
944
|
* @example
|
|
942
945
|
* ```typescript
|
|
943
|
-
* const payment = await delopay.payments.create(
|
|
944
|
-
* amount: 5000,
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
* });
|
|
946
|
+
* const payment = await delopay.payments.create(
|
|
947
|
+
* { amount: 5000, currency: 'EUR', customer_id: 'cus_123' },
|
|
948
|
+
* { headers: { 'Idempotency-Key': 'order_1001' } },
|
|
949
|
+
* );
|
|
948
950
|
* ```
|
|
949
951
|
*/
|
|
950
|
-
async create(params) {
|
|
951
|
-
return this.request("POST", "/payments", { body: params });
|
|
952
|
+
async create(params, options) {
|
|
953
|
+
return this.request("POST", "/payments", { body: params, ...options });
|
|
952
954
|
}
|
|
953
955
|
/**
|
|
954
956
|
* Retrieve a payment by its ID.
|
|
@@ -1032,6 +1034,8 @@ var Payments = class {
|
|
|
1032
1034
|
* List payment intents, optionally filtered by customer or date range.
|
|
1033
1035
|
*
|
|
1034
1036
|
* @param params - Optional filter and pagination parameters.
|
|
1037
|
+
* @param options - Optional per-call extras: extra `headers`, a `timeout`
|
|
1038
|
+
* override, and an `AbortSignal` for cancellation.
|
|
1035
1039
|
* @returns Paginated list of payment intents.
|
|
1036
1040
|
*
|
|
1037
1041
|
* @example
|
|
@@ -1039,9 +1043,10 @@ var Payments = class {
|
|
|
1039
1043
|
* const { data } = await delopay.payments.list({ customer_id: 'cus_123', limit: 25 });
|
|
1040
1044
|
* ```
|
|
1041
1045
|
*/
|
|
1042
|
-
async list(params) {
|
|
1046
|
+
async list(params, options) {
|
|
1043
1047
|
return this.request("GET", "/payments/list", {
|
|
1044
|
-
query: params
|
|
1048
|
+
query: params,
|
|
1049
|
+
...options
|
|
1045
1050
|
});
|
|
1046
1051
|
}
|
|
1047
1052
|
// --- Advanced operations (Task 3.2) ---
|
|
@@ -1762,7 +1767,7 @@ var Shops = class {
|
|
|
1762
1767
|
*
|
|
1763
1768
|
* @example
|
|
1764
1769
|
* ```typescript
|
|
1765
|
-
* const shop = await delopay.shops.create('merch_123', {
|
|
1770
|
+
* const shop = await delopay.shops.create('merch_123', { shop_name: 'EU Store' });
|
|
1766
1771
|
* ```
|
|
1767
1772
|
*/
|
|
1768
1773
|
async create(merchantId, params) {
|
|
@@ -2522,11 +2527,16 @@ var Subscriptions = class {
|
|
|
2522
2527
|
constructor(request) {
|
|
2523
2528
|
this.request = request;
|
|
2524
2529
|
}
|
|
2525
|
-
/**
|
|
2530
|
+
/**
|
|
2531
|
+
* Create and immediately confirm a subscription. `POST /subscriptions`
|
|
2532
|
+
*
|
|
2533
|
+
* For billing processors that require buyer approval (e.g. PayPal), the
|
|
2534
|
+
* response carries a `redirect_url` the customer must be sent to.
|
|
2535
|
+
*/
|
|
2526
2536
|
async createAndConfirm(params) {
|
|
2527
2537
|
return this.request("POST", "/subscriptions", { body: params });
|
|
2528
2538
|
}
|
|
2529
|
-
/** Create a subscription
|
|
2539
|
+
/** Create a subscription without confirming it. `POST /subscriptions/create` */
|
|
2530
2540
|
async create(params) {
|
|
2531
2541
|
return this.request("POST", "/subscriptions/create", { body: params });
|
|
2532
2542
|
}
|
|
@@ -2534,43 +2544,58 @@ var Subscriptions = class {
|
|
|
2534
2544
|
async retrieve(subscriptionId) {
|
|
2535
2545
|
return this.request("GET", `/subscriptions/${encodeURIComponent(subscriptionId)}`);
|
|
2536
2546
|
}
|
|
2537
|
-
/**
|
|
2547
|
+
/**
|
|
2548
|
+
* Confirm a previously created subscription. `POST /subscriptions/{subscriptionId}/confirm`
|
|
2549
|
+
*
|
|
2550
|
+
* Like {@link createAndConfirm}, the response may carry a `redirect_url` for
|
|
2551
|
+
* processors that require buyer approval.
|
|
2552
|
+
*/
|
|
2538
2553
|
async confirm(subscriptionId, params) {
|
|
2539
2554
|
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/confirm`, {
|
|
2540
2555
|
body: params
|
|
2541
2556
|
});
|
|
2542
2557
|
}
|
|
2543
|
-
/** Update a subscription. `PUT /subscriptions/{subscriptionId}/update` */
|
|
2558
|
+
/** Update a subscription's plan/price. `PUT /subscriptions/{subscriptionId}/update` */
|
|
2544
2559
|
async update(subscriptionId, params) {
|
|
2545
2560
|
return this.request("PUT", `/subscriptions/${encodeURIComponent(subscriptionId)}/update`, {
|
|
2546
2561
|
body: params
|
|
2547
2562
|
});
|
|
2548
2563
|
}
|
|
2549
|
-
/** List subscriptions. `GET /subscriptions/list` */
|
|
2564
|
+
/** List subscriptions for the profile. `GET /subscriptions/list` */
|
|
2550
2565
|
async list(params) {
|
|
2551
2566
|
return this.request("GET", "/subscriptions/list", {
|
|
2552
2567
|
query: params
|
|
2553
2568
|
});
|
|
2554
2569
|
}
|
|
2555
|
-
/**
|
|
2570
|
+
/** Estimate the cost of a subscription before creating it. `GET /subscriptions/estimate` */
|
|
2556
2571
|
async getEstimate(params) {
|
|
2557
|
-
return this.request("GET", "/subscriptions/estimate", {
|
|
2572
|
+
return this.request("GET", "/subscriptions/estimate", {
|
|
2573
|
+
query: params
|
|
2574
|
+
});
|
|
2558
2575
|
}
|
|
2559
|
-
/**
|
|
2576
|
+
/** List purchasable subscription items (plans/addons). `GET /subscriptions/items` */
|
|
2560
2577
|
async getItems(params) {
|
|
2561
|
-
return this.request("GET", "/subscriptions/items", {
|
|
2578
|
+
return this.request("GET", "/subscriptions/items", {
|
|
2579
|
+
query: params
|
|
2580
|
+
});
|
|
2562
2581
|
}
|
|
2563
2582
|
/** Pause a subscription. `POST /subscriptions/{subscriptionId}/pause` */
|
|
2564
|
-
async pause(subscriptionId) {
|
|
2565
|
-
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause
|
|
2583
|
+
async pause(subscriptionId, params) {
|
|
2584
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause`, {
|
|
2585
|
+
body: params
|
|
2586
|
+
});
|
|
2566
2587
|
}
|
|
2567
|
-
/** Resume a subscription. `POST /subscriptions/{subscriptionId}/resume` */
|
|
2568
|
-
async resume(subscriptionId) {
|
|
2569
|
-
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume
|
|
2588
|
+
/** Resume a paused subscription. `POST /subscriptions/{subscriptionId}/resume` */
|
|
2589
|
+
async resume(subscriptionId, params) {
|
|
2590
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume`, {
|
|
2591
|
+
body: params
|
|
2592
|
+
});
|
|
2570
2593
|
}
|
|
2571
2594
|
/** Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel` */
|
|
2572
|
-
async cancel(subscriptionId) {
|
|
2573
|
-
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel
|
|
2595
|
+
async cancel(subscriptionId, params) {
|
|
2596
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`, {
|
|
2597
|
+
body: params
|
|
2598
|
+
});
|
|
2574
2599
|
}
|
|
2575
2600
|
};
|
|
2576
2601
|
|
|
@@ -2655,7 +2680,7 @@ var Delopay = class {
|
|
|
2655
2680
|
/**
|
|
2656
2681
|
* Create a new Delopay client.
|
|
2657
2682
|
*
|
|
2658
|
-
* @param apiKey - Your Delopay API key (e.g. `
|
|
2683
|
+
* @param apiKey - Your Delopay API key (e.g. `prd_...` or `snd_...`).
|
|
2659
2684
|
* Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
|
|
2660
2685
|
* @param options - Optional configuration (sandbox mode, base URL override, timeout).
|
|
2661
2686
|
*/
|
|
@@ -2912,34 +2937,64 @@ var Delopay = class {
|
|
|
2912
2937
|
* Auto-paginate a list endpoint. Yields items one by one, fetching
|
|
2913
2938
|
* the next page automatically when the current one is exhausted.
|
|
2914
2939
|
*
|
|
2915
|
-
*
|
|
2940
|
+
* Delopay list endpoints use one of two pagination styles, so this helper
|
|
2941
|
+
* supports both:
|
|
2942
|
+
* - **Offset** (default) — for endpoints like `customers.list` that accept
|
|
2943
|
+
* `offset`/`limit`. Each page advances `offset` by the number of items returned.
|
|
2944
|
+
* - **Cursor** — for endpoints like `payments.list` and `payouts.list` that page
|
|
2945
|
+
* with `starting_after`/`limit` (they ignore `offset`). Pass a `cursor` extractor
|
|
2946
|
+
* that returns the id of an item; the next page is requested with
|
|
2947
|
+
* `starting_after` set to the last item's id.
|
|
2948
|
+
*
|
|
2949
|
+
* @param listFn - A function that takes the paging params and returns `{ data: T[] }` or `T[]`.
|
|
2916
2950
|
* @param params - Additional parameters to pass to every page request.
|
|
2917
|
-
* @param
|
|
2951
|
+
* @param options - Page size (number) for offset mode, or `{ pageSize?, cursor? }`.
|
|
2952
|
+
* Provide `cursor` to switch to cursor pagination.
|
|
2918
2953
|
*
|
|
2919
2954
|
* @example
|
|
2920
2955
|
* ```typescript
|
|
2956
|
+
* // Offset endpoint (customers):
|
|
2957
|
+
* for await (const c of delopay.paginate((p) => delopay.customers.list(p))) {
|
|
2958
|
+
* console.log(c.customer_id);
|
|
2959
|
+
* }
|
|
2960
|
+
*
|
|
2961
|
+
* // Cursor endpoint (payments): extract the id used as the next cursor.
|
|
2921
2962
|
* for await (const payment of delopay.paginate(
|
|
2922
2963
|
* (p) => delopay.payments.list(p),
|
|
2964
|
+
* undefined,
|
|
2965
|
+
* { cursor: (p) => p.payment_id },
|
|
2923
2966
|
* )) {
|
|
2924
2967
|
* console.log(payment.payment_id);
|
|
2925
2968
|
* }
|
|
2926
2969
|
* ```
|
|
2927
2970
|
*/
|
|
2928
|
-
async *paginate(listFn, params,
|
|
2971
|
+
async *paginate(listFn, params, options) {
|
|
2972
|
+
const pageSize = typeof options === "number" ? options : options?.pageSize ?? 50;
|
|
2973
|
+
const cursorOf = typeof options === "object" ? options.cursor : void 0;
|
|
2929
2974
|
let offset = 0;
|
|
2975
|
+
let after;
|
|
2930
2976
|
while (true) {
|
|
2931
|
-
const
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2977
|
+
const page = { ...params ?? {}, limit: pageSize };
|
|
2978
|
+
if (cursorOf) {
|
|
2979
|
+
if (after !== void 0) page.starting_after = after;
|
|
2980
|
+
} else {
|
|
2981
|
+
page.offset = offset;
|
|
2982
|
+
}
|
|
2983
|
+
const result = await listFn(page);
|
|
2936
2984
|
const items = Array.isArray(result) ? result : result.data;
|
|
2937
2985
|
if (items.length === 0) break;
|
|
2938
2986
|
for (const item of items) {
|
|
2939
2987
|
yield item;
|
|
2940
2988
|
}
|
|
2941
2989
|
if (items.length < pageSize) break;
|
|
2942
|
-
|
|
2990
|
+
if (cursorOf) {
|
|
2991
|
+
const last = items[items.length - 1];
|
|
2992
|
+
if (last === void 0) break;
|
|
2993
|
+
after = cursorOf(last);
|
|
2994
|
+
if (after === void 0) break;
|
|
2995
|
+
} else {
|
|
2996
|
+
offset += items.length;
|
|
2997
|
+
}
|
|
2943
2998
|
}
|
|
2944
2999
|
}
|
|
2945
3000
|
};
|
|
@@ -3621,4 +3676,4 @@ export {
|
|
|
3621
3676
|
applyBrandingVariables,
|
|
3622
3677
|
shadowFor
|
|
3623
3678
|
};
|
|
3624
|
-
//# sourceMappingURL=chunk-
|
|
3679
|
+
//# sourceMappingURL=chunk-ML3Z6JBP.js.map
|