@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,65 +1,70 @@
|
|
|
1
|
-
import { randomBytes } from "crypto"
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
import { randomBytes } from "crypto"
|
|
2
|
+
|
|
3
|
+
/** Partner-level configuration, resolved from env vars with built-in defaults. */
|
|
4
|
+
export type PayPalModuleConfig = {
|
|
5
|
+
partnerServiceUrl: string
|
|
6
|
+
partnerJsUrl: string
|
|
7
|
+
backendUrl: string
|
|
8
|
+
sellerNonce: string
|
|
9
|
+
bnCode?: string
|
|
10
|
+
partnerMerchantIdSandbox: string
|
|
11
|
+
partnerMerchantIdLive: string
|
|
12
|
+
alertWebhookUrls?: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const STATIC_CFG: PayPalModuleConfig = {
|
|
16
|
+
partnerServiceUrl:
|
|
17
|
+
"https://mbjtechnolabs.com/ppcp-seller-onboarding/seller-onboarding.php?from=medusa",
|
|
18
|
+
partnerJsUrl:
|
|
19
|
+
"https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js",
|
|
20
|
+
backendUrl: "http://localhost:9000",
|
|
21
|
+
sellerNonce: "",
|
|
22
|
+
bnCode: "MBJTechnolabs_SI_SPB",
|
|
23
|
+
partnerMerchantIdSandbox: "K6QLN2LPGQRHL",
|
|
24
|
+
partnerMerchantIdLive: "GT5R877JNBPLL",
|
|
25
|
+
alertWebhookUrls: [],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let warnedGeneratedNonce = false
|
|
29
|
+
|
|
30
|
+
function generateSellerNonce(): string {
|
|
31
|
+
// The nonce doubles as the OAuth code_verifier for the onboarding exchange,
|
|
32
|
+
// so every instance must agree on it. It is persisted into settings on first
|
|
33
|
+
// boot, but two instances booting simultaneously can race to persist
|
|
34
|
+
// different generated values — an onboarding link minted against the losing
|
|
35
|
+
// nonce then fails its token exchange with an opaque invalid_grant. Pinning
|
|
36
|
+
// PAYPAL_SELLER_NONCE removes the race entirely.
|
|
37
|
+
if (!warnedGeneratedNonce) {
|
|
38
|
+
warnedGeneratedNonce = true
|
|
39
|
+
console.warn(
|
|
40
|
+
"[PayPal] PAYPAL_SELLER_NONCE is not set — generating a random seller nonce. " +
|
|
41
|
+
"For multi-instance deployments, set PAYPAL_SELLER_NONCE to a fixed random string " +
|
|
42
|
+
"so all instances share the same onboarding code_verifier."
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
return randomBytes(32).toString("hex")
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Resolve the module configuration from the environment. */
|
|
49
|
+
export function getPayPalConfig(): PayPalModuleConfig {
|
|
50
|
+
const backendUrl = process.env.MEDUSA_BACKEND_URL || STATIC_CFG.backendUrl
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...STATIC_CFG,
|
|
54
|
+
partnerServiceUrl:
|
|
55
|
+
process.env.PAYPAL_PARTNER_SERVICE_URL || STATIC_CFG.partnerServiceUrl,
|
|
56
|
+
backendUrl,
|
|
57
|
+
sellerNonce: process.env.PAYPAL_SELLER_NONCE || generateSellerNonce(),
|
|
58
|
+
partnerMerchantIdSandbox:
|
|
59
|
+
process.env.PAYPAL_PARTNER_MERCHANT_ID_SANDBOX ||
|
|
60
|
+
STATIC_CFG.partnerMerchantIdSandbox,
|
|
61
|
+
partnerMerchantIdLive:
|
|
62
|
+
process.env.PAYPAL_PARTNER_MERCHANT_ID_LIVE ||
|
|
63
|
+
STATIC_CFG.partnerMerchantIdLive,
|
|
64
|
+
alertWebhookUrls:
|
|
65
|
+
(process.env.PAYPAL_ALERT_WEBHOOK_URLS || "")
|
|
66
|
+
.split(",")
|
|
67
|
+
.map((url) => url.trim())
|
|
68
|
+
.filter(Boolean) || STATIC_CFG.alertWebhookUrls,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,107 +1,123 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Currencies PayPal requires as whole numbers (no decimal component).
|
|
3
|
+
* See https://developer.paypal.com/api/rest/reference/currency-codes/
|
|
4
|
+
*/
|
|
5
|
+
const ZERO_DECIMAL_CURRENCIES = new Set([
|
|
6
|
+
"BIF",
|
|
7
|
+
"CLP",
|
|
8
|
+
"DJF",
|
|
9
|
+
"GNF",
|
|
10
|
+
// HUF and TWD have 2 ISO 4217 minor digits, but PayPal still rejects
|
|
11
|
+
// "1000.00" for them (DECIMAL_PRECISION) — they must be sent as "1000".
|
|
12
|
+
"HUF",
|
|
13
|
+
"JPY",
|
|
14
|
+
"KMF",
|
|
15
|
+
"KRW",
|
|
16
|
+
"MGA",
|
|
17
|
+
"PYG",
|
|
18
|
+
"RWF",
|
|
19
|
+
"TWD",
|
|
20
|
+
"UGX",
|
|
21
|
+
"VND",
|
|
22
|
+
"VUV",
|
|
23
|
+
"XAF",
|
|
24
|
+
"XOF",
|
|
25
|
+
"XPF",
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
const THREE_DECIMAL_CURRENCIES = new Set([
|
|
29
|
+
"BHD",
|
|
30
|
+
"IQD",
|
|
31
|
+
"JOD",
|
|
32
|
+
"KWD",
|
|
33
|
+
"OMR",
|
|
34
|
+
"TND",
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
/** Number of decimal places PayPal expects for a currency (0, 2, or 3). */
|
|
38
|
+
export function getCurrencyExponent(currencyCode: string) {
|
|
39
|
+
const code = currencyCode.toUpperCase()
|
|
40
|
+
if (ZERO_DECIMAL_CURRENCIES.has(code)) {
|
|
41
|
+
return 0
|
|
42
|
+
}
|
|
43
|
+
if (THREE_DECIMAL_CURRENCIES.has(code)) {
|
|
44
|
+
return 3
|
|
45
|
+
}
|
|
46
|
+
return 2
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Coerce a Medusa monetary amount into a plain JS number.
|
|
51
|
+
*
|
|
52
|
+
* Medusa passes amounts to payment providers as a `BigNumberInput`, which can be
|
|
53
|
+
* a plain `number`/`string`, a `BigNumber` instance (exposing a `numeric`
|
|
54
|
+
* getter), or the serialized raw form `{ value, precision }`. A naive
|
|
55
|
+
* `Number(amount)` returns `NaN` for the object forms — which silently turns a
|
|
56
|
+
* partial refund/capture into a full one and produces a `…-NaN` idempotency key.
|
|
57
|
+
*/
|
|
58
|
+
export function toAmountNumber(amount: unknown): number {
|
|
59
|
+
if (amount === null || amount === undefined) {
|
|
60
|
+
return 0
|
|
61
|
+
}
|
|
62
|
+
if (typeof amount === "number") {
|
|
63
|
+
if (!Number.isFinite(amount)) {
|
|
64
|
+
throw new Error(`Invalid payment amount: non-finite number (${amount})`)
|
|
65
|
+
}
|
|
66
|
+
return amount
|
|
67
|
+
}
|
|
68
|
+
if (typeof amount === "string") {
|
|
69
|
+
// `Number("")` and `Number(" ")` both coerce to 0 — treat a blank string
|
|
70
|
+
// as invalid rather than let it silently become a zero amount (which would
|
|
71
|
+
// turn a partial refund/capture into a full one).
|
|
72
|
+
if (amount.trim() === "") {
|
|
73
|
+
throw new Error(`Invalid payment amount: unparseable string "${amount}"`)
|
|
74
|
+
}
|
|
75
|
+
const parsed = Number(amount)
|
|
76
|
+
if (!Number.isFinite(parsed)) {
|
|
77
|
+
throw new Error(`Invalid payment amount: unparseable string "${amount}"`)
|
|
78
|
+
}
|
|
79
|
+
return parsed
|
|
80
|
+
}
|
|
81
|
+
if (typeof amount === "object") {
|
|
82
|
+
const obj = amount as Record<string, unknown>
|
|
83
|
+
// Medusa BigNumber instance.
|
|
84
|
+
if (typeof obj.numeric === "number" && Number.isFinite(obj.numeric)) {
|
|
85
|
+
return obj.numeric
|
|
86
|
+
}
|
|
87
|
+
// Serialized raw form: { value: "20", precision: 20 }.
|
|
88
|
+
if (obj.value !== undefined && obj.value !== null) {
|
|
89
|
+
// Guard the blank-string-coerces-to-0 case here too (see string branch).
|
|
90
|
+
if (typeof obj.value === "string" && obj.value.trim() === "") {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Invalid payment amount: unparseable BigNumber value "${obj.value}"`
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
const parsed = Number(obj.value)
|
|
96
|
+
if (!Number.isFinite(parsed)) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Invalid payment amount: unparseable BigNumber value "${obj.value}"`
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
return parsed
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Invalid payment amount: unrecognized type (${typeof amount})`
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Format a Medusa amount for the PayPal REST API.
|
|
111
|
+
*
|
|
112
|
+
* Medusa passes monetary amounts to payment providers in MAJOR units
|
|
113
|
+
* (e.g. `10` for €10.00), and PayPal's Orders/Payments API also expects major
|
|
114
|
+
* units as a string (e.g. `"10.00"`). So this only fixes the decimal precision
|
|
115
|
+
* for the currency — it must NOT divide/convert to minor units.
|
|
116
|
+
*/
|
|
117
|
+
export function formatAmountForPayPal(amount: number, currencyCode: string) {
|
|
118
|
+
if (!Number.isFinite(amount)) {
|
|
119
|
+
throw new Error(`Invalid payment amount for PayPal formatting: ${amount}`)
|
|
120
|
+
}
|
|
121
|
+
const exponent = getCurrencyExponent(currencyCode)
|
|
122
|
+
return amount.toFixed(exponent)
|
|
123
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { MedusaWorkflow } from "@medusajs/framework/workflows-sdk"
|
|
2
|
-
import type { MedusaContainer } from "@medusajs/framework"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Run a Medusa *core* workflow by its registered id, without importing it from
|
|
6
|
-
* `@medusajs/core-flows`.
|
|
7
|
-
*
|
|
8
|
-
* Why this exists:
|
|
9
|
-
* Importing anything from `@medusajs/core-flows` (e.g.
|
|
10
|
-
* `import { completeCartWorkflow } from "@medusajs/core-flows"`) pulls in the
|
|
11
|
-
* entire core-flows barrel. Every workflow module in that barrel calls
|
|
12
|
-
* `createWorkflow(...)` at import time, which registers the workflow in the
|
|
13
|
-
* global `WorkflowManager`. When this plugin is resolved as a *separate* copy
|
|
14
|
-
* of `@medusajs/core-flows` from the host application — which is exactly what
|
|
15
|
-
* happens when the plugin is consumed as a locally-linked package living
|
|
16
|
-
* outside the app's `node_modules` (e.g. a sibling folder with its own
|
|
17
|
-
* `node_modules`) — those registrations run a second time and collide with the
|
|
18
|
-
* host's already-registered workflows. Medusa then aborts boot with:
|
|
19
|
-
*
|
|
20
|
-
* An error occurred while registering API Routes.
|
|
21
|
-
* Error: Workflow with id "create-fulfillment-workflow" and step definition
|
|
22
|
-
* already exists.
|
|
23
|
-
*
|
|
24
|
-
* (The id is whichever core workflow happens to register first.)
|
|
25
|
-
*
|
|
26
|
-
* The host registers every core workflow into the global `MedusaWorkflow`
|
|
27
|
-
* registry at startup. Looking the workflow up there and running it reuses that
|
|
28
|
-
* single registered instance and never triggers a second registration, so the
|
|
29
|
-
* plugin works regardless of how it is installed or linked.
|
|
30
|
-
*/
|
|
31
|
-
export async function runCoreWorkflow<TInput = unknown, TResult = unknown>(
|
|
32
|
-
container: MedusaContainer,
|
|
33
|
-
workflowId: string,
|
|
34
|
-
input: TInput
|
|
35
|
-
): Promise<{ result: TResult }> {
|
|
36
|
-
const workflow = MedusaWorkflow.getWorkflow(workflowId)
|
|
37
|
-
|
|
38
|
-
if (!workflow) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Core workflow "${workflowId}" is not registered. ` +
|
|
41
|
-
`Ensure the Medusa application has loaded its core workflows.`
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return workflow(container).run({ input })
|
|
46
|
-
}
|
|
1
|
+
import { MedusaWorkflow } from "@medusajs/framework/workflows-sdk"
|
|
2
|
+
import type { MedusaContainer } from "@medusajs/framework"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Run a Medusa *core* workflow by its registered id, without importing it from
|
|
6
|
+
* `@medusajs/core-flows`.
|
|
7
|
+
*
|
|
8
|
+
* Why this exists:
|
|
9
|
+
* Importing anything from `@medusajs/core-flows` (e.g.
|
|
10
|
+
* `import { completeCartWorkflow } from "@medusajs/core-flows"`) pulls in the
|
|
11
|
+
* entire core-flows barrel. Every workflow module in that barrel calls
|
|
12
|
+
* `createWorkflow(...)` at import time, which registers the workflow in the
|
|
13
|
+
* global `WorkflowManager`. When this plugin is resolved as a *separate* copy
|
|
14
|
+
* of `@medusajs/core-flows` from the host application — which is exactly what
|
|
15
|
+
* happens when the plugin is consumed as a locally-linked package living
|
|
16
|
+
* outside the app's `node_modules` (e.g. a sibling folder with its own
|
|
17
|
+
* `node_modules`) — those registrations run a second time and collide with the
|
|
18
|
+
* host's already-registered workflows. Medusa then aborts boot with:
|
|
19
|
+
*
|
|
20
|
+
* An error occurred while registering API Routes.
|
|
21
|
+
* Error: Workflow with id "create-fulfillment-workflow" and step definition
|
|
22
|
+
* already exists.
|
|
23
|
+
*
|
|
24
|
+
* (The id is whichever core workflow happens to register first.)
|
|
25
|
+
*
|
|
26
|
+
* The host registers every core workflow into the global `MedusaWorkflow`
|
|
27
|
+
* registry at startup. Looking the workflow up there and running it reuses that
|
|
28
|
+
* single registered instance and never triggers a second registration, so the
|
|
29
|
+
* plugin works regardless of how it is installed or linked.
|
|
30
|
+
*/
|
|
31
|
+
export async function runCoreWorkflow<TInput = unknown, TResult = unknown>(
|
|
32
|
+
container: MedusaContainer,
|
|
33
|
+
workflowId: string,
|
|
34
|
+
input: TInput
|
|
35
|
+
): Promise<{ result: TResult }> {
|
|
36
|
+
const workflow = MedusaWorkflow.getWorkflow(workflowId)
|
|
37
|
+
|
|
38
|
+
if (!workflow) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Core workflow "${workflowId}" is not registered. ` +
|
|
41
|
+
`Ensure the Medusa application has loaded its core workflows.`
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return workflow(container).run({ input })
|
|
46
|
+
}
|