@paykit-sdk/stripe 1.1.9 → 1.1.93

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
@@ -27,7 +27,10 @@ export const endpoints = createEndpointHandlers(paykit);
27
27
  import { paykit } from '@/lib/paykit';
28
28
  import { EndpointPath } from '@paykit-sdk/core';
29
29
 
30
- export async function POST(request: NextRequest, { params }: { params: { endpoint: string[] } }) {
30
+ export async function POST(
31
+ request: NextRequest,
32
+ { params }: { params: { endpoint: string[] } },
33
+ ) {
31
34
  try {
32
35
  // Construct the endpoint path with full type safety
33
36
  const endpoint = ('/' + params.endpoint.join('/')) as EndpointPath;
@@ -106,46 +109,50 @@ const app = express();
106
109
 
107
110
  // IMPORTANT: Webhook route must come BEFORE express.json() middleware
108
111
  // This ensures we get the raw body for signature verification
109
- app.post('/api/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
110
- try {
111
- const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
112
-
113
- if (!webhookSecret) {
114
- return res.status(500).json({ error: 'Webhook secret not configured' });
115
- }
116
-
117
- const webhook = paykit.webhooks
118
- .setup({ webhookSecret })
119
- .on('customer.created', async event => {
120
- console.log('Customer created:', event.data);
121
- })
122
- .on('subscription.created', async event => {
123
- console.log('Subscription created:', event.data);
124
- })
125
- .on('payment.created', async event => {
126
- console.log('Payment created:', event.data);
127
- })
128
- .on('refund.created', async event => {
129
- console.log('Refund created:', event.data);
130
- })
131
- .on('invoice.generated', async event => {
132
- console.log('Invoice generated:', event.data);
112
+ app.post(
113
+ '/api/webhooks/stripe',
114
+ express.raw({ type: 'application/json' }),
115
+ async (req, res) => {
116
+ try {
117
+ const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
118
+
119
+ if (!webhookSecret) {
120
+ return res.status(500).json({ error: 'Webhook secret not configured' });
121
+ }
122
+
123
+ const webhook = paykit.webhooks
124
+ .setup({ webhookSecret })
125
+ .on('customer.created', async event => {
126
+ console.log('Customer created:', event.data);
127
+ })
128
+ .on('subscription.created', async event => {
129
+ console.log('Subscription created:', event.data);
130
+ })
131
+ .on('payment.created', async event => {
132
+ console.log('Payment created:', event.data);
133
+ })
134
+ .on('refund.created', async event => {
135
+ console.log('Refund created:', event.data);
136
+ })
137
+ .on('invoice.generated', async event => {
138
+ console.log('Invoice generated:', event.data);
139
+ });
140
+
141
+ const body = req.body; // Raw buffer from express.raw()
142
+ const headers = req.headers;
143
+ const url = request.url;
144
+ await webhook.handle({ body, headers, fullUrl: url });
145
+
146
+ // Return immediately, processing happens in background
147
+ res.json({ success: true });
148
+ } catch (error) {
149
+ console.error('Webhook error:', error);
150
+ res.status(500).json({
151
+ message: error instanceof Error ? error.message : 'Webhook processing failed',
133
152
  });
134
-
135
- const body = req.body; // Raw buffer from express.raw()
136
- const headers = req.headers;
137
- const url = request.url;
138
- await webhook.handle({ body, headers, fullUrl: url });
139
-
140
- // Return immediately, processing happens in background
141
- res.json({ success: true });
142
- } catch (error) {
143
- console.error('Webhook error:', error);
144
- res.status(500).json({
145
- message: error instanceof Error ? error.message : 'Webhook processing failed',
146
- });
147
- }
148
- });
153
+ }
154
+ },
155
+ );
149
156
 
150
157
  // Regular API routes use JSON middleware
151
158
  app.use(express.json());
@@ -200,4 +207,4 @@ STRIPE_WEBHOOK_SECRET=whsec_...
200
207
 
201
208
  ## License
202
209
 
203
- GPL-3.0
210
+ ISC