@paykit-sdk/stripe 1.1.103 → 1.1.105

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
@@ -33,11 +33,15 @@ export async function POST(
33
33
  ) {
34
34
  try {
35
35
  // Construct the endpoint path with full type safety
36
- const endpoint = ('/' + params.endpoint.join('/')) as EndpointPath;
36
+ const endpoint = ('/' +
37
+ params.endpoint.join('/')) as EndpointPath;
37
38
  const handler = endpoints[endpoint];
38
39
 
39
40
  if (!handler) {
40
- return NextResponse.json({ message: 'Endpoint not found' }, { status: 404 });
41
+ return NextResponse.json(
42
+ { message: 'Endpoint not found' },
43
+ { status: 404 },
44
+ );
41
45
  }
42
46
 
43
47
  // Parse request body
@@ -50,7 +54,12 @@ export async function POST(
50
54
  } catch (error) {
51
55
  console.error('PayKit API Error:', error);
52
56
  return NextResponse.json(
53
- { message: error instanceof Error ? error.message : 'Internal server error' },
57
+ {
58
+ message:
59
+ error instanceof Error
60
+ ? error.message
61
+ : 'Internal server error',
62
+ },
54
63
  { status: 500 },
55
64
  );
56
65
  }
@@ -90,11 +99,16 @@ export async function POST(request: NextRequest) {
90
99
 
91
100
  const body = await request.text();
92
101
  const headers = Object.fromEntries(request.headers.entries());
93
- const url = request.url
94
- await webhook.handle({ body, headers, fullUrl: url });
102
+ const url = request.url;
95
103
 
96
- // Return immediately, processing happens in background
97
- return NextResponse.json({ success: true });
104
+ try {
105
+ console.log('Webhook handled');
106
+ await webhook.handle({ body, headers, fullUrl: url });
107
+ return NextResponse.json({ success: true });
108
+ } catch (error) {
109
+ console.log('Webhook Error', error);
110
+ return NextResponse.json({ success: false });
111
+ }
98
112
  }
99
113
  ```
100
114
 
@@ -102,7 +116,10 @@ export async function POST(request: NextRequest) {
102
116
 
103
117
  ```typescript
104
118
  import { paykit, endpoints } from '@/lib/paykit';
105
- import { createEndpointHandlers, EndpointPath } from '@paykit-sdk/core';
119
+ import {
120
+ createEndpointHandlers,
121
+ EndpointPath,
122
+ } from '@paykit-sdk/core';
106
123
  import express from 'express';
107
124
 
108
125
  const app = express();
@@ -117,7 +134,9 @@ app.post(
117
134
  const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
118
135
 
119
136
  if (!webhookSecret) {
120
- return res.status(500).json({ error: 'Webhook secret not configured' });
137
+ return res
138
+ .status(500)
139
+ .json({ error: 'Webhook secret not configured' });
121
140
  }
122
141
 
123
142
  const webhook = paykit.webhooks
@@ -148,7 +167,10 @@ app.post(
148
167
  } catch (error) {
149
168
  console.error('Webhook error:', error);
150
169
  res.status(500).json({
151
- message: error instanceof Error ? error.message : 'Webhook processing failed',
170
+ message:
171
+ error instanceof Error
172
+ ? error.message
173
+ : 'Webhook processing failed',
152
174
  });
153
175
  }
154
176
  },
@@ -159,7 +181,10 @@ app.use(express.json());
159
181
 
160
182
  app.post('/api/paykit/*', async (req, res) => {
161
183
  try {
162
- const endpoint = req.path.replace('/api/paykit', '') as EndpointPath;
184
+ const endpoint = req.path.replace(
185
+ '/api/paykit',
186
+ '',
187
+ ) as EndpointPath;
163
188
  const handler = endpoints[endpoint];
164
189
 
165
190
  if (!handler) {
@@ -172,7 +197,10 @@ app.post('/api/paykit/*', async (req, res) => {
172
197
  res.json({ result });
173
198
  } catch (error) {
174
199
  res.status(500).json({
175
- message: error instanceof Error ? error.message : 'Internal server error',
200
+ message:
201
+ error instanceof Error
202
+ ? error.message
203
+ : 'Internal server error',
176
204
  });
177
205
  }
178
206
  });