@paywallex/node 1.0.0 → 1.2.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 +27 -2
- package/dist/index.d.ts +67 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,31 @@ const session = await paywallex.checkoutSessions.create({
|
|
|
39
39
|
|
|
40
40
|
Les montants sont en XOF entiers : `2500` veut dire 2 500 F.
|
|
41
41
|
|
|
42
|
+
### Facturation à l'usage
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const plan = await paywallex.plans.create({ name: "Formule SMS", amount: 2000, currency: "XOF", interval: "monthly",
|
|
46
|
+
usage: { mode: "metered", unit: "SMS", unit_amount: 5, cap: 10000 } });
|
|
47
|
+
await paywallex.subscriptions.reportUsage(subscriptionId, { quantity: 120 }, { idempotencyKey: "sms-2026-10-25" });
|
|
48
|
+
// 402 usage_cap_reached : l'abonné doit relever son plafond dans Paywallex.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Paiements partagés (plateformes)
|
|
52
|
+
|
|
53
|
+
Indiquez la part de chaque vendeur par son @identifiant : elle part sur son solde dès que l'argent de la vente est disponible chez vous. Vous gardez le reste, frais Paywallex déduits.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const session = await paywallex.checkoutSessions.create({
|
|
57
|
+
currency: "XOF",
|
|
58
|
+
amount: 20000,
|
|
59
|
+
splits: [
|
|
60
|
+
{ destination: "@chezpapa", amount: 15000, description: "Commande 1042" },
|
|
61
|
+
{ destination: "@livraison-rapide", amount: 2000 },
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
// session.splits[0].status : "pending", puis "paid" (événement payment_split.paid)
|
|
65
|
+
```
|
|
66
|
+
|
|
42
67
|
## Vérifier un webhook
|
|
43
68
|
|
|
44
69
|
Vérifiez la signature avant de traiter un événement. Le SDK compare en temps constant et refuse un horodatage de plus de 5 minutes.
|
|
@@ -87,7 +112,7 @@ Le SDK réessaie 2 fois en cas de coupure réseau, de `429` ou d'erreur `5xx`, e
|
|
|
87
112
|
Pour rejouer vous-même une requête sans risque, donnez votre propre clé :
|
|
88
113
|
|
|
89
114
|
```ts
|
|
90
|
-
await paywallex.refunds.create({ payment: "…" }, { idempotencyKey:
|
|
115
|
+
await paywallex.refunds.create({ payment: "…" }, { idempotencyKey: `remboursement-${order.id}` });
|
|
91
116
|
```
|
|
92
117
|
|
|
93
118
|
## Ce que couvre le SDK
|
|
@@ -101,7 +126,7 @@ await paywallex.refunds.create({ payment: "…" }, { idempotencyKey: "remboursem
|
|
|
101
126
|
| `files` | `upload` (justificatifs PDF, PNG, JPEG de 5 Mo au plus) |
|
|
102
127
|
| `payouts`, `events`, `statements` | `list`, `retrieve` (`statements.csv`) |
|
|
103
128
|
| `customers`, `paymentLinks`, `invoices`, `pots` | `list`, `create`, `retrieve`, `update`, `action` |
|
|
104
|
-
| `plans`, `coupons`, `subscriptions` | création, lecture, `cancel`, `pause`, `resume`, `changePlan`, `manageLink` |
|
|
129
|
+
| `plans`, `coupons`, `subscriptions` | création, lecture, `cancel`, `pause`, `resume`, `changePlan`, `manageLink`, `reportUsage`, `usage` |
|
|
105
130
|
| `webhookEndpoints` | `list`, `create`, `del`, `rotateSecret` |
|
|
106
131
|
| client | `account()`, `balance()`, `networkStatus()` |
|
|
107
132
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.2.0";
|
|
2
2
|
/** Erreur de l'API : testez `code` (stable), jamais le message. */
|
|
3
3
|
export declare class PaywallexError extends Error {
|
|
4
4
|
readonly status: number;
|
|
@@ -42,6 +42,60 @@ export type LineItem = {
|
|
|
42
42
|
unit_amount: number;
|
|
43
43
|
quantity?: number;
|
|
44
44
|
};
|
|
45
|
+
/** DV7 : facturation à l'usage d'une offre (metered : fin de période + plafond ; credits : packs prépayés). */
|
|
46
|
+
export type UsagePlan = {
|
|
47
|
+
mode: "metered";
|
|
48
|
+
unit: string;
|
|
49
|
+
unit_amount: number;
|
|
50
|
+
cap: number;
|
|
51
|
+
} | {
|
|
52
|
+
mode: "credits";
|
|
53
|
+
unit: string;
|
|
54
|
+
pack_units: number;
|
|
55
|
+
pack_amount: number;
|
|
56
|
+
};
|
|
57
|
+
export type UsageSummary = {
|
|
58
|
+
mode: "metered" | "credits";
|
|
59
|
+
unit: string;
|
|
60
|
+
currency: string;
|
|
61
|
+
unit_amount: number | null;
|
|
62
|
+
cap: number | null;
|
|
63
|
+
unbilled_amount: number | null;
|
|
64
|
+
unbilled_quantity: number | null;
|
|
65
|
+
credits_remaining: number | null;
|
|
66
|
+
pack: {
|
|
67
|
+
units: number;
|
|
68
|
+
amount: number;
|
|
69
|
+
} | null;
|
|
70
|
+
};
|
|
71
|
+
export type UsageRecord = Obj & {
|
|
72
|
+
subscription: string;
|
|
73
|
+
mode: "metered" | "credits";
|
|
74
|
+
quantity: number;
|
|
75
|
+
amount: number;
|
|
76
|
+
description: string | null;
|
|
77
|
+
status: "unbilled" | "billed" | "credited" | "waived";
|
|
78
|
+
period: number;
|
|
79
|
+
usage?: UsageSummary | null;
|
|
80
|
+
};
|
|
81
|
+
/** DV7 : part d'un vendeur (paiements partagés). La plateforme garde le reste, frais Paywallex déduits. */
|
|
82
|
+
export type SplitInput = {
|
|
83
|
+
destination: string;
|
|
84
|
+
amount: number;
|
|
85
|
+
description?: string;
|
|
86
|
+
};
|
|
87
|
+
export type PaymentSplit = Obj & {
|
|
88
|
+
destination: string;
|
|
89
|
+
destination_name: string | null;
|
|
90
|
+
amount: number;
|
|
91
|
+
currency: string;
|
|
92
|
+
description: string | null;
|
|
93
|
+
status: "pending" | "paid" | "failed" | "canceled";
|
|
94
|
+
amount_paid: number;
|
|
95
|
+
amount_reversed: number;
|
|
96
|
+
failure_reason: string | null;
|
|
97
|
+
paid_at: number | null;
|
|
98
|
+
};
|
|
45
99
|
export type CheckoutSessionCreate = {
|
|
46
100
|
currency: "XOF";
|
|
47
101
|
amount?: number;
|
|
@@ -54,6 +108,7 @@ export type CheckoutSessionCreate = {
|
|
|
54
108
|
cancel_url?: string;
|
|
55
109
|
expires_at?: number;
|
|
56
110
|
payment_methods?: string[];
|
|
111
|
+
splits?: SplitInput[];
|
|
57
112
|
[k: string]: unknown;
|
|
58
113
|
};
|
|
59
114
|
export type CheckoutSession = Obj & {
|
|
@@ -62,8 +117,10 @@ export type CheckoutSession = Obj & {
|
|
|
62
117
|
amount: number;
|
|
63
118
|
currency: string;
|
|
64
119
|
payment_id: string | null;
|
|
120
|
+
splits?: PaymentSplit[];
|
|
65
121
|
};
|
|
66
122
|
export type Payment = Obj & {
|
|
123
|
+
splits?: PaymentSplit[];
|
|
67
124
|
amount: number;
|
|
68
125
|
amount_charged: number;
|
|
69
126
|
fee: number;
|
|
@@ -226,6 +283,15 @@ export declare class Paywallex {
|
|
|
226
283
|
manageLink: (id: string) => Promise<Obj & {
|
|
227
284
|
url: string;
|
|
228
285
|
}>;
|
|
286
|
+
reportUsage: (id: string, p: {
|
|
287
|
+
quantity: number;
|
|
288
|
+
description?: string;
|
|
289
|
+
}, o?: RequestOptions) => Promise<UsageRecord>;
|
|
290
|
+
usage: (id: string, p?: {
|
|
291
|
+
limit?: number;
|
|
292
|
+
}) => Promise<List<UsageRecord> & {
|
|
293
|
+
usage: UsageSummary | null;
|
|
294
|
+
}>;
|
|
229
295
|
};
|
|
230
296
|
readonly webhookEndpoints: {
|
|
231
297
|
list: () => Promise<List<Obj>>;
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Côté serveur uniquement : ne mettez jamais une clé secrète pwx_sk_… dans un navigateur ou une app mobile.
|
|
3
3
|
// Référence : https://api.paywallex.app/api/developer/openapi-v1.json. Signé : Superagent (DV3, 24 oct. 2026).
|
|
4
4
|
import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
5
|
-
export const VERSION = "1.
|
|
5
|
+
export const VERSION = "1.2.0";
|
|
6
6
|
/** Erreur de l'API : testez `code` (stable), jamais le message. */
|
|
7
7
|
export class PaywallexError extends Error {
|
|
8
8
|
status;
|
|
@@ -134,6 +134,9 @@ export class Paywallex {
|
|
|
134
134
|
/** Une hausse doit être acceptée par l'abonné dans Paywallex. */
|
|
135
135
|
changePlan: (id, p) => r.post(`/v1/subscriptions/${enc(id)}/change_plan`, p),
|
|
136
136
|
manageLink: (id) => r.post(`/v1/subscriptions/${enc(id)}/manage_link`, {}),
|
|
137
|
+
// DV7 : facturation à l'usage. 402 usage_cap_reached / usage_credits_exhausted si l'abonné doit agir dans Paywallex.
|
|
138
|
+
reportUsage: (id, p, o) => r.post(`/v1/subscriptions/${enc(id)}/usage`, p, o),
|
|
139
|
+
usage: (id, p) => r.get(`/v1/subscriptions/${enc(id)}/usage`, p),
|
|
137
140
|
};
|
|
138
141
|
this.webhookEndpoints = {
|
|
139
142
|
list: () => r.get("/v1/webhook_endpoints"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paywallex/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "SDK serveur officiel de l'API Paywallex /v1 : sessions de paiement Mobile Money, remboursements, litiges, abonnements, webhooks signés.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|