@easypayment/medusa-payment-paypal 1.2.2 → 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 +390 -136
- package/.medusa/server/src/admin/index.mjs +390 -136
- 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 +19 -0
- package/README.md +184 -175
- package/package.json +24 -5
- 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,45 +1,63 @@
|
|
|
1
|
-
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
-
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
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
|
-
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
+
|
|
4
|
+
/** GET /admin/paypal/settings — the full settings singleton. */
|
|
5
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
try {
|
|
7
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
8
|
+
return res.json(await paypal.getSettings())
|
|
9
|
+
} catch (e: unknown) {
|
|
10
|
+
console.error(
|
|
11
|
+
"[PayPal] settings GET failed:",
|
|
12
|
+
e instanceof Error ? e.message : e
|
|
13
|
+
)
|
|
14
|
+
return res.status(500).json({ message: "Failed to load PayPal settings" })
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Top-level settings sections an admin may write; anything else is dropped. */
|
|
19
|
+
const ALLOWED_SETTINGS_KEYS = new Set([
|
|
20
|
+
"additional_settings",
|
|
21
|
+
"paypal_settings",
|
|
22
|
+
"advanced_card_payments",
|
|
23
|
+
"pay_later_messaging",
|
|
24
|
+
"apple_pay",
|
|
25
|
+
"google_pay",
|
|
26
|
+
"api_details",
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
/** POST /admin/paypal/settings — deep-merge the allowed sections of the body. */
|
|
30
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
31
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
32
|
+
|
|
33
|
+
const raw =
|
|
34
|
+
req.body && typeof req.body === "object"
|
|
35
|
+
? (req.body as Record<string, unknown>)
|
|
36
|
+
: {}
|
|
37
|
+
const patch: Record<string, unknown> = {}
|
|
38
|
+
for (const key of Object.keys(raw)) {
|
|
39
|
+
if (ALLOWED_SETTINGS_KEYS.has(key)) {
|
|
40
|
+
patch[key] = raw[key]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Object.keys(patch).length === 0) {
|
|
45
|
+
return res
|
|
46
|
+
.status(400)
|
|
47
|
+
.json({ message: "No valid settings fields provided" })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
return res.json(
|
|
52
|
+
await paypal.saveSettings(
|
|
53
|
+
patch as Record<string, Record<string, unknown>>
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
} catch (e: unknown) {
|
|
57
|
+
console.error(
|
|
58
|
+
"[PayPal] settings POST failed:",
|
|
59
|
+
e instanceof Error ? e.message : e
|
|
60
|
+
)
|
|
61
|
+
return res.status(500).json({ message: "Failed to save PayPal settings" })
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
-
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GET /admin/paypal/status[?environment=sandbox|live] — connection status.
|
|
6
|
+
* Read-only: never triggers the seller-profile backfill.
|
|
7
|
+
*/
|
|
8
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
9
|
+
try {
|
|
10
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
11
|
+
|
|
12
|
+
const q = (req.query || {}) as Record<string, any>
|
|
13
|
+
const envParam = (q.environment || q.env) as string | undefined
|
|
14
|
+
const env =
|
|
15
|
+
envParam === "live"
|
|
16
|
+
? "live"
|
|
17
|
+
: envParam === "sandbox"
|
|
18
|
+
? "sandbox"
|
|
19
|
+
: undefined
|
|
20
|
+
|
|
21
|
+
return res.json(await paypal.getStatus(env))
|
|
22
|
+
} catch (e: unknown) {
|
|
23
|
+
console.error(
|
|
24
|
+
"[PayPal] status GET failed:",
|
|
25
|
+
e instanceof Error ? e.message : e
|
|
26
|
+
)
|
|
27
|
+
return res.status(500).json({ message: "Failed to retrieve PayPal status" })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PayPal onboarding `return_url` under the `/hooks` namespace.
|
|
3
|
-
*
|
|
4
|
-
* PayPal redirects the onboarding popup here as a plain top-level browser
|
|
5
|
-
* navigation, which carries no `x-publishable-api-key` header — and Medusa's
|
|
6
|
-
* store publishable-key middleware rejects every `/store/*` request without
|
|
7
|
-
* that header before the handler runs. Hosting the return bridge under
|
|
8
|
-
* `/hooks` (no publishable-key guard) lets the popup complete the credential
|
|
9
|
-
* exchange and close itself.
|
|
10
|
-
*
|
|
11
|
-
* The legacy `/store/paypal/onboard-return` route is kept for deployments
|
|
12
|
-
* whose edge injects the key; both paths share this exact handler. Newly
|
|
13
|
-
* generated onboarding links point at `/hooks/paypal/onboard-return`.
|
|
14
|
-
*/
|
|
15
|
-
export { GET } from "../../../store/paypal/onboard-return/route"
|
|
1
|
+
/**
|
|
2
|
+
* PayPal onboarding `return_url` under the `/hooks` namespace.
|
|
3
|
+
*
|
|
4
|
+
* PayPal redirects the onboarding popup here as a plain top-level browser
|
|
5
|
+
* navigation, which carries no `x-publishable-api-key` header — and Medusa's
|
|
6
|
+
* store publishable-key middleware rejects every `/store/*` request without
|
|
7
|
+
* that header before the handler runs. Hosting the return bridge under
|
|
8
|
+
* `/hooks` (no publishable-key guard) lets the popup complete the credential
|
|
9
|
+
* exchange and close itself.
|
|
10
|
+
*
|
|
11
|
+
* The legacy `/store/paypal/onboard-return` route is kept for deployments
|
|
12
|
+
* whose edge injects the key; both paths share this exact handler. Newly
|
|
13
|
+
* generated onboarding links point at `/hooks/paypal/onboard-return`.
|
|
14
|
+
*/
|
|
15
|
+
export { GET } from "../../../store/paypal/onboard-return/route"
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PayPal webhook endpoint under the `/hooks` namespace.
|
|
3
|
-
*
|
|
4
|
-
* Medusa applies its store publishable-key middleware to EVERY `/store/*`
|
|
5
|
-
* route, and PayPal's webhook delivery cannot send the
|
|
6
|
-
* `x-publishable-api-key` header — so the original
|
|
7
|
-
* `/store/paypal/webhook` endpoint is rejected with NOT_ALLOWED before the
|
|
8
|
-
* handler runs unless a reverse proxy injects the header. The `/hooks`
|
|
9
|
-
* namespace (the same one Medusa core uses for provider webhooks) has no such
|
|
10
|
-
* guard, so external callers can reach it directly.
|
|
11
|
-
*
|
|
12
|
-
* The `/store/paypal/webhook` route is kept for deployments that already
|
|
13
|
-
* inject the key at their edge; both paths share this exact handler. New
|
|
14
|
-
* webhook registrations (and migrated existing ones) point at
|
|
15
|
-
* `/hooks/paypal/webhook`.
|
|
16
|
-
*/
|
|
17
|
-
export { POST } from "../../../store/paypal/webhook/route"
|
|
1
|
+
/**
|
|
2
|
+
* PayPal webhook endpoint under the `/hooks` namespace.
|
|
3
|
+
*
|
|
4
|
+
* Medusa applies its store publishable-key middleware to EVERY `/store/*`
|
|
5
|
+
* route, and PayPal's webhook delivery cannot send the
|
|
6
|
+
* `x-publishable-api-key` header — so the original
|
|
7
|
+
* `/store/paypal/webhook` endpoint is rejected with NOT_ALLOWED before the
|
|
8
|
+
* handler runs unless a reverse proxy injects the header. The `/hooks`
|
|
9
|
+
* namespace (the same one Medusa core uses for provider webhooks) has no such
|
|
10
|
+
* guard, so external callers can reach it directly.
|
|
11
|
+
*
|
|
12
|
+
* The `/store/paypal/webhook` route is kept for deployments that already
|
|
13
|
+
* inject the key at their edge; both paths share this exact handler. New
|
|
14
|
+
* webhook registrations (and migrated existing ones) point at
|
|
15
|
+
* `/hooks/paypal/webhook`.
|
|
16
|
+
*/
|
|
17
|
+
export { POST } from "../../../store/paypal/webhook/route"
|
package/src/api/middlewares.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { defineMiddlewares } from "@medusajs/framework/http"
|
|
2
|
-
import { createRateLimiter } from "./utils/rate-limit"
|
|
3
|
-
|
|
4
|
-
export default defineMiddlewares({
|
|
5
|
-
routes: [
|
|
6
|
-
{
|
|
7
|
-
// Keep the exact bytes PayPal signed (`req.rawBody`) so webhook signature
|
|
8
|
-
// verification hashes the original payload, not a re-serialized copy. This
|
|
9
|
-
// entry must precede the "/store/paypal/:path*" catch-all below.
|
|
10
|
-
// Rate-limited (opt-in, like the store routes): every unauthenticated
|
|
11
|
-
// POST here costs a DB dedup read plus an outbound PayPal
|
|
12
|
-
// verify-webhook-signature call, and a flood of garbage requests could
|
|
13
|
-
// trip the shared circuit breaker for legitimate verifications.
|
|
14
|
-
matcher: "/store/paypal/webhook",
|
|
15
|
-
method: ["POST"],
|
|
16
|
-
bodyParser: { preserveRawBody: true },
|
|
17
|
-
middlewares: [
|
|
18
|
-
createRateLimiter("webhook", {
|
|
19
|
-
maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
|
|
20
|
-
windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
// Same raw-body requirement for the /hooks mirror of the webhook route —
|
|
26
|
-
// the path external PayPal deliveries actually reach, since Medusa's
|
|
27
|
-
// publishable-key middleware blocks unauthenticated POSTs to /store/*.
|
|
28
|
-
matcher: "/hooks/paypal/webhook",
|
|
29
|
-
method: ["POST"],
|
|
30
|
-
bodyParser: { preserveRawBody: true },
|
|
31
|
-
middlewares: [
|
|
32
|
-
createRateLimiter("webhook-hooks", {
|
|
33
|
-
maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
|
|
34
|
-
windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
|
|
35
|
-
}),
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
// Rate-limit the order-creating route: unauthenticated by necessity, so
|
|
40
|
-
// cap how fast one client can spin up PayPal orders on the merchant
|
|
41
|
-
// account. Each createRateLimiter() call builds its own counter at boot.
|
|
42
|
-
matcher: "/store/paypal/create-order",
|
|
43
|
-
method: ["POST"],
|
|
44
|
-
middlewares: [createRateLimiter("create-order")],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
matcher: "/store/paypal/capture-order",
|
|
48
|
-
method: ["POST"],
|
|
49
|
-
middlewares: [createRateLimiter("capture-order")],
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
matcher: "/store/paypal-complete",
|
|
53
|
-
method: ["POST"],
|
|
54
|
-
middlewares: [createRateLimiter("paypal-complete")],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
matcher: "/store/paypal/:path*",
|
|
58
|
-
middlewares: [],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
})
|
|
1
|
+
import { defineMiddlewares } from "@medusajs/framework/http"
|
|
2
|
+
import { createRateLimiter } from "./utils/rate-limit"
|
|
3
|
+
|
|
4
|
+
export default defineMiddlewares({
|
|
5
|
+
routes: [
|
|
6
|
+
{
|
|
7
|
+
// Keep the exact bytes PayPal signed (`req.rawBody`) so webhook signature
|
|
8
|
+
// verification hashes the original payload, not a re-serialized copy. This
|
|
9
|
+
// entry must precede the "/store/paypal/:path*" catch-all below.
|
|
10
|
+
// Rate-limited (opt-in, like the store routes): every unauthenticated
|
|
11
|
+
// POST here costs a DB dedup read plus an outbound PayPal
|
|
12
|
+
// verify-webhook-signature call, and a flood of garbage requests could
|
|
13
|
+
// trip the shared circuit breaker for legitimate verifications.
|
|
14
|
+
matcher: "/store/paypal/webhook",
|
|
15
|
+
method: ["POST"],
|
|
16
|
+
bodyParser: { preserveRawBody: true },
|
|
17
|
+
middlewares: [
|
|
18
|
+
createRateLimiter("webhook", {
|
|
19
|
+
maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
|
|
20
|
+
windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
// Same raw-body requirement for the /hooks mirror of the webhook route —
|
|
26
|
+
// the path external PayPal deliveries actually reach, since Medusa's
|
|
27
|
+
// publishable-key middleware blocks unauthenticated POSTs to /store/*.
|
|
28
|
+
matcher: "/hooks/paypal/webhook",
|
|
29
|
+
method: ["POST"],
|
|
30
|
+
bodyParser: { preserveRawBody: true },
|
|
31
|
+
middlewares: [
|
|
32
|
+
createRateLimiter("webhook-hooks", {
|
|
33
|
+
maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
|
|
34
|
+
windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
// Rate-limit the order-creating route: unauthenticated by necessity, so
|
|
40
|
+
// cap how fast one client can spin up PayPal orders on the merchant
|
|
41
|
+
// account. Each createRateLimiter() call builds its own counter at boot.
|
|
42
|
+
matcher: "/store/paypal/create-order",
|
|
43
|
+
method: ["POST"],
|
|
44
|
+
middlewares: [createRateLimiter("create-order")],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
matcher: "/store/paypal/capture-order",
|
|
48
|
+
method: ["POST"],
|
|
49
|
+
middlewares: [createRateLimiter("capture-order")],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
matcher: "/store/paypal-complete",
|
|
53
|
+
method: ["POST"],
|
|
54
|
+
middlewares: [createRateLimiter("paypal-complete")],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
matcher: "/store/paypal/:path*",
|
|
58
|
+
middlewares: [],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
})
|
|
@@ -1,54 +1,63 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
1
|
+
import {
|
|
2
|
+
MedusaResponse,
|
|
3
|
+
MedusaStoreRequest,
|
|
4
|
+
refetchEntity,
|
|
5
|
+
} from "@medusajs/framework/http"
|
|
6
|
+
import { MedusaError } from "@medusajs/framework/utils"
|
|
7
|
+
import { runCoreWorkflow } from "../../../../../modules/paypal/utils/core-workflow"
|
|
8
|
+
|
|
9
|
+
type CreatePaymentSessionBody = {
|
|
10
|
+
provider_id: string
|
|
11
|
+
data?: Record<string, unknown>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Fields returned when the request carries no explicit `fields` query. */
|
|
15
|
+
const defaultPaymentCollectionFields = [
|
|
16
|
+
"id",
|
|
17
|
+
"currency_code",
|
|
18
|
+
"amount",
|
|
19
|
+
"*payment_sessions",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* POST /store/payment-collections/:id/payment-sessions — create a payment
|
|
24
|
+
* session via the core workflow and return the refreshed collection.
|
|
25
|
+
*/
|
|
26
|
+
export async function POST(req: MedusaStoreRequest, res: MedusaResponse) {
|
|
27
|
+
const collectionId = req.params.id
|
|
28
|
+
|
|
29
|
+
const { provider_id, data } = req.body as CreatePaymentSessionBody
|
|
30
|
+
|
|
31
|
+
if (!provider_id || typeof provider_id !== "string") {
|
|
32
|
+
throw new MedusaError(
|
|
33
|
+
MedusaError.Types.INVALID_DATA,
|
|
34
|
+
"provider_id is required to create a payment session"
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await runCoreWorkflow(req.scope, "create-payment-sessions", {
|
|
40
|
+
payment_collection_id: collectionId,
|
|
41
|
+
provider_id,
|
|
42
|
+
customer_id: req.auth_context?.actor_id,
|
|
43
|
+
data,
|
|
44
|
+
})
|
|
45
|
+
} catch (error) {
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
47
|
+
throw new MedusaError(
|
|
48
|
+
MedusaError.Types.UNEXPECTED_STATE,
|
|
49
|
+
`Failed to create payment session for provider '${provider_id}': ${message}`
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const paymentCollection = await refetchEntity({
|
|
54
|
+
entity: "payment_collection",
|
|
55
|
+
idOrFilter: collectionId,
|
|
56
|
+
scope: req.scope,
|
|
57
|
+
fields: req.queryConfig?.fields ?? defaultPaymentCollectionFields,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
res.status(200).json({
|
|
61
|
+
payment_collection: paymentCollection,
|
|
62
|
+
})
|
|
63
|
+
}
|