@easypayment/medusa-payment-paypal 1.2.3 → 1.2.4
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 +387 -133
- package/.medusa/server/src/admin/index.mjs +387 -133
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +5 -1
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/environment/route.js +2 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +9 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +9 -4
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +7 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +9 -2
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +10 -3
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/settings/route.js +9 -2
- package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/status/route.js +9 -1
- package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +4 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +5 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +23 -3
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.d.ts +5 -0
- package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.js +12 -5
- package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +8 -0
- 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 +54 -20
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js +19 -19
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts +1 -0
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/settings/route.js +4 -1
- package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +7 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.js +34 -3
- package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.js +33 -6
- package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.d.ts +4 -0
- package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.js +9 -4
- package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +5 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.js +13 -2
- package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
- package/.medusa/server/src/modules/paypal/index.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/index.js +1 -0
- package/.medusa/server/src/modules/paypal/index.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/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js +6 -6
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +4 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js +4 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +14 -6
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +55 -32
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +6 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.js +6 -4
- package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +8 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +39 -12
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +72 -2
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +159 -33
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +5 -2
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.js +15 -5
- package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +3 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +9 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/currencies.js +13 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts +12 -0
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.js +4 -3
- package/.medusa/server/src/modules/paypal/utils/payment-session.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts +11 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +17 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js +6 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js +6 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +43 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.js +57 -5
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
- package/.medusa/server/src/providers/paypal/index.d.ts +1 -0
- package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal/index.js +1 -0
- package/.medusa/server/src/providers/paypal/index.js.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.d.ts +1 -0
- package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.js +1 -0
- package/.medusa/server/src/providers/paypal_card/index.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts +6 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js +9 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts +1 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.js +17 -4
- package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -1
- package/CHANGELOG.md +11 -0
- package/README.md +184 -184
- package/package.json +7 -4
- package/src/admin/index.ts +1 -1
- package/src/admin/routes/settings/paypal/_components/FieldRow.tsx +38 -29
- package/src/admin/routes/settings/paypal/_components/SectionCard.tsx +29 -26
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +49 -48
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +63 -52
- package/src/admin/routes/settings/paypal/_utils/adminFetch.ts +52 -32
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +246 -139
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +208 -123
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/connection/page.tsx +974 -908
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/page.tsx +14 -13
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +304 -273
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +48 -39
- package/src/api/admin/paypal/disconnect/route.ts +15 -14
- package/src/api/admin/paypal/environment/route.ts +34 -32
- package/src/api/admin/paypal/onboard-complete/route.ts +61 -50
- package/src/api/admin/paypal/onboarding-link/route.ts +91 -76
- package/src/api/admin/paypal/onboarding-status/route.ts +21 -20
- package/src/api/admin/paypal/save-credentials/route.ts +48 -37
- package/src/api/admin/paypal/settings/route.ts +63 -45
- package/src/api/admin/paypal/status/route.ts +29 -17
- package/src/api/hooks/paypal/onboard-return/route.ts +15 -15
- package/src/api/hooks/paypal/webhook/route.ts +17 -17
- package/src/api/middlewares.ts +61 -61
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +63 -54
- package/src/api/store/paypal/capture-order/route.ts +416 -370
- package/src/api/store/paypal/config/route.ts +121 -115
- package/src/api/store/paypal/create-order/route.ts +586 -539
- package/src/api/store/paypal/onboard-return/route.ts +116 -113
- package/src/api/store/paypal/settings/route.ts +29 -19
- package/src/api/store/paypal/webhook/route.ts +380 -314
- package/src/api/store/paypal-complete/route.ts +157 -128
- package/src/api/utils/rate-limit.ts +143 -129
- package/src/index.ts +1 -1
- package/src/jobs/paypal-webhook-retry.ts +257 -241
- package/src/modules/paypal/index.ts +9 -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 +15 -11
- package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +15 -11
- package/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.ts +15 -11
- package/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.ts +17 -17
- package/src/modules/paypal/migrations/20270202000000_align_nullable_defaults.ts +44 -44
- package/src/modules/paypal/migrations/20270301000000_add_webhook_transmission_id_index.ts +15 -15
- package/src/modules/paypal/models/paypal_connection.ts +28 -23
- package/src/modules/paypal/models/paypal_metric.ts +13 -9
- package/src/modules/paypal/models/paypal_settings.ts +13 -8
- package/src/modules/paypal/models/paypal_webhook_event.ts +26 -19
- package/src/modules/paypal/payment-provider/base-provider.ts +287 -275
- package/src/modules/paypal/payment-provider/card-service.ts +927 -855
- package/src/modules/paypal/payment-provider/index.ts +14 -15
- package/src/modules/paypal/payment-provider/service.ts +906 -836
- package/src/modules/paypal/payment-provider/status-utils.ts +59 -59
- package/src/modules/paypal/payment-provider/webhook-utils.ts +109 -109
- package/src/modules/paypal/service.ts +362 -115
- package/src/modules/paypal/types/config.ts +70 -65
- package/src/modules/paypal/utils/amounts.ts +123 -107
- package/src/modules/paypal/utils/core-workflow.ts +46 -46
- package/src/modules/paypal/utils/credential-resolver.ts +275 -271
- package/src/modules/paypal/utils/currencies.ts +97 -84
- package/src/modules/paypal/utils/partner.ts +8 -8
- package/src/modules/paypal/utils/payment-session.ts +144 -138
- package/src/modules/paypal/utils/paypal-auth.ts +6 -5
- package/src/modules/paypal/utils/paypal-fetch.ts +197 -181
- package/src/modules/paypal/utils/provider-ids.ts +21 -15
- package/src/modules/paypal/utils/secret-crypto.ts +226 -197
- package/src/modules/paypal/utils/webhook-verify.ts +61 -61
- package/src/modules/paypal/webhook-processor.ts +641 -573
- package/src/providers/paypal/index.ts +9 -8
- package/src/providers/paypal_card/index.ts +9 -8
- package/src/subscribers/paypal-order-invoice.ts +180 -173
- package/src/subscribers/paypal-webhook-process.ts +147 -131
- package/tsconfig.json +21 -31
|
@@ -1,84 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Currencies accepted by the PayPal Orders API.
|
|
3
|
+
* See https://developer.paypal.com/api/rest/reference/currency-codes/
|
|
4
|
+
*/
|
|
5
|
+
const PAYPAL_SUPPORTED_CURRENCIES = new Set([
|
|
6
|
+
"AUD",
|
|
7
|
+
"BRL",
|
|
8
|
+
"CAD",
|
|
9
|
+
"CHF",
|
|
10
|
+
"CZK",
|
|
11
|
+
"DKK",
|
|
12
|
+
"EUR",
|
|
13
|
+
"GBP",
|
|
14
|
+
"HKD",
|
|
15
|
+
"HUF",
|
|
16
|
+
"ILS",
|
|
17
|
+
"JPY",
|
|
18
|
+
"MXN",
|
|
19
|
+
"MYR",
|
|
20
|
+
"NOK",
|
|
21
|
+
"NZD",
|
|
22
|
+
"PHP",
|
|
23
|
+
"PLN",
|
|
24
|
+
"SEK",
|
|
25
|
+
"SGD",
|
|
26
|
+
"THB",
|
|
27
|
+
"TWD",
|
|
28
|
+
"USD",
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
type CurrencyCheck = {
|
|
32
|
+
currency: string
|
|
33
|
+
overrideCurrency?: string
|
|
34
|
+
supported: boolean
|
|
35
|
+
errors: string[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Trim + upper-case an ISO 4217 code, substituting `fallback` when blank. */
|
|
39
|
+
export function normalizeCurrencyCode(code?: string, fallback = "EUR") {
|
|
40
|
+
const trimmed = String(code || "").trim()
|
|
41
|
+
return (trimmed || fallback).toUpperCase()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Whether PayPal accepts orders in this currency. */
|
|
45
|
+
export function isPayPalCurrencySupported(currencyCode: string) {
|
|
46
|
+
return PAYPAL_SUPPORTED_CURRENCIES.has(normalizeCurrencyCode(currencyCode))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Check a cart currency against PayPal support and, when configured, the
|
|
51
|
+
* merchant's PayPal currency override. Returns every problem found so the
|
|
52
|
+
* storefront can show an actionable message rather than a bare failure.
|
|
53
|
+
*/
|
|
54
|
+
export function getPayPalCurrencyCompatibility(input: {
|
|
55
|
+
currencyCode?: string
|
|
56
|
+
paypalCurrencyOverride?: string
|
|
57
|
+
}): CurrencyCheck {
|
|
58
|
+
const currency = normalizeCurrencyCode(input.currencyCode)
|
|
59
|
+
const overrideCurrency = input.paypalCurrencyOverride
|
|
60
|
+
? normalizeCurrencyCode(input.paypalCurrencyOverride)
|
|
61
|
+
: undefined
|
|
62
|
+
const errors: string[] = []
|
|
63
|
+
|
|
64
|
+
if (!isPayPalCurrencySupported(currency)) {
|
|
65
|
+
errors.push(`PayPal does not support currency "${currency}".`)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (overrideCurrency && overrideCurrency !== currency) {
|
|
69
|
+
errors.push(
|
|
70
|
+
`PayPal is configured for "${overrideCurrency}", but the store cart uses "${currency}".`
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
currency,
|
|
76
|
+
overrideCurrency,
|
|
77
|
+
supported: errors.length === 0,
|
|
78
|
+
errors,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** `getPayPalCurrencyCompatibility`, but throws when incompatible. */
|
|
83
|
+
export function assertPayPalCurrencySupported(input: {
|
|
84
|
+
currencyCode?: string
|
|
85
|
+
paypalCurrencyOverride?: string
|
|
86
|
+
}) {
|
|
87
|
+
const result = getPayPalCurrencyCompatibility(input)
|
|
88
|
+
if (!result.supported) {
|
|
89
|
+
throw new Error(result.errors.join(" "))
|
|
90
|
+
}
|
|
91
|
+
return result
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The supported currency codes as an array (for API responses). */
|
|
95
|
+
export function getPayPalSupportedCurrencies() {
|
|
96
|
+
return Array.from(PAYPAL_SUPPORTED_CURRENCIES.values())
|
|
97
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PayPal Partner Attribution Id (BN code) for this integration.
|
|
3
|
-
*
|
|
4
|
-
* Centralized here so the value lives in exactly one place instead of being
|
|
5
|
-
* re-declared across the providers, credential resolver, and store routes.
|
|
6
|
-
* Sent as the `PayPal-Partner-Attribution-Id` header on outbound PayPal calls.
|
|
7
|
-
*/
|
|
8
|
-
export const PAYPAL_PARTNER_ATTRIBUTION_ID = "MBJTechnolabs_SI_SPB"
|
|
1
|
+
/**
|
|
2
|
+
* PayPal Partner Attribution Id (BN code) for this integration.
|
|
3
|
+
*
|
|
4
|
+
* Centralized here so the value lives in exactly one place instead of being
|
|
5
|
+
* re-declared across the providers, credential resolver, and store routes.
|
|
6
|
+
* Sent as the `PayPal-Partner-Attribution-Id` header on outbound PayPal calls.
|
|
7
|
+
*/
|
|
8
|
+
export const PAYPAL_PARTNER_ATTRIBUTION_ID = "MBJTechnolabs_SI_SPB"
|
|
@@ -1,138 +1,144 @@
|
|
|
1
|
-
import type { IPaymentModuleService } from "@medusajs/framework/types"
|
|
2
|
-
import { Modules } from "@medusajs/framework/utils"
|
|
3
|
-
import { isPayPalProviderId } from "./provider-ids"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Shared PayPal payment-session helpers.
|
|
7
|
-
*
|
|
8
|
-
* `create-order` and `capture-order` must agree on (a) which payment session
|
|
9
|
-
* belongs to a cart and (b) how the PayPal order id is stored/read on it —
|
|
10
|
-
* otherwise the capture's fail-closed binding (the order id stored by
|
|
11
|
-
* create-order must equal the one being captured) can never be satisfied.
|
|
12
|
-
* Keeping the logic here, resolved through the Payment module service
|
|
13
|
-
* (`Modules.PAYMENT`), guarantees both routes use the same, correct path.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export type PayPalCartSession = {
|
|
17
|
-
session_id: string
|
|
18
|
-
session_data: Record<string, any>
|
|
19
|
-
session_status: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Resolve the cart's active PayPal payment session (wallet or card). When a
|
|
24
|
-
* cart has more than one PayPal session, the most recently created one wins —
|
|
25
|
-
* both create-order and capture-order rely on this same selection so they
|
|
26
|
-
* always read and write the same session.
|
|
27
|
-
*/
|
|
28
|
-
export async function findPayPalSessionForCart(
|
|
29
|
-
cartId: string,
|
|
30
|
-
scope: any
|
|
31
|
-
): Promise<PayPalCartSession | null> {
|
|
32
|
-
try {
|
|
33
|
-
const query = scope.resolve("query")
|
|
34
|
-
const { data: carts } = await query.graph({
|
|
35
|
-
entity: "cart",
|
|
36
|
-
fields: [
|
|
37
|
-
"id",
|
|
38
|
-
"payment_collection.payment_sessions.id",
|
|
39
|
-
"payment_collection.payment_sessions.data",
|
|
40
|
-
"payment_collection.payment_sessions.status",
|
|
41
|
-
"payment_collection.payment_sessions.provider_id",
|
|
42
|
-
"payment_collection.payment_sessions.created_at",
|
|
43
|
-
],
|
|
44
|
-
filters: { id: cartId },
|
|
45
|
-
})
|
|
46
|
-
const cart = carts?.[0]
|
|
47
|
-
const sessions = cart?.payment_collection?.payment_sessions || []
|
|
48
|
-
const session = sessions
|
|
49
|
-
.filter((s: any) => isPayPalProviderId(s.provider_id))
|
|
50
|
-
.sort(
|
|
51
|
-
(a: any, b: any) =>
|
|
52
|
-
new Date(b.created_at || 0).getTime() -
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
1
|
+
import type { IPaymentModuleService } from "@medusajs/framework/types"
|
|
2
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
3
|
+
import { isPayPalProviderId } from "./provider-ids"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared PayPal payment-session helpers.
|
|
7
|
+
*
|
|
8
|
+
* `create-order` and `capture-order` must agree on (a) which payment session
|
|
9
|
+
* belongs to a cart and (b) how the PayPal order id is stored/read on it —
|
|
10
|
+
* otherwise the capture's fail-closed binding (the order id stored by
|
|
11
|
+
* create-order must equal the one being captured) can never be satisfied.
|
|
12
|
+
* Keeping the logic here, resolved through the Payment module service
|
|
13
|
+
* (`Modules.PAYMENT`), guarantees both routes use the same, correct path.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export type PayPalCartSession = {
|
|
17
|
+
session_id: string
|
|
18
|
+
session_data: Record<string, any>
|
|
19
|
+
session_status: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the cart's active PayPal payment session (wallet or card). When a
|
|
24
|
+
* cart has more than one PayPal session, the most recently created one wins —
|
|
25
|
+
* both create-order and capture-order rely on this same selection so they
|
|
26
|
+
* always read and write the same session.
|
|
27
|
+
*/
|
|
28
|
+
export async function findPayPalSessionForCart(
|
|
29
|
+
cartId: string,
|
|
30
|
+
scope: any
|
|
31
|
+
): Promise<PayPalCartSession | null> {
|
|
32
|
+
try {
|
|
33
|
+
const query = scope.resolve("query")
|
|
34
|
+
const { data: carts } = await query.graph({
|
|
35
|
+
entity: "cart",
|
|
36
|
+
fields: [
|
|
37
|
+
"id",
|
|
38
|
+
"payment_collection.payment_sessions.id",
|
|
39
|
+
"payment_collection.payment_sessions.data",
|
|
40
|
+
"payment_collection.payment_sessions.status",
|
|
41
|
+
"payment_collection.payment_sessions.provider_id",
|
|
42
|
+
"payment_collection.payment_sessions.created_at",
|
|
43
|
+
],
|
|
44
|
+
filters: { id: cartId },
|
|
45
|
+
})
|
|
46
|
+
const cart = carts?.[0]
|
|
47
|
+
const sessions = cart?.payment_collection?.payment_sessions || []
|
|
48
|
+
const session = sessions
|
|
49
|
+
.filter((s: any) => isPayPalProviderId(s.provider_id))
|
|
50
|
+
.sort(
|
|
51
|
+
(a: any, b: any) =>
|
|
52
|
+
new Date(b.created_at || 0).getTime() -
|
|
53
|
+
new Date(a.created_at || 0).getTime()
|
|
54
|
+
)[0]
|
|
55
|
+
|
|
56
|
+
if (!session) return null
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
session_id: session.id,
|
|
60
|
+
session_data: (session.data || {}) as Record<string, any>,
|
|
61
|
+
session_status: session.status,
|
|
62
|
+
}
|
|
63
|
+
} catch (e: any) {
|
|
64
|
+
console.warn("[PayPal] findPayPalSessionForCart failed:", e?.message)
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Read the PayPal order id stored on a session's `data`. Accepts both the
|
|
71
|
+
* canonical `data.paypal.order_id` and the legacy top-level `data.order_id`.
|
|
72
|
+
* Returns null when none is present.
|
|
73
|
+
*/
|
|
74
|
+
export function getStoredPayPalOrderId(
|
|
75
|
+
sessionData?: Record<string, any> | null
|
|
76
|
+
): string | null {
|
|
77
|
+
const paypal = (sessionData?.paypal || {}) as Record<string, unknown>
|
|
78
|
+
const id = String(paypal.order_id || sessionData?.order_id || "")
|
|
79
|
+
return id || null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const SESSION_UPDATE_MAX_ATTEMPTS = 3
|
|
83
|
+
const SESSION_UPDATE_BASE_DELAY_MS = 200
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Shallow-merge `extraData` into a payment session's `data`, preserving the
|
|
87
|
+
* session's amount/currency. Callers that update the nested `paypal` object are
|
|
88
|
+
* responsible for spreading its existing keys (see `getStoredPayPalOrderId`).
|
|
89
|
+
*
|
|
90
|
+
* The write is retried a few times before giving up: when this runs right after
|
|
91
|
+
* a successful PayPal capture, a transient DB blip that loses the write means
|
|
92
|
+
* the money is captured but Medusa never records it. A bounded retry closes the
|
|
93
|
+
* common transient-failure window; if every attempt fails the error is
|
|
94
|
+
* re-thrown (with a CRITICAL log for capture/order data) so the caller can react
|
|
95
|
+
* — the webhook and paypal-complete's live re-derivation remain the backstop.
|
|
96
|
+
*/
|
|
97
|
+
export async function updatePayPalSessionData(
|
|
98
|
+
sessionId: string,
|
|
99
|
+
extraData: Record<string, any>,
|
|
100
|
+
scope: any
|
|
101
|
+
): Promise<void> {
|
|
102
|
+
const paymentModule = scope.resolve(Modules.PAYMENT) as IPaymentModuleService
|
|
103
|
+
let lastError: unknown
|
|
104
|
+
|
|
105
|
+
for (let attempt = 1; attempt <= SESSION_UPDATE_MAX_ATTEMPTS; attempt++) {
|
|
106
|
+
try {
|
|
107
|
+
const [existing] = await paymentModule.listPaymentSessions(
|
|
108
|
+
{ id: [sessionId] },
|
|
109
|
+
{ take: 1 }
|
|
110
|
+
)
|
|
111
|
+
const mergedData = { ...(existing?.data || {}), ...extraData }
|
|
112
|
+
await (paymentModule as any).updatePaymentSession({
|
|
113
|
+
id: sessionId,
|
|
114
|
+
data: mergedData,
|
|
115
|
+
amount: existing?.amount,
|
|
116
|
+
currency_code: existing?.currency_code,
|
|
117
|
+
})
|
|
118
|
+
return
|
|
119
|
+
} catch (e: unknown) {
|
|
120
|
+
lastError = e
|
|
121
|
+
const msg = e instanceof Error ? e.message : String(e)
|
|
122
|
+
console.warn(
|
|
123
|
+
`[PayPal] updatePayPalSessionData attempt ${attempt}/${SESSION_UPDATE_MAX_ATTEMPTS} failed:`,
|
|
124
|
+
msg
|
|
125
|
+
)
|
|
126
|
+
if (attempt < SESSION_UPDATE_MAX_ATTEMPTS) {
|
|
127
|
+
await new Promise((r) =>
|
|
128
|
+
setTimeout(r, SESSION_UPDATE_BASE_DELAY_MS * attempt)
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const msg = lastError instanceof Error ? lastError.message : String(lastError)
|
|
135
|
+
console.error("[PayPal] updatePayPalSessionData failed after retries:", msg)
|
|
136
|
+
const hasCaptureData = "capture_id" in extraData || "order_id" in extraData
|
|
137
|
+
if (hasCaptureData) {
|
|
138
|
+
console.error(
|
|
139
|
+
"[PayPal] CRITICAL: Payment data (capture/order) was NOT persisted to session.",
|
|
140
|
+
{ sessionId, keys: Object.keys(extraData) }
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
throw lastError
|
|
144
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** PayPal REST API origin: production for `"live"`, sandbox otherwise. */
|
|
2
|
+
export function getPayPalApiBase(environment: string): string {
|
|
3
|
+
return environment === "live"
|
|
4
|
+
? "https://api-m.paypal.com"
|
|
5
|
+
: "https://api-m.sandbox.paypal.com"
|
|
6
|
+
}
|