@paykit-sdk/paypal 1.0.1 → 1.0.3
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/controllers/subscription.d.mts +37 -0
- package/dist/controllers/subscription.d.ts +37 -0
- package/dist/controllers/subscription.js +179 -0
- package/dist/controllers/subscription.mjs +177 -0
- package/dist/controllers/webhook.d.mts +18 -0
- package/dist/controllers/webhook.d.ts +18 -0
- package/dist/controllers/webhook.js +122 -0
- package/dist/controllers/webhook.mjs +120 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4669 -0
- package/dist/index.mjs +4666 -0
- package/dist/paypal-provider.d.mts +66 -0
- package/dist/paypal-provider.d.ts +66 -0
- package/dist/paypal-provider.js +4651 -0
- package/dist/paypal-provider.mjs +4649 -0
- package/dist/schema.d.mts +138 -0
- package/dist/schema.d.ts +138 -0
- package/dist/schema.js +92 -0
- package/dist/schema.mjs +85 -0
- package/dist/types.d.mts +108 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +2 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/mapper.d.mts +22 -0
- package/dist/utils/mapper.d.ts +22 -0
- package/dist/utils/mapper.js +77 -0
- package/dist/utils/mapper.mjs +72 -0
- package/package.json +35 -13
- package/CHANGELOG.md +0 -9
- package/src/controllers/subscription.ts +0 -118
- package/src/controllers/webhook.ts +0 -45
- package/src/index.ts +0 -20
- package/src/paypal-provider.ts +0 -504
- package/src/schema.ts +0 -230
- package/src/types.ts +0 -126
- package/src/utils/mapper.ts +0 -111
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Refund as Refund$1, Checkout, Payment, Subscription } from '@paykit-sdk/core';
|
|
2
|
+
import { Refund, Order } from '@paypal/paypal-server-sdk';
|
|
3
|
+
import { PayPalSubscription } from '../types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Refund
|
|
7
|
+
*/
|
|
8
|
+
declare const paykitRefund$InboundSchema: (refund: Refund) => Refund$1;
|
|
9
|
+
/**
|
|
10
|
+
* Checkout
|
|
11
|
+
*/
|
|
12
|
+
declare const paykitCheckout$InboundSchema: (order: Order) => Checkout;
|
|
13
|
+
/**
|
|
14
|
+
* Payment
|
|
15
|
+
*/
|
|
16
|
+
declare const paykitPayment$InboundSchema: (order: Order) => Payment;
|
|
17
|
+
/**
|
|
18
|
+
* Subscription
|
|
19
|
+
*/
|
|
20
|
+
declare const paykitSubscription$InboundSchema: (subscription: PayPalSubscription) => Subscription;
|
|
21
|
+
|
|
22
|
+
export { paykitCheckout$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@paykit-sdk/core');
|
|
4
|
+
|
|
5
|
+
// src/utils/mapper.ts
|
|
6
|
+
var paykitRefund$InboundSchema = (refund) => {
|
|
7
|
+
return {
|
|
8
|
+
id: refund.id,
|
|
9
|
+
amount: refund.amount?.value ? parseFloat(refund.amount.value) : 0,
|
|
10
|
+
currency: refund.amount?.currencyCode || "USD",
|
|
11
|
+
metadata: refund.customId ? core.omitInternalMetadata(JSON.parse(refund.customId)) : {},
|
|
12
|
+
reason: refund.noteToPayer ?? null
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var paykitCheckout$InboundSchema = (order) => {
|
|
16
|
+
return {
|
|
17
|
+
id: order.id,
|
|
18
|
+
payment_url: order.links?.find((l) => l.rel === "approve")?.href || "",
|
|
19
|
+
amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
|
|
20
|
+
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
21
|
+
customer: order.payer?.payerId ? order.payer?.payerId : { email: order.payer?.emailAddress ?? "" },
|
|
22
|
+
session_type: "one_time",
|
|
23
|
+
products: [{ id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "", quantity: 1 }],
|
|
24
|
+
metadata: order.purchaseUnits?.[0]?.customId ? core.omitInternalMetadata(JSON.parse(order.purchaseUnits?.[0]?.customId)) : {},
|
|
25
|
+
subscription: null
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
var paykitPayment$InboundSchema = (order) => {
|
|
29
|
+
const statusMap = {
|
|
30
|
+
CREATED: "pending",
|
|
31
|
+
SAVED: "pending",
|
|
32
|
+
APPROVED: "requires_capture",
|
|
33
|
+
VOIDED: "canceled",
|
|
34
|
+
COMPLETED: "succeeded",
|
|
35
|
+
PAYER_ACTION_REQUIRED: "requires_action"
|
|
36
|
+
};
|
|
37
|
+
const status = statusMap[order.status ?? statusMap.CREATED];
|
|
38
|
+
return {
|
|
39
|
+
id: order.id,
|
|
40
|
+
status,
|
|
41
|
+
amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
|
|
42
|
+
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
43
|
+
metadata: order.purchaseUnits?.[0]?.customId ? core.omitInternalMetadata(JSON.parse(order.purchaseUnits?.[0]?.customId)) : {},
|
|
44
|
+
customer: order.payer?.payerId ? order.payer?.payerId : { email: order.payer?.emailAddress ?? "" },
|
|
45
|
+
item_id: order.purchaseUnits?.[0]?.items?.[0]?.sku || ""
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var paykitSubscription$InboundSchema = (subscription) => {
|
|
49
|
+
const statusMap = {
|
|
50
|
+
APPROVAL_PENDING: "pending",
|
|
51
|
+
APPROVED: "active",
|
|
52
|
+
ACTIVE: "active",
|
|
53
|
+
SUSPENDED: "past_due",
|
|
54
|
+
CANCELLED: "canceled",
|
|
55
|
+
EXPIRED: "canceled"
|
|
56
|
+
};
|
|
57
|
+
const status = statusMap[subscription.status ?? statusMap.APPROVAL_PENDING];
|
|
58
|
+
return {
|
|
59
|
+
id: subscription.id,
|
|
60
|
+
customer: { email: subscription.subscriber?.email_address ?? "" },
|
|
61
|
+
status,
|
|
62
|
+
item_id: subscription.plan_id,
|
|
63
|
+
current_period_start: subscription.start_time ? new Date(subscription.start_time) : /* @__PURE__ */ new Date(),
|
|
64
|
+
current_period_end: subscription.status_update_time ? new Date(subscription.status_update_time) : /* @__PURE__ */ new Date(),
|
|
65
|
+
// todo: Would need to calculate based on billing cycle
|
|
66
|
+
metadata: subscription.customId ? core.omitInternalMetadata(JSON.parse(subscription.customId)) : {},
|
|
67
|
+
billing_interval: "month",
|
|
68
|
+
amount: 0,
|
|
69
|
+
currency: "USD",
|
|
70
|
+
custom_fields: null
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.paykitCheckout$InboundSchema = paykitCheckout$InboundSchema;
|
|
75
|
+
exports.paykitPayment$InboundSchema = paykitPayment$InboundSchema;
|
|
76
|
+
exports.paykitRefund$InboundSchema = paykitRefund$InboundSchema;
|
|
77
|
+
exports.paykitSubscription$InboundSchema = paykitSubscription$InboundSchema;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { omitInternalMetadata } from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
// src/utils/mapper.ts
|
|
4
|
+
var paykitRefund$InboundSchema = (refund) => {
|
|
5
|
+
return {
|
|
6
|
+
id: refund.id,
|
|
7
|
+
amount: refund.amount?.value ? parseFloat(refund.amount.value) : 0,
|
|
8
|
+
currency: refund.amount?.currencyCode || "USD",
|
|
9
|
+
metadata: refund.customId ? omitInternalMetadata(JSON.parse(refund.customId)) : {},
|
|
10
|
+
reason: refund.noteToPayer ?? null
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
var paykitCheckout$InboundSchema = (order) => {
|
|
14
|
+
return {
|
|
15
|
+
id: order.id,
|
|
16
|
+
payment_url: order.links?.find((l) => l.rel === "approve")?.href || "",
|
|
17
|
+
amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
|
|
18
|
+
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
19
|
+
customer: order.payer?.payerId ? order.payer?.payerId : { email: order.payer?.emailAddress ?? "" },
|
|
20
|
+
session_type: "one_time",
|
|
21
|
+
products: [{ id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "", quantity: 1 }],
|
|
22
|
+
metadata: order.purchaseUnits?.[0]?.customId ? omitInternalMetadata(JSON.parse(order.purchaseUnits?.[0]?.customId)) : {},
|
|
23
|
+
subscription: null
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var paykitPayment$InboundSchema = (order) => {
|
|
27
|
+
const statusMap = {
|
|
28
|
+
CREATED: "pending",
|
|
29
|
+
SAVED: "pending",
|
|
30
|
+
APPROVED: "requires_capture",
|
|
31
|
+
VOIDED: "canceled",
|
|
32
|
+
COMPLETED: "succeeded",
|
|
33
|
+
PAYER_ACTION_REQUIRED: "requires_action"
|
|
34
|
+
};
|
|
35
|
+
const status = statusMap[order.status ?? statusMap.CREATED];
|
|
36
|
+
return {
|
|
37
|
+
id: order.id,
|
|
38
|
+
status,
|
|
39
|
+
amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
|
|
40
|
+
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
41
|
+
metadata: order.purchaseUnits?.[0]?.customId ? omitInternalMetadata(JSON.parse(order.purchaseUnits?.[0]?.customId)) : {},
|
|
42
|
+
customer: order.payer?.payerId ? order.payer?.payerId : { email: order.payer?.emailAddress ?? "" },
|
|
43
|
+
item_id: order.purchaseUnits?.[0]?.items?.[0]?.sku || ""
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var paykitSubscription$InboundSchema = (subscription) => {
|
|
47
|
+
const statusMap = {
|
|
48
|
+
APPROVAL_PENDING: "pending",
|
|
49
|
+
APPROVED: "active",
|
|
50
|
+
ACTIVE: "active",
|
|
51
|
+
SUSPENDED: "past_due",
|
|
52
|
+
CANCELLED: "canceled",
|
|
53
|
+
EXPIRED: "canceled"
|
|
54
|
+
};
|
|
55
|
+
const status = statusMap[subscription.status ?? statusMap.APPROVAL_PENDING];
|
|
56
|
+
return {
|
|
57
|
+
id: subscription.id,
|
|
58
|
+
customer: { email: subscription.subscriber?.email_address ?? "" },
|
|
59
|
+
status,
|
|
60
|
+
item_id: subscription.plan_id,
|
|
61
|
+
current_period_start: subscription.start_time ? new Date(subscription.start_time) : /* @__PURE__ */ new Date(),
|
|
62
|
+
current_period_end: subscription.status_update_time ? new Date(subscription.status_update_time) : /* @__PURE__ */ new Date(),
|
|
63
|
+
// todo: Would need to calculate based on billing cycle
|
|
64
|
+
metadata: subscription.customId ? omitInternalMetadata(JSON.parse(subscription.customId)) : {},
|
|
65
|
+
billing_interval: "month",
|
|
66
|
+
amount: 0,
|
|
67
|
+
currency: "USD",
|
|
68
|
+
custom_fields: null
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { paykitCheckout$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
package/package.json
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/paypal",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "PayPal provider for PayKit",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"paypal",
|
|
16
|
+
"paykit",
|
|
17
|
+
"payment",
|
|
18
|
+
"typescript"
|
|
19
|
+
],
|
|
7
20
|
"author": "Emmanuel Odii",
|
|
8
21
|
"license": "ISC",
|
|
9
|
-
"peerDependencies": {
|
|
10
|
-
"@paykit-sdk/core": ">=1.1.93"
|
|
11
|
-
},
|
|
12
22
|
"devDependencies": {
|
|
13
|
-
"@paykit-sdk/core": "
|
|
23
|
+
"@paykit-sdk/core": "workspace:*",
|
|
24
|
+
"tsup": "^8.5.0",
|
|
25
|
+
"typescript": "^5.9.2",
|
|
26
|
+
"zod": "^3.24.2"
|
|
14
27
|
},
|
|
15
28
|
"dependencies": {
|
|
16
|
-
"@paypal/paypal-server-sdk": "^1.1.0"
|
|
17
|
-
"zod": "^3.24.2"
|
|
29
|
+
"@paypal/paypal-server-sdk": "^1.1.0"
|
|
18
30
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@paykit-sdk/core": ">=1.1.95"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/usepaykit/paykit-sdk.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/usepaykit/paykit-sdk/issues"
|
|
21
43
|
}
|
|
22
|
-
}
|
|
44
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { CreateSubscriptionSchema } from '@paykit-sdk/core';
|
|
2
|
-
import { ApiResponse, CustomError } from '@paypal/paypal-server-sdk';
|
|
3
|
-
import { BaseController } from '@paypal/paypal-server-sdk/dist/types/controllers/baseController';
|
|
4
|
-
import {
|
|
5
|
-
createSubscriptionApticSchema,
|
|
6
|
-
resumeSubscriptionApticSchemaRequest,
|
|
7
|
-
resumeSubscriptionApticSchemaRequest as cancelSubscriptionApticSchemaRequest,
|
|
8
|
-
subscriptionApticSchema,
|
|
9
|
-
} from '../schema';
|
|
10
|
-
|
|
11
|
-
export class SubscriptionsController extends BaseController {
|
|
12
|
-
private catchAllErrors(req: ReturnType<BaseController['createRequest']>) {
|
|
13
|
-
req.throwOn(
|
|
14
|
-
400,
|
|
15
|
-
CustomError,
|
|
16
|
-
'Request is not well-formed, syntactically incorrect, or violates schema.',
|
|
17
|
-
);
|
|
18
|
-
req.throwOn(
|
|
19
|
-
401,
|
|
20
|
-
CustomError,
|
|
21
|
-
'Authentication failed due to missing authorization header, or invalid authentication credentials.',
|
|
22
|
-
);
|
|
23
|
-
req.throwOn(
|
|
24
|
-
422,
|
|
25
|
-
CustomError,
|
|
26
|
-
'The requested action could not be performed, semantically incorrect, or failed business validation.',
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @return Response from the API call
|
|
32
|
-
*/
|
|
33
|
-
async createSubscription({
|
|
34
|
-
body,
|
|
35
|
-
}: {
|
|
36
|
-
body: CreateSubscriptionSchema;
|
|
37
|
-
}): Promise<ApiResponse<any>> {
|
|
38
|
-
const req = this.createRequest('POST', '/v1/billing/subscriptions');
|
|
39
|
-
const mapped = req.prepareArgs({ body: [body, createSubscriptionApticSchema] });
|
|
40
|
-
req.header('Content-Type', 'application/json');
|
|
41
|
-
req.header('PayPal-Request-Id', Math.random().toString(36).substring(2, 15));
|
|
42
|
-
|
|
43
|
-
req.json(mapped.body);
|
|
44
|
-
this.catchAllErrors(req);
|
|
45
|
-
req.authenticate([{ oauth2: true }]);
|
|
46
|
-
return req.callAsJson(subscriptionApticSchema);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @returns Response from the API call
|
|
51
|
-
*/
|
|
52
|
-
async resumeSubscription({
|
|
53
|
-
body,
|
|
54
|
-
subscriptionId,
|
|
55
|
-
}: {
|
|
56
|
-
body: { reason: string };
|
|
57
|
-
subscriptionId: string;
|
|
58
|
-
}) {
|
|
59
|
-
const req = this.createRequest(
|
|
60
|
-
'POST',
|
|
61
|
-
`v1/billing/subscriptions/${subscriptionId}/activate `,
|
|
62
|
-
);
|
|
63
|
-
const mapped = req.prepareArgs({
|
|
64
|
-
body: [body, resumeSubscriptionApticSchemaRequest],
|
|
65
|
-
});
|
|
66
|
-
req.header('Content-Type', 'application/json');
|
|
67
|
-
req.header('PayPal-Request-Id', Math.random().toString(36).substring(2, 15));
|
|
68
|
-
|
|
69
|
-
req.json(mapped.body);
|
|
70
|
-
this.catchAllErrors(req);
|
|
71
|
-
req.authenticate([{ oauth2: true }]);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async retrieveSubscription({ subscriptionId }: { subscriptionId: string }) {
|
|
75
|
-
const req = this.createRequest('GET', `v1/billing/subscriptions/${subscriptionId}`);
|
|
76
|
-
req.header('PayPal-Request-Id', Math.random().toString(36).substring(2, 15));
|
|
77
|
-
this.catchAllErrors(req);
|
|
78
|
-
req.authenticate([{ oauth2: true }]);
|
|
79
|
-
return req.callAsJson(subscriptionApticSchema);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async cancelSubscription({
|
|
83
|
-
subscriptionId,
|
|
84
|
-
reason,
|
|
85
|
-
}: {
|
|
86
|
-
subscriptionId: string;
|
|
87
|
-
reason: string;
|
|
88
|
-
}) {
|
|
89
|
-
const req = this.createRequest(
|
|
90
|
-
'POST',
|
|
91
|
-
`v1/billing/subscriptions/${subscriptionId}/cancel`,
|
|
92
|
-
);
|
|
93
|
-
const mapped = req.prepareArgs({
|
|
94
|
-
body: [reason, cancelSubscriptionApticSchemaRequest],
|
|
95
|
-
});
|
|
96
|
-
req.header('PayPal-Request-Id', Math.random().toString(36).substring(2, 15));
|
|
97
|
-
req.json(mapped.body);
|
|
98
|
-
this.catchAllErrors(req);
|
|
99
|
-
req.authenticate([{ oauth2: true }]);
|
|
100
|
-
return req.callAsJson(subscriptionApticSchema);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async updateSubscription({
|
|
104
|
-
subscriptionId,
|
|
105
|
-
metadata,
|
|
106
|
-
}: {
|
|
107
|
-
subscriptionId: string;
|
|
108
|
-
metadata: Record<string, unknown>;
|
|
109
|
-
}) {
|
|
110
|
-
const req = this.createRequest('PATCH', `v1/billing/subscriptions/${subscriptionId}`);
|
|
111
|
-
req.header('PayPal-Request-Id', Math.random().toString(36).substring(2, 15));
|
|
112
|
-
|
|
113
|
-
req.json({ op: 'replace', path: '/custom_id', value: JSON.stringify(metadata) });
|
|
114
|
-
|
|
115
|
-
this.catchAllErrors(req);
|
|
116
|
-
req.authenticate([{ oauth2: true }]);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, CustomError } from '@paypal/paypal-server-sdk';
|
|
2
|
-
import { BaseController } from '@paypal/paypal-server-sdk/dist/types/controllers/baseController';
|
|
3
|
-
import { VerifyWebhookSchema, verifyWebhookSchema } from '../schema';
|
|
4
|
-
|
|
5
|
-
export class WebhookController extends BaseController {
|
|
6
|
-
async verifyWebhook(body: {
|
|
7
|
-
authAlgo: string;
|
|
8
|
-
certUrl: string;
|
|
9
|
-
transmissionId: string;
|
|
10
|
-
transmissionSig: string;
|
|
11
|
-
transmissionTime: string;
|
|
12
|
-
webhookId: string;
|
|
13
|
-
webhookEvent: string;
|
|
14
|
-
}): Promise<ApiResponse<VerifyWebhookSchema>> {
|
|
15
|
-
const req = this.createRequest('POST', '/v1/notifications/verify-webhook-signature');
|
|
16
|
-
req.header('Content-Type', 'application/json');
|
|
17
|
-
|
|
18
|
-
req.throwOn(
|
|
19
|
-
400,
|
|
20
|
-
CustomError,
|
|
21
|
-
'Request is not well-formed, syntactically incorrect, or violates schema.',
|
|
22
|
-
);
|
|
23
|
-
req.throwOn(
|
|
24
|
-
401,
|
|
25
|
-
CustomError,
|
|
26
|
-
'Authentication failed due to missing authorization header, or invalid authentication credentials.',
|
|
27
|
-
);
|
|
28
|
-
req.throwOn(
|
|
29
|
-
422,
|
|
30
|
-
CustomError,
|
|
31
|
-
'The requested action could not be performed, semantically incorrect, or failed business validation.',
|
|
32
|
-
);
|
|
33
|
-
req.json(
|
|
34
|
-
Object.fromEntries(
|
|
35
|
-
Object.entries(body).map(([key, value]) => [
|
|
36
|
-
key.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`),
|
|
37
|
-
value,
|
|
38
|
-
]),
|
|
39
|
-
),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
req.authenticate([{ oauth2: true }]);
|
|
43
|
-
return req.callAsJson(verifyWebhookSchema);
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { validateRequiredKeys } from '@paykit-sdk/core';
|
|
2
|
-
import { PayPalOptions, PayPalProvider } from './paypal-provider';
|
|
3
|
-
|
|
4
|
-
export const paypal = () => {
|
|
5
|
-
const envVars = validateRequiredKeys(
|
|
6
|
-
['PAYPAL_CLIENT_ID', 'PAYPAL_CLIENT_SECRET', 'PAYPAL_SANDBOX'],
|
|
7
|
-
process.env as Record<string, string>,
|
|
8
|
-
'Missing required environment variables: {keys}',
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
return new PayPalProvider({
|
|
12
|
-
clientId: envVars.PAYPAL_CLIENT_ID,
|
|
13
|
-
clientSecret: envVars.PAYPAL_CLIENT_SECRET,
|
|
14
|
-
isSandbox: envVars.PAYPAL_SANDBOX === 'true',
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const createPayPal = (config: PayPalOptions) => {
|
|
19
|
-
return new PayPalProvider(config);
|
|
20
|
-
};
|