@paykit-sdk/paypal 1.0.5 → 1.0.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
@@ -35,11 +35,15 @@ export async function POST(
35
35
  ) {
36
36
  try {
37
37
  // Construct the endpoint path with full type safety
38
- const endpoint = ('/' + params.endpoint.join('/')) as EndpointPath;
38
+ const endpoint = ('/' +
39
+ params.endpoint.join('/')) as EndpointPath;
39
40
  const handler = endpoints[endpoint];
40
41
 
41
42
  if (!handler) {
42
- return NextResponse.json({ message: 'Endpoint not found' }, { status: 404 });
43
+ return NextResponse.json(
44
+ { message: 'Endpoint not found' },
45
+ { status: 404 },
46
+ );
43
47
  }
44
48
 
45
49
  // Parse request body
@@ -52,7 +56,12 @@ export async function POST(
52
56
  } catch (error) {
53
57
  console.error('PayKit API Error:', error);
54
58
  return NextResponse.json(
55
- { message: error instanceof Error ? error.message : 'Internal server error' },
59
+ {
60
+ message:
61
+ error instanceof Error
62
+ ? error.message
63
+ : 'Internal server error',
64
+ },
56
65
  { status: 500 },
57
66
  );
58
67
  }
@@ -69,7 +78,10 @@ export async function POST(request: NextRequest) {
69
78
  const webhookSecret = process.env.PAYPAL_WEBHOOK_ID;
70
79
 
71
80
  if (!webhookSecret) {
72
- return NextResponse.json({ error: 'Webhook secret not configured' }, { status: 500 });
81
+ return NextResponse.json(
82
+ { error: 'Webhook secret not configured' },
83
+ { status: 500 },
84
+ );
73
85
  }
74
86
 
75
87
  const webhook = paykit.webhooks
@@ -90,10 +102,15 @@ export async function POST(request: NextRequest) {
90
102
  const body = await request.text();
91
103
  const headers = Object.fromEntries(request.headers.entries());
92
104
  const url = request.url;
93
- await webhook.handle({ body, headers, fullUrl: url });
94
105
 
95
- // Return immediately, processing happens in background
96
- return NextResponse.json({ success: true });
106
+ try {
107
+ console.log('Webhook handled');
108
+ await webhook.handle({ body, headers, fullUrl: url });
109
+ return NextResponse.json({ success: true });
110
+ } catch (error) {
111
+ console.log('Webhook Error', error);
112
+ return NextResponse.json({ success: false });
113
+ }
97
114
  }
98
115
  ```
99
116
 
@@ -116,7 +133,9 @@ app.post(
116
133
  const webhookSecret = process.env.PAYPAL_WEBHOOK_ID;
117
134
 
118
135
  if (!webhookSecret) {
119
- return res.status(500).json({ error: 'Webhook secret not configured' });
136
+ return res
137
+ .status(500)
138
+ .json({ error: 'Webhook secret not configured' });
120
139
  }
121
140
 
122
141
  const webhook = paykit.webhooks
@@ -144,7 +163,10 @@ app.post(
144
163
  } catch (error) {
145
164
  console.error('Webhook error:', error);
146
165
  res.status(500).json({
147
- message: error instanceof Error ? error.message : 'Webhook processing failed',
166
+ message:
167
+ error instanceof Error
168
+ ? error.message
169
+ : 'Webhook processing failed',
148
170
  });
149
171
  }
150
172
  },
@@ -155,7 +177,10 @@ app.use(express.json());
155
177
 
156
178
  app.post('/api/paykit/*', async (req, res) => {
157
179
  try {
158
- const endpoint = req.path.replace('/api/paykit', '') as EndpointPath;
180
+ const endpoint = req.path.replace(
181
+ '/api/paykit',
182
+ '',
183
+ ) as EndpointPath;
159
184
  const handler = endpoints[endpoint];
160
185
 
161
186
  if (!handler) {
@@ -168,7 +193,10 @@ app.post('/api/paykit/*', async (req, res) => {
168
193
  res.json({ result });
169
194
  } catch (error) {
170
195
  res.status(500).json({
171
- message: error instanceof Error ? error.message : 'Internal server error',
196
+ message:
197
+ error instanceof Error
198
+ ? error.message
199
+ : 'Internal server error',
172
200
  });
173
201
  }
174
202
  });
@@ -21,7 +21,7 @@ declare class SubscriptionsController extends BaseController {
21
21
  };
22
22
  subscriptionId: string;
23
23
  }): Promise<void>;
24
- retrieveSubscription({ subscriptionId }: {
24
+ retrieveSubscription({ subscriptionId, }: {
25
25
  subscriptionId: string;
26
26
  }): Promise<ApiResponse<Subscription>>;
27
27
  cancelSubscription({ subscriptionId, reason, }: {
@@ -21,7 +21,7 @@ declare class SubscriptionsController extends BaseController {
21
21
  };
22
22
  subscriptionId: string;
23
23
  }): Promise<void>;
24
- retrieveSubscription({ subscriptionId }: {
24
+ retrieveSubscription({ subscriptionId, }: {
25
25
  subscriptionId: string;
26
26
  }): Promise<ApiResponse<Subscription>>;
27
27
  cancelSubscription({ subscriptionId, reason, }: {
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var paypalServerSdk = require('@paypal/paypal-server-sdk');
4
- var baseController = require('@paypal/paypal-server-sdk/dist/types/controllers/baseController');
5
- var schema = require('@paypal/paypal-server-sdk/dist/types/schema');
4
+ var baseController = require('@paypal/paypal-server-sdk/dist/cjs/controllers/baseController');
5
+ var schema = require('@paypal/paypal-server-sdk/dist/cjs/schema');
6
6
 
7
7
  // src/controllers/subscription.ts
8
8
  schema.object({
@@ -30,7 +30,9 @@ var createSubscriptionApticSchema = schema.object({
30
30
  ],
31
31
  phone: [
32
32
  "phone",
33
- schema.lazy(() => schema.object({ phone_number: ["phone_number", schema.string()] }))
33
+ schema.lazy(
34
+ () => schema.object({ phone_number: ["phone_number", schema.string()] })
35
+ )
34
36
  ]
35
37
  })
36
38
  )
@@ -83,7 +85,10 @@ var VerifyWebhookStatus = /* @__PURE__ */ ((VerifyWebhookStatus2) => {
83
85
  return VerifyWebhookStatus2;
84
86
  })(VerifyWebhookStatus || {});
85
87
  schema.object({
86
- verification_status: ["verification_status", schema.stringEnum(VerifyWebhookStatus)]
88
+ verification_status: [
89
+ "verification_status",
90
+ schema.stringEnum(VerifyWebhookStatus)
91
+ ]
87
92
  });
88
93
 
89
94
  // src/controllers/subscription.ts
@@ -111,10 +116,18 @@ var SubscriptionsController = class extends baseController.BaseController {
111
116
  async createSubscription({
112
117
  body
113
118
  }) {
114
- const req = this.createRequest("POST", "/v1/billing/subscriptions");
115
- const mapped = req.prepareArgs({ body: [body, createSubscriptionApticSchema] });
119
+ const req = this.createRequest(
120
+ "POST",
121
+ "/v1/billing/subscriptions"
122
+ );
123
+ const mapped = req.prepareArgs({
124
+ body: [body, createSubscriptionApticSchema]
125
+ });
116
126
  req.header("Content-Type", "application/json");
117
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
127
+ req.header(
128
+ "PayPal-Request-Id",
129
+ Math.random().toString(36).substring(2, 15)
130
+ );
118
131
  req.json(mapped.body);
119
132
  this.catchAllErrors(req);
120
133
  req.authenticate([{ oauth2: true }]);
@@ -135,14 +148,25 @@ var SubscriptionsController = class extends baseController.BaseController {
135
148
  body: [body, resumeSubscriptionApticSchemaRequest]
136
149
  });
137
150
  req.header("Content-Type", "application/json");
138
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
151
+ req.header(
152
+ "PayPal-Request-Id",
153
+ Math.random().toString(36).substring(2, 15)
154
+ );
139
155
  req.json(mapped.body);
140
156
  this.catchAllErrors(req);
141
157
  req.authenticate([{ oauth2: true }]);
142
158
  }
143
- async retrieveSubscription({ subscriptionId }) {
144
- const req = this.createRequest("GET", `v1/billing/subscriptions/${subscriptionId}`);
145
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
159
+ async retrieveSubscription({
160
+ subscriptionId
161
+ }) {
162
+ const req = this.createRequest(
163
+ "GET",
164
+ `v1/billing/subscriptions/${subscriptionId}`
165
+ );
166
+ req.header(
167
+ "PayPal-Request-Id",
168
+ Math.random().toString(36).substring(2, 15)
169
+ );
146
170
  this.catchAllErrors(req);
147
171
  req.authenticate([{ oauth2: true }]);
148
172
  return req.callAsJson(subscriptionApticSchema);
@@ -158,7 +182,10 @@ var SubscriptionsController = class extends baseController.BaseController {
158
182
  const mapped = req.prepareArgs({
159
183
  body: [reason, resumeSubscriptionApticSchemaRequest]
160
184
  });
161
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
185
+ req.header(
186
+ "PayPal-Request-Id",
187
+ Math.random().toString(36).substring(2, 15)
188
+ );
162
189
  req.json(mapped.body);
163
190
  this.catchAllErrors(req);
164
191
  req.authenticate([{ oauth2: true }]);
@@ -168,9 +195,19 @@ var SubscriptionsController = class extends baseController.BaseController {
168
195
  subscriptionId,
169
196
  metadata
170
197
  }) {
171
- const req = this.createRequest("PATCH", `v1/billing/subscriptions/${subscriptionId}`);
172
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
173
- req.json({ op: "replace", path: "/custom_id", value: JSON.stringify(metadata) });
198
+ const req = this.createRequest(
199
+ "PATCH",
200
+ `v1/billing/subscriptions/${subscriptionId}`
201
+ );
202
+ req.header(
203
+ "PayPal-Request-Id",
204
+ Math.random().toString(36).substring(2, 15)
205
+ );
206
+ req.json({
207
+ op: "replace",
208
+ path: "/custom_id",
209
+ value: JSON.stringify(metadata)
210
+ });
174
211
  this.catchAllErrors(req);
175
212
  req.authenticate([{ oauth2: true }]);
176
213
  }
@@ -1,6 +1,6 @@
1
1
  import { CustomError } from '@paypal/paypal-server-sdk';
2
- import { BaseController } from '@paypal/paypal-server-sdk/dist/types/controllers/baseController';
3
- import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/types/schema';
2
+ import { BaseController } from '@paypal/paypal-server-sdk/dist/cjs/controllers/baseController';
3
+ import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/cjs/schema';
4
4
 
5
5
  // src/controllers/subscription.ts
6
6
  object({
@@ -28,7 +28,9 @@ var createSubscriptionApticSchema = object({
28
28
  ],
29
29
  phone: [
30
30
  "phone",
31
- lazy(() => object({ phone_number: ["phone_number", string()] }))
31
+ lazy(
32
+ () => object({ phone_number: ["phone_number", string()] })
33
+ )
32
34
  ]
33
35
  })
34
36
  )
@@ -81,7 +83,10 @@ var VerifyWebhookStatus = /* @__PURE__ */ ((VerifyWebhookStatus2) => {
81
83
  return VerifyWebhookStatus2;
82
84
  })(VerifyWebhookStatus || {});
83
85
  object({
84
- verification_status: ["verification_status", stringEnum(VerifyWebhookStatus)]
86
+ verification_status: [
87
+ "verification_status",
88
+ stringEnum(VerifyWebhookStatus)
89
+ ]
85
90
  });
86
91
 
87
92
  // src/controllers/subscription.ts
@@ -109,10 +114,18 @@ var SubscriptionsController = class extends BaseController {
109
114
  async createSubscription({
110
115
  body
111
116
  }) {
112
- const req = this.createRequest("POST", "/v1/billing/subscriptions");
113
- const mapped = req.prepareArgs({ body: [body, createSubscriptionApticSchema] });
117
+ const req = this.createRequest(
118
+ "POST",
119
+ "/v1/billing/subscriptions"
120
+ );
121
+ const mapped = req.prepareArgs({
122
+ body: [body, createSubscriptionApticSchema]
123
+ });
114
124
  req.header("Content-Type", "application/json");
115
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
125
+ req.header(
126
+ "PayPal-Request-Id",
127
+ Math.random().toString(36).substring(2, 15)
128
+ );
116
129
  req.json(mapped.body);
117
130
  this.catchAllErrors(req);
118
131
  req.authenticate([{ oauth2: true }]);
@@ -133,14 +146,25 @@ var SubscriptionsController = class extends BaseController {
133
146
  body: [body, resumeSubscriptionApticSchemaRequest]
134
147
  });
135
148
  req.header("Content-Type", "application/json");
136
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
149
+ req.header(
150
+ "PayPal-Request-Id",
151
+ Math.random().toString(36).substring(2, 15)
152
+ );
137
153
  req.json(mapped.body);
138
154
  this.catchAllErrors(req);
139
155
  req.authenticate([{ oauth2: true }]);
140
156
  }
141
- async retrieveSubscription({ subscriptionId }) {
142
- const req = this.createRequest("GET", `v1/billing/subscriptions/${subscriptionId}`);
143
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
157
+ async retrieveSubscription({
158
+ subscriptionId
159
+ }) {
160
+ const req = this.createRequest(
161
+ "GET",
162
+ `v1/billing/subscriptions/${subscriptionId}`
163
+ );
164
+ req.header(
165
+ "PayPal-Request-Id",
166
+ Math.random().toString(36).substring(2, 15)
167
+ );
144
168
  this.catchAllErrors(req);
145
169
  req.authenticate([{ oauth2: true }]);
146
170
  return req.callAsJson(subscriptionApticSchema);
@@ -156,7 +180,10 @@ var SubscriptionsController = class extends BaseController {
156
180
  const mapped = req.prepareArgs({
157
181
  body: [reason, resumeSubscriptionApticSchemaRequest]
158
182
  });
159
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
183
+ req.header(
184
+ "PayPal-Request-Id",
185
+ Math.random().toString(36).substring(2, 15)
186
+ );
160
187
  req.json(mapped.body);
161
188
  this.catchAllErrors(req);
162
189
  req.authenticate([{ oauth2: true }]);
@@ -166,9 +193,19 @@ var SubscriptionsController = class extends BaseController {
166
193
  subscriptionId,
167
194
  metadata
168
195
  }) {
169
- const req = this.createRequest("PATCH", `v1/billing/subscriptions/${subscriptionId}`);
170
- req.header("PayPal-Request-Id", Math.random().toString(36).substring(2, 15));
171
- req.json({ op: "replace", path: "/custom_id", value: JSON.stringify(metadata) });
196
+ const req = this.createRequest(
197
+ "PATCH",
198
+ `v1/billing/subscriptions/${subscriptionId}`
199
+ );
200
+ req.header(
201
+ "PayPal-Request-Id",
202
+ Math.random().toString(36).substring(2, 15)
203
+ );
204
+ req.json({
205
+ op: "replace",
206
+ path: "/custom_id",
207
+ value: JSON.stringify(metadata)
208
+ });
172
209
  this.catchAllErrors(req);
173
210
  req.authenticate([{ oauth2: true }]);
174
211
  }
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var paypalServerSdk = require('@paypal/paypal-server-sdk');
4
- var baseController = require('@paypal/paypal-server-sdk/dist/types/controllers/baseController');
5
- var schema = require('@paypal/paypal-server-sdk/dist/types/schema');
4
+ var baseController = require('@paypal/paypal-server-sdk/dist/cjs/controllers/baseController');
5
+ var schema = require('@paypal/paypal-server-sdk/dist/cjs/schema');
6
6
 
7
7
  // src/controllers/webhook.ts
8
8
  schema.object({
@@ -30,7 +30,9 @@ schema.object({
30
30
  ],
31
31
  phone: [
32
32
  "phone",
33
- schema.lazy(() => schema.object({ phone_number: ["phone_number", schema.string()] }))
33
+ schema.lazy(
34
+ () => schema.object({ phone_number: ["phone_number", schema.string()] })
35
+ )
34
36
  ]
35
37
  })
36
38
  )
@@ -83,13 +85,19 @@ var VerifyWebhookStatus = /* @__PURE__ */ ((VerifyWebhookStatus2) => {
83
85
  return VerifyWebhookStatus2;
84
86
  })(VerifyWebhookStatus || {});
85
87
  var verifyWebhookSchema = schema.object({
86
- verification_status: ["verification_status", schema.stringEnum(VerifyWebhookStatus)]
88
+ verification_status: [
89
+ "verification_status",
90
+ schema.stringEnum(VerifyWebhookStatus)
91
+ ]
87
92
  });
88
93
 
89
94
  // src/controllers/webhook.ts
90
95
  var WebhookController = class extends baseController.BaseController {
91
96
  async verifyWebhook(body) {
92
- const req = this.createRequest("POST", "/v1/notifications/verify-webhook-signature");
97
+ const req = this.createRequest(
98
+ "POST",
99
+ "/v1/notifications/verify-webhook-signature"
100
+ );
93
101
  req.header("Content-Type", "application/json");
94
102
  req.throwOn(
95
103
  400,
@@ -1,6 +1,6 @@
1
1
  import { CustomError } from '@paypal/paypal-server-sdk';
2
- import { BaseController } from '@paypal/paypal-server-sdk/dist/types/controllers/baseController';
3
- import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/types/schema';
2
+ import { BaseController } from '@paypal/paypal-server-sdk/dist/cjs/controllers/baseController';
3
+ import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/cjs/schema';
4
4
 
5
5
  // src/controllers/webhook.ts
6
6
  object({
@@ -28,7 +28,9 @@ object({
28
28
  ],
29
29
  phone: [
30
30
  "phone",
31
- lazy(() => object({ phone_number: ["phone_number", string()] }))
31
+ lazy(
32
+ () => object({ phone_number: ["phone_number", string()] })
33
+ )
32
34
  ]
33
35
  })
34
36
  )
@@ -81,13 +83,19 @@ var VerifyWebhookStatus = /* @__PURE__ */ ((VerifyWebhookStatus2) => {
81
83
  return VerifyWebhookStatus2;
82
84
  })(VerifyWebhookStatus || {});
83
85
  var verifyWebhookSchema = object({
84
- verification_status: ["verification_status", stringEnum(VerifyWebhookStatus)]
86
+ verification_status: [
87
+ "verification_status",
88
+ stringEnum(VerifyWebhookStatus)
89
+ ]
85
90
  });
86
91
 
87
92
  // src/controllers/webhook.ts
88
93
  var WebhookController = class extends BaseController {
89
94
  async verifyWebhook(body) {
90
- const req = this.createRequest("POST", "/v1/notifications/verify-webhook-signature");
95
+ const req = this.createRequest(
96
+ "POST",
97
+ "/v1/notifications/verify-webhook-signature"
98
+ );
91
99
  req.header("Content-Type", "application/json");
92
100
  req.throwOn(
93
101
  400,
package/dist/index.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PayPalProvider, PayPalOptions } from './paypal-provider.mjs';
2
2
  import '@paykit-sdk/core';
3
+ import '@paypal/paypal-server-sdk';
4
+ import './types.mjs';
3
5
 
4
6
  declare const paypal: () => PayPalProvider;
5
7
  declare const createPayPal: (config: PayPalOptions) => PayPalProvider;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PayPalProvider, PayPalOptions } from './paypal-provider.js';
2
2
  import '@paykit-sdk/core';
3
+ import '@paypal/paypal-server-sdk';
4
+ import './types.js';
3
5
 
4
6
  declare const paypal: () => PayPalProvider;
5
7
  declare const createPayPal: (config: PayPalOptions) => PayPalProvider;