@paykit-sdk/stripe 1.1.4 → 1.1.6
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +71 -66
- package/dist/index.mjs +73 -66
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription,
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription, HandleWebhookParams, WebhookEventPayload } from '@paykit-sdk/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
|
|
4
4
|
interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
|
|
@@ -28,7 +28,7 @@ declare class StripeProvider implements PayKitProvider {
|
|
|
28
28
|
/**
|
|
29
29
|
* Webhook management
|
|
30
30
|
*/
|
|
31
|
-
handleWebhook: (params:
|
|
31
|
+
handleWebhook: (params: HandleWebhookParams) => Promise<WebhookEventPayload>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
declare const createStripe: (config: StripeConfig) => StripeProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription,
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription, HandleWebhookParams, WebhookEventPayload } from '@paykit-sdk/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
|
|
4
4
|
interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
|
|
@@ -28,7 +28,7 @@ declare class StripeProvider implements PayKitProvider {
|
|
|
28
28
|
/**
|
|
29
29
|
* Webhook management
|
|
30
30
|
*/
|
|
31
|
-
handleWebhook: (params:
|
|
31
|
+
handleWebhook: (params: HandleWebhookParams) => Promise<WebhookEventPayload>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
declare const createStripe: (config: StripeConfig) => StripeProvider;
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
stripe: () => stripe
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_core3 = require("@paykit-sdk/core");
|
|
37
38
|
|
|
38
39
|
// src/stripe-provider.ts
|
|
39
40
|
var import_core2 = require("@paykit-sdk/core");
|
|
@@ -85,7 +86,8 @@ var toPaykitInvoice = (invoice) => {
|
|
|
85
86
|
amount: invoice.amount_paid,
|
|
86
87
|
currency: invoice.currency,
|
|
87
88
|
metadata: (0, import_core.stringifyObjectValues)(invoice.metadata ?? {}),
|
|
88
|
-
customer_id: invoice.customer?.toString() ?? ""
|
|
89
|
+
customer_id: invoice.customer?.toString() ?? "",
|
|
90
|
+
billing_mode: invoice.billingMode
|
|
89
91
|
};
|
|
90
92
|
};
|
|
91
93
|
|
|
@@ -154,67 +156,73 @@ var StripeProvider = class {
|
|
|
154
156
|
const stripeHeaders = (0, import_core2.headersExtractor)(headers, ["x-stripe-signature"]);
|
|
155
157
|
const signature = stripeHeaders[0].value;
|
|
156
158
|
const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
data
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
const webhookHandlers = {
|
|
160
|
+
/**
|
|
161
|
+
* Invoice
|
|
162
|
+
*/
|
|
163
|
+
"checkout.session.completed": (event2) => {
|
|
164
|
+
const data = event2.data.object;
|
|
165
|
+
if (data.mode !== "payment") return null;
|
|
166
|
+
return (0, import_core2.toPaykitEvent)({
|
|
167
|
+
type: "$invoicePaid",
|
|
168
|
+
created: event2.created,
|
|
169
|
+
id: event2.id,
|
|
170
|
+
data: {
|
|
171
|
+
id: data.id,
|
|
172
|
+
amount: data.amount_total ?? 0,
|
|
173
|
+
currency: data.currency ?? "",
|
|
174
|
+
metadata: (0, import_core2.stringifyObjectValues)({ ...data.metadata ?? {}, $mode: data.mode }),
|
|
175
|
+
customer_id: data.customer?.toString() ?? "",
|
|
176
|
+
billing_mode: "one_time"
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
"invoice.paid": (event2) => {
|
|
181
|
+
const data = event2.data.object;
|
|
182
|
+
if (data.status !== "paid" && !["subscription_create", "subscription_cycle"].includes(data.billing_reason)) {
|
|
183
|
+
return null;
|
|
169
184
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
type: "$
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
data
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
data
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
type: "$subscriptionUpdated",
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
data:
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
data: toPaykitSubscription(subscription)
|
|
212
|
-
});
|
|
213
|
-
} else if (event.type == "invoice.paid" && event.data.object.status == "paid") {
|
|
214
|
-
const invoice = event.data.object;
|
|
215
|
-
return (0, import_core2.toPaykitEvent)({ type: "$invoicePaid", created: event.created, id: event.id, data: toPaykitInvoice(invoice) });
|
|
216
|
-
}
|
|
217
|
-
throw new Error(`Unhandled event type: ${event.type}`);
|
|
185
|
+
return (0, import_core2.toPaykitEvent)({
|
|
186
|
+
type: "$invoicePaid",
|
|
187
|
+
created: event2.created,
|
|
188
|
+
id: event2.id,
|
|
189
|
+
data: toPaykitInvoice({ ...data, billingMode: "recurring" })
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* Customer
|
|
194
|
+
*/
|
|
195
|
+
"customer.created": (event2) => {
|
|
196
|
+
const data = event2.data.object;
|
|
197
|
+
return (0, import_core2.toPaykitEvent)({ type: "$customerCreated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
|
|
198
|
+
},
|
|
199
|
+
"customer.updated": (event2) => {
|
|
200
|
+
const data = event2.data.object;
|
|
201
|
+
return (0, import_core2.toPaykitEvent)({ type: "$customerUpdated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
|
|
202
|
+
},
|
|
203
|
+
"customer.deleted": (event2) => {
|
|
204
|
+
return (0, import_core2.toPaykitEvent)({ type: "$customerDeleted", created: event2.created, id: event2.id, data: null });
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Subscription
|
|
208
|
+
*/
|
|
209
|
+
"customer.subscription.created": (event2) => {
|
|
210
|
+
const data = event2.data.object;
|
|
211
|
+
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCreated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
|
|
212
|
+
},
|
|
213
|
+
"customer.subscription.updated": (event2) => {
|
|
214
|
+
const data = event2.data.object;
|
|
215
|
+
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionUpdated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
|
|
216
|
+
},
|
|
217
|
+
"customer.subscription.deleted": (event2) => {
|
|
218
|
+
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCancelled", created: event2.created, id: event2.id, data: null });
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const handler = webhookHandlers[event.type];
|
|
222
|
+
if (!handler) throw new Error(`Unhandled event type: ${event.type}`);
|
|
223
|
+
const result = handler(event);
|
|
224
|
+
if (!result) throw new Error(`Unhandled event type: ${event.type}`);
|
|
225
|
+
return result;
|
|
218
226
|
};
|
|
219
227
|
const { debug, apiKey, ...rest } = config;
|
|
220
228
|
this.stripe = new import_stripe.default(apiKey, rest);
|
|
@@ -226,12 +234,9 @@ var createStripe = (config) => {
|
|
|
226
234
|
return new StripeProvider(config);
|
|
227
235
|
};
|
|
228
236
|
var stripe = () => {
|
|
229
|
-
const
|
|
237
|
+
const envVars = (0, import_core3.validateEnvVars)(["STRIPE_API_KEY"], process.env);
|
|
230
238
|
const isDev = process.env.NODE_ENV === "development";
|
|
231
|
-
|
|
232
|
-
throw new Error("STRIPE_API_KEY is not set");
|
|
233
|
-
}
|
|
234
|
-
return createStripe({ apiKey, debug: isDev, apiVersion: "2025-07-30.basil" });
|
|
239
|
+
return createStripe({ apiKey: envVars.STRIPE_API_KEY, debug: isDev, apiVersion: "2025-07-30.basil" });
|
|
235
240
|
};
|
|
236
241
|
// Annotate the CommonJS export names for ESM import in node:
|
|
237
242
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { validateEnvVars } from "@paykit-sdk/core";
|
|
3
|
+
|
|
1
4
|
// src/stripe-provider.ts
|
|
2
5
|
import {
|
|
3
6
|
toPaykitEvent,
|
|
@@ -52,7 +55,8 @@ var toPaykitInvoice = (invoice) => {
|
|
|
52
55
|
amount: invoice.amount_paid,
|
|
53
56
|
currency: invoice.currency,
|
|
54
57
|
metadata: stringifyObjectValues(invoice.metadata ?? {}),
|
|
55
|
-
customer_id: invoice.customer?.toString() ?? ""
|
|
58
|
+
customer_id: invoice.customer?.toString() ?? "",
|
|
59
|
+
billing_mode: invoice.billingMode
|
|
56
60
|
};
|
|
57
61
|
};
|
|
58
62
|
|
|
@@ -121,67 +125,73 @@ var StripeProvider = class {
|
|
|
121
125
|
const stripeHeaders = headersExtractor(headers, ["x-stripe-signature"]);
|
|
122
126
|
const signature = stripeHeaders[0].value;
|
|
123
127
|
const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
data
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
const webhookHandlers = {
|
|
129
|
+
/**
|
|
130
|
+
* Invoice
|
|
131
|
+
*/
|
|
132
|
+
"checkout.session.completed": (event2) => {
|
|
133
|
+
const data = event2.data.object;
|
|
134
|
+
if (data.mode !== "payment") return null;
|
|
135
|
+
return toPaykitEvent({
|
|
136
|
+
type: "$invoicePaid",
|
|
137
|
+
created: event2.created,
|
|
138
|
+
id: event2.id,
|
|
139
|
+
data: {
|
|
140
|
+
id: data.id,
|
|
141
|
+
amount: data.amount_total ?? 0,
|
|
142
|
+
currency: data.currency ?? "",
|
|
143
|
+
metadata: stringifyObjectValues2({ ...data.metadata ?? {}, $mode: data.mode }),
|
|
144
|
+
customer_id: data.customer?.toString() ?? "",
|
|
145
|
+
billing_mode: "one_time"
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
"invoice.paid": (event2) => {
|
|
150
|
+
const data = event2.data.object;
|
|
151
|
+
if (data.status !== "paid" && !["subscription_create", "subscription_cycle"].includes(data.billing_reason)) {
|
|
152
|
+
return null;
|
|
136
153
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
type: "$
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
data
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
data
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
type: "$subscriptionUpdated",
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
data:
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
data: toPaykitSubscription(subscription)
|
|
179
|
-
});
|
|
180
|
-
} else if (event.type == "invoice.paid" && event.data.object.status == "paid") {
|
|
181
|
-
const invoice = event.data.object;
|
|
182
|
-
return toPaykitEvent({ type: "$invoicePaid", created: event.created, id: event.id, data: toPaykitInvoice(invoice) });
|
|
183
|
-
}
|
|
184
|
-
throw new Error(`Unhandled event type: ${event.type}`);
|
|
154
|
+
return toPaykitEvent({
|
|
155
|
+
type: "$invoicePaid",
|
|
156
|
+
created: event2.created,
|
|
157
|
+
id: event2.id,
|
|
158
|
+
data: toPaykitInvoice({ ...data, billingMode: "recurring" })
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* Customer
|
|
163
|
+
*/
|
|
164
|
+
"customer.created": (event2) => {
|
|
165
|
+
const data = event2.data.object;
|
|
166
|
+
return toPaykitEvent({ type: "$customerCreated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
|
|
167
|
+
},
|
|
168
|
+
"customer.updated": (event2) => {
|
|
169
|
+
const data = event2.data.object;
|
|
170
|
+
return toPaykitEvent({ type: "$customerUpdated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
|
|
171
|
+
},
|
|
172
|
+
"customer.deleted": (event2) => {
|
|
173
|
+
return toPaykitEvent({ type: "$customerDeleted", created: event2.created, id: event2.id, data: null });
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Subscription
|
|
177
|
+
*/
|
|
178
|
+
"customer.subscription.created": (event2) => {
|
|
179
|
+
const data = event2.data.object;
|
|
180
|
+
return toPaykitEvent({ type: "$subscriptionCreated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
|
|
181
|
+
},
|
|
182
|
+
"customer.subscription.updated": (event2) => {
|
|
183
|
+
const data = event2.data.object;
|
|
184
|
+
return toPaykitEvent({ type: "$subscriptionUpdated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
|
|
185
|
+
},
|
|
186
|
+
"customer.subscription.deleted": (event2) => {
|
|
187
|
+
return toPaykitEvent({ type: "$subscriptionCancelled", created: event2.created, id: event2.id, data: null });
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const handler = webhookHandlers[event.type];
|
|
191
|
+
if (!handler) throw new Error(`Unhandled event type: ${event.type}`);
|
|
192
|
+
const result = handler(event);
|
|
193
|
+
if (!result) throw new Error(`Unhandled event type: ${event.type}`);
|
|
194
|
+
return result;
|
|
185
195
|
};
|
|
186
196
|
const { debug, apiKey, ...rest } = config;
|
|
187
197
|
this.stripe = new Stripe(apiKey, rest);
|
|
@@ -193,12 +203,9 @@ var createStripe = (config) => {
|
|
|
193
203
|
return new StripeProvider(config);
|
|
194
204
|
};
|
|
195
205
|
var stripe = () => {
|
|
196
|
-
const
|
|
206
|
+
const envVars = validateEnvVars(["STRIPE_API_KEY"], process.env);
|
|
197
207
|
const isDev = process.env.NODE_ENV === "development";
|
|
198
|
-
|
|
199
|
-
throw new Error("STRIPE_API_KEY is not set");
|
|
200
|
-
}
|
|
201
|
-
return createStripe({ apiKey, debug: isDev, apiVersion: "2025-07-30.basil" });
|
|
208
|
+
return createStripe({ apiKey: envVars.STRIPE_API_KEY, debug: isDev, apiVersion: "2025-07-30.basil" });
|
|
202
209
|
};
|
|
203
210
|
export {
|
|
204
211
|
createStripe,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/stripe",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Stripe provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"stripe": "^18.2.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@paykit-sdk/core": "^1.1.
|
|
27
|
+
"@paykit-sdk/core": "^1.1.7"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"tsup": "^8.0.0",
|