@easypayment/medusa-paypal 0.4.7 → 0.4.8
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/.medusa/server/src/admin/index.js +7 -7
- package/.medusa/server/src/admin/index.mjs +7 -7
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.js +62 -139
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +22 -22
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +11 -11
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +18 -18
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +16 -16
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +20 -20
- package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +14 -14
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js +15 -15
- package/README.md +142 -142
- package/package.json +75 -75
- package/src/admin/index.ts +7 -7
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +52 -52
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +51 -51
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +200 -200
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +183 -183
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +5 -5
- package/src/admin/routes/settings/paypal/connection/page.tsx +754 -754
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +5 -5
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +5 -5
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +376 -376
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +24 -24
- package/src/api/admin/paypal/disconnect/route.ts +8 -8
- package/src/api/admin/paypal/environment/route.ts +25 -25
- package/src/api/admin/paypal/onboard-complete/route.ts +44 -44
- package/src/api/admin/paypal/onboarding-link/route.ts +45 -45
- package/src/api/admin/paypal/onboarding-status/route.ts +18 -18
- package/src/api/admin/paypal/rotate-credentials/route.ts +8 -8
- package/src/api/admin/paypal/save-credentials/route.ts +14 -14
- package/src/api/admin/paypal/settings/route.ts +14 -14
- package/src/api/admin/paypal/status/route.ts +12 -12
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +65 -65
- package/src/api/store/paypal/capture-order/route.ts +276 -276
- package/src/api/store/paypal/config/route.ts +102 -102
- package/src/api/store/paypal/create-order/route.ts +77 -176
- package/src/api/store/paypal/settings/route.ts +19 -19
- package/src/api/store/paypal/webhook/route.ts +246 -246
- package/src/api/store/paypal-complete/route.ts +75 -75
- package/src/jobs/paypal-reconcile.ts +112 -112
- package/src/jobs/paypal-webhook-retry.ts +85 -85
- package/src/modules/paypal/clients/paypal-seller.client.ts +59 -59
- package/src/modules/paypal/index.ts +8 -8
- package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -33
- package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -22
- package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -29
- package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -27
- package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -31
- package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -25
- package/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.ts +26 -26
- package/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.ts +11 -11
- package/src/modules/paypal/models/paypal_connection.ts +21 -21
- package/src/modules/paypal/models/paypal_metric.ts +9 -9
- package/src/modules/paypal/models/paypal_settings.ts +8 -8
- package/src/modules/paypal/models/paypal_webhook_event.ts +19 -19
- package/src/modules/paypal/payment-provider/README.md +22 -22
- package/src/modules/paypal/payment-provider/card-service.ts +760 -760
- package/src/modules/paypal/payment-provider/index.ts +19 -19
- package/src/modules/paypal/payment-provider/service.ts +1121 -1121
- package/src/modules/paypal/payment-provider/webhook-utils.ts +88 -88
- package/src/modules/paypal/service.ts +1247 -1247
- package/src/modules/paypal/types/config.ts +47 -47
- package/src/modules/paypal/utils/amounts.ts +41 -41
- package/src/modules/paypal/utils/crypto.ts +51 -51
- package/src/modules/paypal/utils/currencies.ts +84 -84
- package/src/modules/paypal/utils/paypal-auth.ts +32 -32
- package/src/modules/paypal/utils/provider-ids.ts +15 -15
- package/src/modules/paypal/webhook-processor.ts +215 -215
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ProviderWebhookPayload,
|
|
3
|
-
WebhookActionResult,
|
|
4
|
-
} from "@medusajs/framework/types"
|
|
5
|
-
|
|
6
|
-
const EVENT_ACTIONS: Record<string, WebhookActionResult["action"]> = {
|
|
7
|
-
"CHECKOUT.ORDER.CREATED": "pending",
|
|
8
|
-
"CHECKOUT.ORDER.SAVED": "pending",
|
|
9
|
-
"CHECKOUT.ORDER.APPROVED": "authorized",
|
|
10
|
-
"CHECKOUT.ORDER.PAYER_ACTION_REQUIRED": "pending",
|
|
11
|
-
"CHECKOUT.ORDER.CANCELLED": "canceled",
|
|
12
|
-
"CHECKOUT.ORDER.EXPIRED": "failed",
|
|
13
|
-
"CHECKOUT.ORDER.VOIDED": "canceled",
|
|
14
|
-
"CHECKOUT.ORDER.COMPLETED": "captured",
|
|
15
|
-
"PAYMENT.AUTHORIZATION.CREATED": "authorized",
|
|
16
|
-
"PAYMENT.AUTHORIZATION.DENIED": "failed",
|
|
17
|
-
"PAYMENT.AUTHORIZATION.EXPIRED": "failed",
|
|
18
|
-
"PAYMENT.AUTHORIZATION.PENDING": "pending",
|
|
19
|
-
"PAYMENT.AUTHORIZATION.VOIDED": "canceled",
|
|
20
|
-
"PAYMENT.CAPTURE.COMPLETED": "captured",
|
|
21
|
-
"PAYMENT.CAPTURE.DENIED": "failed",
|
|
22
|
-
"PAYMENT.CAPTURE.PENDING": "pending",
|
|
23
|
-
"PAYMENT.CAPTURE.REFUNDED": "canceled",
|
|
24
|
-
"PAYMENT.CAPTURE.REVERSED": "canceled",
|
|
25
|
-
"PAYMENT.REFUND.COMPLETED": "canceled",
|
|
26
|
-
"PAYMENT.REFUND.DENIED": "failed",
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function resolveSessionId(resource: any): string | undefined {
|
|
30
|
-
return (
|
|
31
|
-
resource?.custom_id ||
|
|
32
|
-
resource?.purchase_units?.[0]?.custom_id ||
|
|
33
|
-
resource?.purchase_units?.[0]?.payments?.captures?.[0]?.custom_id ||
|
|
34
|
-
resource?.purchase_units?.[0]?.payments?.authorizations?.[0]?.custom_id ||
|
|
35
|
-
resource?.purchase_units?.[0]?.payments?.refunds?.[0]?.custom_id
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function resolveAmount(resource: any): number | undefined {
|
|
40
|
-
const amount =
|
|
41
|
-
resource?.amount ||
|
|
42
|
-
resource?.purchase_units?.[0]?.amount ||
|
|
43
|
-
resource?.purchase_units?.[0]?.payments?.captures?.[0]?.amount ||
|
|
44
|
-
resource?.purchase_units?.[0]?.payments?.authorizations?.[0]?.amount ||
|
|
45
|
-
resource?.purchase_units?.[0]?.payments?.refunds?.[0]?.amount ||
|
|
46
|
-
resource?.seller_receivable_breakdown?.gross_amount
|
|
47
|
-
const value = amount?.value ?? amount?.amount?.value
|
|
48
|
-
if (value === undefined || value === null) {
|
|
49
|
-
return undefined
|
|
50
|
-
}
|
|
51
|
-
const parsed = Number(value)
|
|
52
|
-
return Number.isFinite(parsed) ? parsed : undefined
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function resolveEventType(payload: ProviderWebhookPayload["payload"]) {
|
|
56
|
-
const raw = payload as { event_type?: string; eventType?: string }
|
|
57
|
-
return raw?.event_type || raw?.eventType
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getPayPalWebhookActionAndData(
|
|
61
|
-
payload: ProviderWebhookPayload["payload"]
|
|
62
|
-
): WebhookActionResult {
|
|
63
|
-
const eventType = resolveEventType(payload)
|
|
64
|
-
if (!eventType) {
|
|
65
|
-
return { action: "not_supported" }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const action = EVENT_ACTIONS[eventType]
|
|
69
|
-
if (!action) {
|
|
70
|
-
return { action: "not_supported" }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const resource = (payload as { resource?: unknown })?.resource
|
|
74
|
-
const sessionId = resolveSessionId(resource)
|
|
75
|
-
const amount = resolveAmount(resource)
|
|
76
|
-
|
|
77
|
-
if (!sessionId || amount === undefined) {
|
|
78
|
-
return { action: "not_supported" }
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
action,
|
|
83
|
-
data: {
|
|
84
|
-
session_id: sessionId,
|
|
85
|
-
amount,
|
|
86
|
-
},
|
|
87
|
-
}
|
|
88
|
-
}
|
|
1
|
+
import type {
|
|
2
|
+
ProviderWebhookPayload,
|
|
3
|
+
WebhookActionResult,
|
|
4
|
+
} from "@medusajs/framework/types"
|
|
5
|
+
|
|
6
|
+
const EVENT_ACTIONS: Record<string, WebhookActionResult["action"]> = {
|
|
7
|
+
"CHECKOUT.ORDER.CREATED": "pending",
|
|
8
|
+
"CHECKOUT.ORDER.SAVED": "pending",
|
|
9
|
+
"CHECKOUT.ORDER.APPROVED": "authorized",
|
|
10
|
+
"CHECKOUT.ORDER.PAYER_ACTION_REQUIRED": "pending",
|
|
11
|
+
"CHECKOUT.ORDER.CANCELLED": "canceled",
|
|
12
|
+
"CHECKOUT.ORDER.EXPIRED": "failed",
|
|
13
|
+
"CHECKOUT.ORDER.VOIDED": "canceled",
|
|
14
|
+
"CHECKOUT.ORDER.COMPLETED": "captured",
|
|
15
|
+
"PAYMENT.AUTHORIZATION.CREATED": "authorized",
|
|
16
|
+
"PAYMENT.AUTHORIZATION.DENIED": "failed",
|
|
17
|
+
"PAYMENT.AUTHORIZATION.EXPIRED": "failed",
|
|
18
|
+
"PAYMENT.AUTHORIZATION.PENDING": "pending",
|
|
19
|
+
"PAYMENT.AUTHORIZATION.VOIDED": "canceled",
|
|
20
|
+
"PAYMENT.CAPTURE.COMPLETED": "captured",
|
|
21
|
+
"PAYMENT.CAPTURE.DENIED": "failed",
|
|
22
|
+
"PAYMENT.CAPTURE.PENDING": "pending",
|
|
23
|
+
"PAYMENT.CAPTURE.REFUNDED": "canceled",
|
|
24
|
+
"PAYMENT.CAPTURE.REVERSED": "canceled",
|
|
25
|
+
"PAYMENT.REFUND.COMPLETED": "canceled",
|
|
26
|
+
"PAYMENT.REFUND.DENIED": "failed",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resolveSessionId(resource: any): string | undefined {
|
|
30
|
+
return (
|
|
31
|
+
resource?.custom_id ||
|
|
32
|
+
resource?.purchase_units?.[0]?.custom_id ||
|
|
33
|
+
resource?.purchase_units?.[0]?.payments?.captures?.[0]?.custom_id ||
|
|
34
|
+
resource?.purchase_units?.[0]?.payments?.authorizations?.[0]?.custom_id ||
|
|
35
|
+
resource?.purchase_units?.[0]?.payments?.refunds?.[0]?.custom_id
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function resolveAmount(resource: any): number | undefined {
|
|
40
|
+
const amount =
|
|
41
|
+
resource?.amount ||
|
|
42
|
+
resource?.purchase_units?.[0]?.amount ||
|
|
43
|
+
resource?.purchase_units?.[0]?.payments?.captures?.[0]?.amount ||
|
|
44
|
+
resource?.purchase_units?.[0]?.payments?.authorizations?.[0]?.amount ||
|
|
45
|
+
resource?.purchase_units?.[0]?.payments?.refunds?.[0]?.amount ||
|
|
46
|
+
resource?.seller_receivable_breakdown?.gross_amount
|
|
47
|
+
const value = amount?.value ?? amount?.amount?.value
|
|
48
|
+
if (value === undefined || value === null) {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
const parsed = Number(value)
|
|
52
|
+
return Number.isFinite(parsed) ? parsed : undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function resolveEventType(payload: ProviderWebhookPayload["payload"]) {
|
|
56
|
+
const raw = payload as { event_type?: string; eventType?: string }
|
|
57
|
+
return raw?.event_type || raw?.eventType
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getPayPalWebhookActionAndData(
|
|
61
|
+
payload: ProviderWebhookPayload["payload"]
|
|
62
|
+
): WebhookActionResult {
|
|
63
|
+
const eventType = resolveEventType(payload)
|
|
64
|
+
if (!eventType) {
|
|
65
|
+
return { action: "not_supported" }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const action = EVENT_ACTIONS[eventType]
|
|
69
|
+
if (!action) {
|
|
70
|
+
return { action: "not_supported" }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const resource = (payload as { resource?: unknown })?.resource
|
|
74
|
+
const sessionId = resolveSessionId(resource)
|
|
75
|
+
const amount = resolveAmount(resource)
|
|
76
|
+
|
|
77
|
+
if (!sessionId || amount === undefined) {
|
|
78
|
+
return { action: "not_supported" }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
action,
|
|
83
|
+
data: {
|
|
84
|
+
session_id: sessionId,
|
|
85
|
+
amount,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
}
|