@paykit-sdk/stripe 1.1.5 → 1.1.7

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 CHANGED
@@ -177,4 +177,4 @@ STRIPE_WEBHOOK_SECRET=whsec_...
177
177
 
178
178
  ## License
179
179
 
180
- ISC
180
+ GPL-3.0
package/dist/index.js CHANGED
@@ -42,20 +42,20 @@ var import_stripe = __toESM(require("stripe"));
42
42
 
43
43
  // lib/mapper.ts
44
44
  var import_core = require("@paykit-sdk/core");
45
- var toPaykitCheckout = (checkout) => {
45
+ var paykitCheckout$InboundSchema = (checkout) => {
46
46
  return {
47
47
  id: checkout.id,
48
- customer_id: checkout.customer,
48
+ customer_id: typeof checkout.customer === "string" ? checkout.customer.toString() : checkout.customer?.id ?? "",
49
49
  session_type: checkout.mode === "subscription" ? "recurring" : "one_time",
50
- // todo: handle `setup` mode
51
50
  payment_url: checkout.url,
52
51
  products: checkout.line_items.data.map((item) => ({ id: item.price.id, quantity: item.quantity })),
53
52
  currency: checkout.currency,
54
53
  amount: checkout.amount_total,
55
- metadata: checkout.metadata
54
+ subscription: null,
55
+ metadata: (0, import_core.stringifyObjectValues)(checkout.metadata ?? {})
56
56
  };
57
57
  };
58
- var toPaykitCustomer = (customer) => {
58
+ var paykitCustomer$InboundSchema = (customer) => {
59
59
  return {
60
60
  id: customer.id,
61
61
  email: customer.email ?? void 0,
@@ -63,30 +63,60 @@ var toPaykitCustomer = (customer) => {
63
63
  metadata: (0, import_core.stringifyObjectValues)(customer.metadata ?? {})
64
64
  };
65
65
  };
66
- var toPaykitSubscriptionStatus = (status) => {
67
- if (["active", "trialing"].includes(status)) return "active";
68
- if (["incomplete_expired", "incomplete", "past_due"].includes(status)) return "past_due";
69
- if (["canceled"].includes(status)) return "canceled";
70
- if (["expired"].includes(status)) return "expired";
71
- throw new Error(`Unknown status: ${status}`);
72
- };
73
- var toPaykitSubscription = (subscription) => {
66
+ var paykitSubscription$InboundSchema = (subscription) => {
67
+ const status = (() => {
68
+ if (["active", "trialing"].includes(subscription.status)) return "active";
69
+ if (["incomplete_expired", "incomplete", "past_due"].includes(subscription.status)) return "past_due";
70
+ if (["canceled"].includes(subscription.status)) return "canceled";
71
+ if (["expired"].includes(subscription.status)) return "expired";
72
+ throw new Error(`Unknown status: ${subscription.status}`);
73
+ })();
74
74
  return {
75
75
  id: subscription.id,
76
+ status,
76
77
  customer_id: subscription.customer?.toString(),
77
- status: toPaykitSubscriptionStatus(subscription.status),
78
+ amount: subscription.items.data[0].price.unit_amount,
79
+ currency: subscription.items.data[0].price.currency,
80
+ item_id: subscription.items.data[0].id,
81
+ billing_interval: subscription.items.data[0].price.recurring?.interval,
82
+ billing_interval_count: subscription.items.data[0].price.recurring?.interval_count ?? 1,
78
83
  current_period_start: new Date(subscription.start_date),
79
84
  current_period_end: new Date(subscription.cancel_at),
80
- metadata: (0, import_core.stringifyObjectValues)(subscription.metadata ?? {})
85
+ metadata: (0, import_core.stringifyObjectValues)(subscription.metadata ?? {}),
86
+ /**
87
+ * todo: fix
88
+ */
89
+ custom_fields: null,
90
+ current_cycle: 0,
91
+ total_cycles: 0
81
92
  };
82
93
  };
83
- var toPaykitInvoice = (invoice) => {
94
+ var paykitInvoice$InboundSchema = (invoice) => {
95
+ const status = (() => {
96
+ if (invoice.status == "paid") return "paid";
97
+ if (["draft", "open", "uncollectible", "void"].includes(invoice.status)) return "open";
98
+ throw new Error(`Unknown status: ${invoice.status}`);
99
+ })();
100
+ const subscriptionId = /* @__PURE__ */ (() => {
101
+ return null;
102
+ })();
103
+ const customerId = (() => {
104
+ if (typeof invoice.customer === "string") return invoice.customer;
105
+ if (invoice.customer?.id) return invoice.customer.id;
106
+ throw new Error(`Unknown customer ID: ${invoice.customer}`);
107
+ })();
84
108
  return {
85
109
  id: invoice.id,
86
- amount: invoice.amount_paid,
87
110
  currency: invoice.currency,
111
+ customer_id: customerId,
112
+ billing_mode: invoice.billingMode,
113
+ amount_paid: invoice.amount_paid,
114
+ line_items: invoice.lines.data.map((line) => ({ id: line.id, quantity: line.quantity })),
115
+ subscription_id: subscriptionId,
116
+ status,
117
+ paid_at: new Date(invoice.created * 1e3).toISOString(),
88
118
  metadata: (0, import_core.stringifyObjectValues)(invoice.metadata ?? {}),
89
- customer_id: invoice.customer?.toString() ?? ""
119
+ custom_fields: invoice.custom_fields ?? null
90
120
  };
91
121
  };
92
122
 
@@ -97,31 +127,30 @@ var StripeProvider = class {
97
127
  * Checkout management
98
128
  */
99
129
  this.createCheckout = async (params) => {
100
- const { customer_id, item_id, metadata, session_type, provider_metadata } = params;
101
130
  const checkout = await this.stripe.checkout.sessions.create({
102
- customer: customer_id,
103
- mode: session_type === "one_time" ? "payment" : "subscription",
104
- ...session_type == "one_time" && { metadata },
105
- ...session_type == "recurring" && { subscription_data: { metadata } },
106
- line_items: [{ price: item_id }],
107
- ...provider_metadata
131
+ customer: params.customer_id,
132
+ mode: params.session_type === "one_time" ? "payment" : "subscription",
133
+ ...params.session_type == "one_time" && { metadata: (0, import_core2.stringifyObjectValues)(params.metadata ?? {}) },
134
+ ...params.session_type == "recurring" && { subscription_data: { metadata: (0, import_core2.stringifyObjectValues)(params.metadata ?? {}) } },
135
+ line_items: [{ price: params.item_id, quantity: params.quantity }],
136
+ ...params.provider_metadata
108
137
  });
109
- return toPaykitCheckout(checkout);
138
+ return paykitCheckout$InboundSchema(checkout);
110
139
  };
111
140
  this.retrieveCheckout = async (id) => {
112
141
  const checkout = await this.stripe.checkout.sessions.retrieve(id);
113
- return toPaykitCheckout(checkout);
142
+ return paykitCheckout$InboundSchema(checkout);
114
143
  };
115
144
  /**
116
145
  * Customer management
117
146
  */
118
147
  this.createCustomer = async (params) => {
119
148
  const customer = await this.stripe.customers.create(params);
120
- return toPaykitCustomer(customer);
149
+ return paykitCustomer$InboundSchema(customer);
121
150
  };
122
151
  this.updateCustomer = async (id, params) => {
123
152
  const customer = await this.stripe.customers.update(id, params);
124
- return toPaykitCustomer(customer);
153
+ return paykitCustomer$InboundSchema(customer);
125
154
  };
126
155
  this.deleteCustomer = async (id) => {
127
156
  await this.stripe.customers.del(id);
@@ -130,7 +159,7 @@ var StripeProvider = class {
130
159
  this.retrieveCustomer = async (id) => {
131
160
  const customer = await this.stripe.customers.retrieve(id);
132
161
  if ("deleted" in customer) return null;
133
- return toPaykitCustomer(customer);
162
+ return paykitCustomer$InboundSchema(customer);
134
163
  };
135
164
  /**
136
165
  * Subscription management
@@ -140,12 +169,12 @@ var StripeProvider = class {
140
169
  return null;
141
170
  };
142
171
  this.updateSubscription = async (id, params) => {
143
- const subscription = await this.stripe.subscriptions.update(id, { metadata: params.metadata });
144
- return toPaykitSubscription(subscription);
172
+ const subscription = await this.stripe.subscriptions.update(id, { metadata: (0, import_core2.stringifyObjectValues)(params.metadata ?? {}) });
173
+ return paykitSubscription$InboundSchema(subscription);
145
174
  };
146
175
  this.retrieveSubscription = async (id) => {
147
176
  const subscription = await this.stripe.subscriptions.retrieve(id);
148
- return toPaykitSubscription(subscription);
177
+ return paykitSubscription$InboundSchema(subscription);
149
178
  };
150
179
  /**
151
180
  * Webhook management
@@ -159,7 +188,7 @@ var StripeProvider = class {
159
188
  /**
160
189
  * Invoice
161
190
  */
162
- "checkout.session.completed": (event2) => {
191
+ "checkout.session.completed": async (event2) => {
163
192
  const data = event2.data.object;
164
193
  if (data.mode !== "payment") return null;
165
194
  return (0, import_core2.toPaykitEvent)({
@@ -168,50 +197,72 @@ var StripeProvider = class {
168
197
  id: event2.id,
169
198
  data: {
170
199
  id: data.id,
171
- amount: data.amount_total ?? 0,
200
+ status: "paid",
201
+ paid_at: new Date(event2.created * 1e3).toISOString(),
202
+ amount_paid: data.amount_total ?? 0,
172
203
  currency: data.currency ?? "",
173
- metadata: (0, import_core2.stringifyObjectValues)({ ...data.metadata ?? {}, $mode: data.mode }),
174
- customer_id: data.customer?.toString() ?? ""
204
+ metadata: (0, import_core2.stringifyObjectValues)({ ...data.metadata ?? {} }),
205
+ customer_id: data.customer?.toString() ?? "",
206
+ billing_mode: "one_time",
207
+ subscription_id: null,
208
+ custom_fields: data.custom_fields ?? null,
209
+ line_items: data.line_items?.data.map((item) => ({ id: item.price.id, quantity: item.quantity })) ?? []
175
210
  }
176
211
  });
177
212
  },
178
- "invoice.paid": (event2) => {
213
+ "invoice.paid": async (event2) => {
179
214
  const data = event2.data.object;
180
- if (data.status !== "paid") return null;
181
- return (0, import_core2.toPaykitEvent)({ type: "$invoicePaid", created: event2.created, id: event2.id, data: toPaykitInvoice(data) });
215
+ const relevantBillingReasons = ["subscription_create", "subscription_cycle"];
216
+ if (data.status !== "paid" && !relevantBillingReasons.includes(data.billing_reason)) return null;
217
+ return (0, import_core2.toPaykitEvent)({
218
+ type: "$invoicePaid",
219
+ created: event2.created,
220
+ id: event2.id,
221
+ data: paykitInvoice$InboundSchema({ ...data, billingMode: "recurring" })
222
+ });
182
223
  },
183
224
  /**
184
225
  * Customer
185
226
  */
186
- "customer.created": (event2) => {
227
+ "customer.created": async (event2) => {
187
228
  const data = event2.data.object;
188
- return (0, import_core2.toPaykitEvent)({ type: "$customerCreated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
229
+ return (0, import_core2.toPaykitEvent)({ type: "$customerCreated", created: event2.created, id: event2.id, data: paykitCustomer$InboundSchema(data) });
189
230
  },
190
- "customer.updated": (event2) => {
231
+ "customer.updated": async (event2) => {
191
232
  const data = event2.data.object;
192
- return (0, import_core2.toPaykitEvent)({ type: "$customerUpdated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
233
+ return (0, import_core2.toPaykitEvent)({ type: "$customerUpdated", created: event2.created, id: event2.id, data: paykitCustomer$InboundSchema(data) });
193
234
  },
194
- "customer.deleted": (event2) => {
235
+ "customer.deleted": async (event2) => {
195
236
  return (0, import_core2.toPaykitEvent)({ type: "$customerDeleted", created: event2.created, id: event2.id, data: null });
196
237
  },
197
238
  /**
198
239
  * Subscription
199
240
  */
200
- "customer.subscription.created": (event2) => {
241
+ "customer.subscription.created": async (event2) => {
201
242
  const data = event2.data.object;
202
- return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCreated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
243
+ return (0, import_core2.toPaykitEvent)({
244
+ type: "$subscriptionCreated",
245
+ created: event2.created,
246
+ id: event2.id,
247
+ data: paykitSubscription$InboundSchema(data)
248
+ });
203
249
  },
204
- "customer.subscription.updated": (event2) => {
250
+ "customer.subscription.updated": async (event2) => {
205
251
  const data = event2.data.object;
206
- return (0, import_core2.toPaykitEvent)({ type: "$subscriptionUpdated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
252
+ return (0, import_core2.toPaykitEvent)({
253
+ type: "$subscriptionUpdated",
254
+ created: event2.created,
255
+ id: event2.id,
256
+ data: paykitSubscription$InboundSchema(data)
257
+ });
207
258
  },
208
- "customer.subscription.deleted": (event2) => {
259
+ "customer.subscription.deleted": async (event2) => {
209
260
  return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCancelled", created: event2.created, id: event2.id, data: null });
210
261
  }
211
262
  };
212
263
  const handler = webhookHandlers[event.type];
213
264
  if (!handler) throw new Error(`Unhandled event type: ${event.type}`);
214
- const result = handler(event);
265
+ const result = await handler(event);
215
266
  if (!result) throw new Error(`Unhandled event type: ${event.type}`);
216
267
  return result;
217
268
  };
package/dist/index.mjs CHANGED
@@ -10,21 +10,23 @@ import {
10
10
  import Stripe from "stripe";
11
11
 
12
12
  // lib/mapper.ts
13
- import { stringifyObjectValues } from "@paykit-sdk/core";
14
- var toPaykitCheckout = (checkout) => {
13
+ import {
14
+ stringifyObjectValues
15
+ } from "@paykit-sdk/core";
16
+ var paykitCheckout$InboundSchema = (checkout) => {
15
17
  return {
16
18
  id: checkout.id,
17
- customer_id: checkout.customer,
19
+ customer_id: typeof checkout.customer === "string" ? checkout.customer.toString() : checkout.customer?.id ?? "",
18
20
  session_type: checkout.mode === "subscription" ? "recurring" : "one_time",
19
- // todo: handle `setup` mode
20
21
  payment_url: checkout.url,
21
22
  products: checkout.line_items.data.map((item) => ({ id: item.price.id, quantity: item.quantity })),
22
23
  currency: checkout.currency,
23
24
  amount: checkout.amount_total,
24
- metadata: checkout.metadata
25
+ subscription: null,
26
+ metadata: stringifyObjectValues(checkout.metadata ?? {})
25
27
  };
26
28
  };
27
- var toPaykitCustomer = (customer) => {
29
+ var paykitCustomer$InboundSchema = (customer) => {
28
30
  return {
29
31
  id: customer.id,
30
32
  email: customer.email ?? void 0,
@@ -32,30 +34,60 @@ var toPaykitCustomer = (customer) => {
32
34
  metadata: stringifyObjectValues(customer.metadata ?? {})
33
35
  };
34
36
  };
35
- var toPaykitSubscriptionStatus = (status) => {
36
- if (["active", "trialing"].includes(status)) return "active";
37
- if (["incomplete_expired", "incomplete", "past_due"].includes(status)) return "past_due";
38
- if (["canceled"].includes(status)) return "canceled";
39
- if (["expired"].includes(status)) return "expired";
40
- throw new Error(`Unknown status: ${status}`);
41
- };
42
- var toPaykitSubscription = (subscription) => {
37
+ var paykitSubscription$InboundSchema = (subscription) => {
38
+ const status = (() => {
39
+ if (["active", "trialing"].includes(subscription.status)) return "active";
40
+ if (["incomplete_expired", "incomplete", "past_due"].includes(subscription.status)) return "past_due";
41
+ if (["canceled"].includes(subscription.status)) return "canceled";
42
+ if (["expired"].includes(subscription.status)) return "expired";
43
+ throw new Error(`Unknown status: ${subscription.status}`);
44
+ })();
43
45
  return {
44
46
  id: subscription.id,
47
+ status,
45
48
  customer_id: subscription.customer?.toString(),
46
- status: toPaykitSubscriptionStatus(subscription.status),
49
+ amount: subscription.items.data[0].price.unit_amount,
50
+ currency: subscription.items.data[0].price.currency,
51
+ item_id: subscription.items.data[0].id,
52
+ billing_interval: subscription.items.data[0].price.recurring?.interval,
53
+ billing_interval_count: subscription.items.data[0].price.recurring?.interval_count ?? 1,
47
54
  current_period_start: new Date(subscription.start_date),
48
55
  current_period_end: new Date(subscription.cancel_at),
49
- metadata: stringifyObjectValues(subscription.metadata ?? {})
56
+ metadata: stringifyObjectValues(subscription.metadata ?? {}),
57
+ /**
58
+ * todo: fix
59
+ */
60
+ custom_fields: null,
61
+ current_cycle: 0,
62
+ total_cycles: 0
50
63
  };
51
64
  };
52
- var toPaykitInvoice = (invoice) => {
65
+ var paykitInvoice$InboundSchema = (invoice) => {
66
+ const status = (() => {
67
+ if (invoice.status == "paid") return "paid";
68
+ if (["draft", "open", "uncollectible", "void"].includes(invoice.status)) return "open";
69
+ throw new Error(`Unknown status: ${invoice.status}`);
70
+ })();
71
+ const subscriptionId = /* @__PURE__ */ (() => {
72
+ return null;
73
+ })();
74
+ const customerId = (() => {
75
+ if (typeof invoice.customer === "string") return invoice.customer;
76
+ if (invoice.customer?.id) return invoice.customer.id;
77
+ throw new Error(`Unknown customer ID: ${invoice.customer}`);
78
+ })();
53
79
  return {
54
80
  id: invoice.id,
55
- amount: invoice.amount_paid,
56
81
  currency: invoice.currency,
82
+ customer_id: customerId,
83
+ billing_mode: invoice.billingMode,
84
+ amount_paid: invoice.amount_paid,
85
+ line_items: invoice.lines.data.map((line) => ({ id: line.id, quantity: line.quantity })),
86
+ subscription_id: subscriptionId,
87
+ status,
88
+ paid_at: new Date(invoice.created * 1e3).toISOString(),
57
89
  metadata: stringifyObjectValues(invoice.metadata ?? {}),
58
- customer_id: invoice.customer?.toString() ?? ""
90
+ custom_fields: invoice.custom_fields ?? null
59
91
  };
60
92
  };
61
93
 
@@ -66,31 +98,30 @@ var StripeProvider = class {
66
98
  * Checkout management
67
99
  */
68
100
  this.createCheckout = async (params) => {
69
- const { customer_id, item_id, metadata, session_type, provider_metadata } = params;
70
101
  const checkout = await this.stripe.checkout.sessions.create({
71
- customer: customer_id,
72
- mode: session_type === "one_time" ? "payment" : "subscription",
73
- ...session_type == "one_time" && { metadata },
74
- ...session_type == "recurring" && { subscription_data: { metadata } },
75
- line_items: [{ price: item_id }],
76
- ...provider_metadata
102
+ customer: params.customer_id,
103
+ mode: params.session_type === "one_time" ? "payment" : "subscription",
104
+ ...params.session_type == "one_time" && { metadata: stringifyObjectValues2(params.metadata ?? {}) },
105
+ ...params.session_type == "recurring" && { subscription_data: { metadata: stringifyObjectValues2(params.metadata ?? {}) } },
106
+ line_items: [{ price: params.item_id, quantity: params.quantity }],
107
+ ...params.provider_metadata
77
108
  });
78
- return toPaykitCheckout(checkout);
109
+ return paykitCheckout$InboundSchema(checkout);
79
110
  };
80
111
  this.retrieveCheckout = async (id) => {
81
112
  const checkout = await this.stripe.checkout.sessions.retrieve(id);
82
- return toPaykitCheckout(checkout);
113
+ return paykitCheckout$InboundSchema(checkout);
83
114
  };
84
115
  /**
85
116
  * Customer management
86
117
  */
87
118
  this.createCustomer = async (params) => {
88
119
  const customer = await this.stripe.customers.create(params);
89
- return toPaykitCustomer(customer);
120
+ return paykitCustomer$InboundSchema(customer);
90
121
  };
91
122
  this.updateCustomer = async (id, params) => {
92
123
  const customer = await this.stripe.customers.update(id, params);
93
- return toPaykitCustomer(customer);
124
+ return paykitCustomer$InboundSchema(customer);
94
125
  };
95
126
  this.deleteCustomer = async (id) => {
96
127
  await this.stripe.customers.del(id);
@@ -99,7 +130,7 @@ var StripeProvider = class {
99
130
  this.retrieveCustomer = async (id) => {
100
131
  const customer = await this.stripe.customers.retrieve(id);
101
132
  if ("deleted" in customer) return null;
102
- return toPaykitCustomer(customer);
133
+ return paykitCustomer$InboundSchema(customer);
103
134
  };
104
135
  /**
105
136
  * Subscription management
@@ -109,12 +140,12 @@ var StripeProvider = class {
109
140
  return null;
110
141
  };
111
142
  this.updateSubscription = async (id, params) => {
112
- const subscription = await this.stripe.subscriptions.update(id, { metadata: params.metadata });
113
- return toPaykitSubscription(subscription);
143
+ const subscription = await this.stripe.subscriptions.update(id, { metadata: stringifyObjectValues2(params.metadata ?? {}) });
144
+ return paykitSubscription$InboundSchema(subscription);
114
145
  };
115
146
  this.retrieveSubscription = async (id) => {
116
147
  const subscription = await this.stripe.subscriptions.retrieve(id);
117
- return toPaykitSubscription(subscription);
148
+ return paykitSubscription$InboundSchema(subscription);
118
149
  };
119
150
  /**
120
151
  * Webhook management
@@ -128,7 +159,7 @@ var StripeProvider = class {
128
159
  /**
129
160
  * Invoice
130
161
  */
131
- "checkout.session.completed": (event2) => {
162
+ "checkout.session.completed": async (event2) => {
132
163
  const data = event2.data.object;
133
164
  if (data.mode !== "payment") return null;
134
165
  return toPaykitEvent({
@@ -137,50 +168,72 @@ var StripeProvider = class {
137
168
  id: event2.id,
138
169
  data: {
139
170
  id: data.id,
140
- amount: data.amount_total ?? 0,
171
+ status: "paid",
172
+ paid_at: new Date(event2.created * 1e3).toISOString(),
173
+ amount_paid: data.amount_total ?? 0,
141
174
  currency: data.currency ?? "",
142
- metadata: stringifyObjectValues2({ ...data.metadata ?? {}, $mode: data.mode }),
143
- customer_id: data.customer?.toString() ?? ""
175
+ metadata: stringifyObjectValues2({ ...data.metadata ?? {} }),
176
+ customer_id: data.customer?.toString() ?? "",
177
+ billing_mode: "one_time",
178
+ subscription_id: null,
179
+ custom_fields: data.custom_fields ?? null,
180
+ line_items: data.line_items?.data.map((item) => ({ id: item.price.id, quantity: item.quantity })) ?? []
144
181
  }
145
182
  });
146
183
  },
147
- "invoice.paid": (event2) => {
184
+ "invoice.paid": async (event2) => {
148
185
  const data = event2.data.object;
149
- if (data.status !== "paid") return null;
150
- return toPaykitEvent({ type: "$invoicePaid", created: event2.created, id: event2.id, data: toPaykitInvoice(data) });
186
+ const relevantBillingReasons = ["subscription_create", "subscription_cycle"];
187
+ if (data.status !== "paid" && !relevantBillingReasons.includes(data.billing_reason)) return null;
188
+ return toPaykitEvent({
189
+ type: "$invoicePaid",
190
+ created: event2.created,
191
+ id: event2.id,
192
+ data: paykitInvoice$InboundSchema({ ...data, billingMode: "recurring" })
193
+ });
151
194
  },
152
195
  /**
153
196
  * Customer
154
197
  */
155
- "customer.created": (event2) => {
198
+ "customer.created": async (event2) => {
156
199
  const data = event2.data.object;
157
- return toPaykitEvent({ type: "$customerCreated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
200
+ return toPaykitEvent({ type: "$customerCreated", created: event2.created, id: event2.id, data: paykitCustomer$InboundSchema(data) });
158
201
  },
159
- "customer.updated": (event2) => {
202
+ "customer.updated": async (event2) => {
160
203
  const data = event2.data.object;
161
- return toPaykitEvent({ type: "$customerUpdated", created: event2.created, id: event2.id, data: toPaykitCustomer(data) });
204
+ return toPaykitEvent({ type: "$customerUpdated", created: event2.created, id: event2.id, data: paykitCustomer$InboundSchema(data) });
162
205
  },
163
- "customer.deleted": (event2) => {
206
+ "customer.deleted": async (event2) => {
164
207
  return toPaykitEvent({ type: "$customerDeleted", created: event2.created, id: event2.id, data: null });
165
208
  },
166
209
  /**
167
210
  * Subscription
168
211
  */
169
- "customer.subscription.created": (event2) => {
212
+ "customer.subscription.created": async (event2) => {
170
213
  const data = event2.data.object;
171
- return toPaykitEvent({ type: "$subscriptionCreated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
214
+ return toPaykitEvent({
215
+ type: "$subscriptionCreated",
216
+ created: event2.created,
217
+ id: event2.id,
218
+ data: paykitSubscription$InboundSchema(data)
219
+ });
172
220
  },
173
- "customer.subscription.updated": (event2) => {
221
+ "customer.subscription.updated": async (event2) => {
174
222
  const data = event2.data.object;
175
- return toPaykitEvent({ type: "$subscriptionUpdated", created: event2.created, id: event2.id, data: toPaykitSubscription(data) });
223
+ return toPaykitEvent({
224
+ type: "$subscriptionUpdated",
225
+ created: event2.created,
226
+ id: event2.id,
227
+ data: paykitSubscription$InboundSchema(data)
228
+ });
176
229
  },
177
- "customer.subscription.deleted": (event2) => {
230
+ "customer.subscription.deleted": async (event2) => {
178
231
  return toPaykitEvent({ type: "$subscriptionCancelled", created: event2.created, id: event2.id, data: null });
179
232
  }
180
233
  };
181
234
  const handler = webhookHandlers[event.type];
182
235
  if (!handler) throw new Error(`Unhandled event type: ${event.type}`);
183
- const result = handler(event);
236
+ const result = await handler(event);
184
237
  if (!result) throw new Error(`Unhandled event type: ${event.type}`);
185
238
  return result;
186
239
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/stripe",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Stripe provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -19,12 +19,12 @@
19
19
  "typescript"
20
20
  ],
21
21
  "author": "Emmanuel Odii",
22
- "license": "ISC",
22
+ "license": "GPL-3.0",
23
23
  "dependencies": {
24
24
  "stripe": "^18.2.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "@paykit-sdk/core": "^1.1.6"
27
+ "@paykit-sdk/core": "^1.1.8"
28
28
  },
29
29
  "devDependencies": {
30
30
  "tsup": "^8.0.0",