@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.
@@ -0,0 +1,120 @@
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';
4
+
5
+ // src/controllers/webhook.ts
6
+ object({
7
+ currency_code: ["currency_code", string()],
8
+ value: ["value", string()]
9
+ });
10
+ object({
11
+ plan_id: ["plan_id", string()],
12
+ quantity: ["quantity", number()],
13
+ custom_id: ["custom_id", string()],
14
+ start_time: ["start_time", string()],
15
+ subscriber: [
16
+ "subscriber",
17
+ lazy(
18
+ () => object({
19
+ email_address: ["email_address", string()],
20
+ name: [
21
+ "name",
22
+ lazy(
23
+ () => object({
24
+ given_name: ["given_name", string()],
25
+ surname: ["surname", string()]
26
+ })
27
+ )
28
+ ],
29
+ phone: [
30
+ "phone",
31
+ lazy(() => object({ phone_number: ["phone_number", string()] }))
32
+ ]
33
+ })
34
+ )
35
+ ]
36
+ });
37
+ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
38
+ SubscriptionStatus2["APPROVAL_PENDING"] = "APPROVAL_PENDING";
39
+ SubscriptionStatus2["APPROVED"] = "APPROVED";
40
+ SubscriptionStatus2["ACTIVE"] = "ACTIVE";
41
+ SubscriptionStatus2["SUSPENDED"] = "SUSPENDED";
42
+ SubscriptionStatus2["CANCELLED"] = "CANCELLED";
43
+ SubscriptionStatus2["EXPIRED"] = "EXPIRED";
44
+ return SubscriptionStatus2;
45
+ })(SubscriptionStatus || {});
46
+ object({
47
+ id: ["id", string()],
48
+ plan_id: ["plan_id", string()],
49
+ quantity: ["quantity", number()],
50
+ custom_id: ["custom_id", string()],
51
+ plan_overridden: ["plan_overridden", boolean()],
52
+ start_time: ["start_time", string()],
53
+ subscriber: [
54
+ "subscriber",
55
+ lazy(
56
+ () => object({
57
+ email_address: ["email_address", string()],
58
+ name: [
59
+ "name",
60
+ lazy(
61
+ () => object({
62
+ given_name: ["given_name", string()],
63
+ surname: ["surname", string()]
64
+ })
65
+ )
66
+ ],
67
+ payer_id: ["payer_id", string()]
68
+ })
69
+ )
70
+ ],
71
+ status: ["status", stringEnum(SubscriptionStatus)],
72
+ status_change_note: ["status_change_note", string()],
73
+ status_update_time: ["status_update_time", string()]
74
+ });
75
+ object({
76
+ reason: ["reason", string()]
77
+ });
78
+ var VerifyWebhookStatus = /* @__PURE__ */ ((VerifyWebhookStatus2) => {
79
+ VerifyWebhookStatus2["SUCCESS"] = "SUCCESS";
80
+ VerifyWebhookStatus2["FAILURE"] = "FAILURE";
81
+ return VerifyWebhookStatus2;
82
+ })(VerifyWebhookStatus || {});
83
+ var verifyWebhookSchema = object({
84
+ verification_status: ["verification_status", stringEnum(VerifyWebhookStatus)]
85
+ });
86
+
87
+ // src/controllers/webhook.ts
88
+ var WebhookController = class extends BaseController {
89
+ async verifyWebhook(body) {
90
+ const req = this.createRequest("POST", "/v1/notifications/verify-webhook-signature");
91
+ req.header("Content-Type", "application/json");
92
+ req.throwOn(
93
+ 400,
94
+ CustomError,
95
+ "Request is not well-formed, syntactically incorrect, or violates schema."
96
+ );
97
+ req.throwOn(
98
+ 401,
99
+ CustomError,
100
+ "Authentication failed due to missing authorization header, or invalid authentication credentials."
101
+ );
102
+ req.throwOn(
103
+ 422,
104
+ CustomError,
105
+ "The requested action could not be performed, semantically incorrect, or failed business validation."
106
+ );
107
+ req.json(
108
+ Object.fromEntries(
109
+ Object.entries(body).map(([key, value]) => [
110
+ key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`),
111
+ value
112
+ ])
113
+ )
114
+ );
115
+ req.authenticate([{ oauth2: true }]);
116
+ return req.callAsJson(verifyWebhookSchema);
117
+ }
118
+ };
119
+
120
+ export { WebhookController };
@@ -0,0 +1,7 @@
1
+ import { PayPalProvider, PayPalOptions } from './paypal-provider.mjs';
2
+ import '@paykit-sdk/core';
3
+
4
+ declare const paypal: () => PayPalProvider;
5
+ declare const createPayPal: (config: PayPalOptions) => PayPalProvider;
6
+
7
+ export { createPayPal, paypal };
@@ -0,0 +1,7 @@
1
+ import { PayPalProvider, PayPalOptions } from './paypal-provider.js';
2
+ import '@paykit-sdk/core';
3
+
4
+ declare const paypal: () => PayPalProvider;
5
+ declare const createPayPal: (config: PayPalOptions) => PayPalProvider;
6
+
7
+ export { createPayPal, paypal };