@easypayment/medusa-payment-paypal 1.2.3 → 1.2.5
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 +392 -138
- package/.medusa/server/src/admin/index.mjs +392 -138
- 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 +11 -1
- 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 +80 -26
- 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 +55 -8
- 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 +24 -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 +296 -0
- 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 -7
- 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 +40 -198
- 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 +9 -2
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +29 -181
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/status-utils.d.ts +21 -0
- package/.medusa/server/src/modules/paypal/payment-provider/status-utils.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/status-utils.js +54 -0
- package/.medusa/server/src/modules/paypal/payment-provider/status-utils.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 +10 -0
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +45 -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 +65 -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 +69 -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 +611 -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 +184 -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 +700 -275
- package/src/modules/paypal/payment-provider/card-service.ts +693 -855
- package/src/modules/paypal/payment-provider/index.ts +14 -15
- package/src/modules/paypal/payment-provider/service.ts +673 -836
- package/src/modules/paypal/payment-provider/status-utils.ts +116 -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 +315 -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,113 +1,116 @@
|
|
|
1
|
-
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
-
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Public PayPal onboarding `return_url`.
|
|
6
|
-
*
|
|
7
|
-
* When a seller finishes onboarding, PayPal redirects the mini-browser popup to
|
|
8
|
-
* this URL as a plain top-level navigation (no auth header / no publishable key),
|
|
9
|
-
* which is why it must live under the public `/store/paypal/*` namespace rather
|
|
10
|
-
* than `/admin/*`. Leaving the popup on a raw JSON / 401 / 405 page is exactly
|
|
11
|
-
* what made the popup appear to "never close".
|
|
12
|
-
*
|
|
13
|
-
* This route is the authoritative, partner.js-independent completion path. It:
|
|
14
|
-
* 1. exchanges PayPal's `authCode` + `sharedId` for seller credentials
|
|
15
|
-
* server-side (idempotent — safe even if partner.js's onboardingCallback or
|
|
16
|
-
* admin status polling also completes the exchange),
|
|
17
|
-
* 2. relays whatever query params PayPal appended back to the opener (the
|
|
18
|
-
* Medusa Admin connection page) via postMessage so it can refresh
|
|
19
|
-
* immediately, and
|
|
20
|
-
* 3. closes the popup.
|
|
21
|
-
*
|
|
22
|
-
* Because the exchange no longer depends on the opener receiving an in-flight
|
|
23
|
-
* postMessage, onboarding completes (and the admin page flips to "connected" via
|
|
24
|
-
* its status poll) even when partner.js never fires its callback.
|
|
25
|
-
*/
|
|
26
|
-
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
27
|
-
const query = (req.query || {}) as Record<string, unknown>
|
|
28
|
-
const params: Record<string, string> = {}
|
|
29
|
-
for (const [k, v] of Object.entries(query)) {
|
|
30
|
-
if (v == null) continue
|
|
31
|
-
params[k] = Array.isArray(v) ? String(v[0]) : String(v)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// PayPal appends the seller's authorization code + shared id to the return_url
|
|
35
|
-
// (plus the env we pinned when generating the link). When present, complete the
|
|
36
|
-
// exchange right here so credentials are saved even if no other path runs.
|
|
37
|
-
const authCode = params.authCode || params.auth_code
|
|
38
|
-
const sharedId = params.sharedId || params.shared_id
|
|
39
|
-
const env =
|
|
40
|
-
params.env === "sandbox" || params.env === "live" ? params.env : undefined
|
|
41
|
-
|
|
42
|
-
if (authCode && sharedId) {
|
|
43
|
-
try {
|
|
44
|
-
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
45
|
-
await paypal.exchangeAndSaveSellerCredentials({ authCode, sharedId, env })
|
|
46
|
-
} catch (e: unknown) {
|
|
47
|
-
// Don't break the popup close on failure — relay the params so the opener
|
|
48
|
-
// (partner.js / admin polling) can still attempt to complete.
|
|
49
|
-
console.error(
|
|
50
|
-
"[PayPal] onboard-return exchange failed:",
|
|
51
|
-
e instanceof Error ? e.message : e
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Restrict the postMessage target to the configured admin origin instead of
|
|
57
|
-
// the "*" wildcard (which would deliver the relayed onboarding params to any
|
|
58
|
-
// origin that happens to open this popup). Prefer PAYPAL_ADMIN_ORIGIN, then
|
|
59
|
-
// the first entry of ADMIN_CORS; fall back to "*" only when neither is set,
|
|
60
|
-
// logging a warning so operators know to lock it down.
|
|
61
|
-
const resolveAdminOrigin = (): string => {
|
|
62
|
-
const explicit = (process.env.PAYPAL_ADMIN_ORIGIN || "").trim()
|
|
63
|
-
if (explicit) return explicit
|
|
64
|
-
const firstCors = (process.env.ADMIN_CORS || "")
|
|
65
|
-
.split(",")
|
|
66
|
-
.map((s) => s.trim())
|
|
67
|
-
.find(Boolean)
|
|
68
|
-
if (firstCors) return firstCors
|
|
69
|
-
console.warn(
|
|
70
|
-
"[PayPal] onboard-return: PAYPAL_ADMIN_ORIGIN/ADMIN_CORS not set \u2014 relaying onboarding result to postMessage origin '*'. Set PAYPAL_ADMIN_ORIGIN to your admin URL to restrict it."
|
|
71
|
-
)
|
|
72
|
-
return "*"
|
|
73
|
-
}
|
|
74
|
-
const targetOrigin = resolveAdminOrigin()
|
|
75
|
-
|
|
76
|
-
// JSON-encode then escape the characters that could break out of the inline
|
|
77
|
-
// <script> string/tag (including the U+2028/U+2029 separators that are legal in
|
|
78
|
-
// JSON but illegal in a JS string literal), so the relayed params embed safely.
|
|
79
|
-
const escapeForScript = (value: string) =>
|
|
80
|
-
value
|
|
81
|
-
.replace(/</g, "\\u003c")
|
|
82
|
-
.replace(/>/g, "\\u003e")
|
|
83
|
-
.replace(/&/g, "\\u0026")
|
|
84
|
-
.replace(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
<
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Public PayPal onboarding `return_url`.
|
|
6
|
+
*
|
|
7
|
+
* When a seller finishes onboarding, PayPal redirects the mini-browser popup to
|
|
8
|
+
* this URL as a plain top-level navigation (no auth header / no publishable key),
|
|
9
|
+
* which is why it must live under the public `/store/paypal/*` namespace rather
|
|
10
|
+
* than `/admin/*`. Leaving the popup on a raw JSON / 401 / 405 page is exactly
|
|
11
|
+
* what made the popup appear to "never close".
|
|
12
|
+
*
|
|
13
|
+
* This route is the authoritative, partner.js-independent completion path. It:
|
|
14
|
+
* 1. exchanges PayPal's `authCode` + `sharedId` for seller credentials
|
|
15
|
+
* server-side (idempotent — safe even if partner.js's onboardingCallback or
|
|
16
|
+
* admin status polling also completes the exchange),
|
|
17
|
+
* 2. relays whatever query params PayPal appended back to the opener (the
|
|
18
|
+
* Medusa Admin connection page) via postMessage so it can refresh
|
|
19
|
+
* immediately, and
|
|
20
|
+
* 3. closes the popup.
|
|
21
|
+
*
|
|
22
|
+
* Because the exchange no longer depends on the opener receiving an in-flight
|
|
23
|
+
* postMessage, onboarding completes (and the admin page flips to "connected" via
|
|
24
|
+
* its status poll) even when partner.js never fires its callback.
|
|
25
|
+
*/
|
|
26
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
27
|
+
const query = (req.query || {}) as Record<string, unknown>
|
|
28
|
+
const params: Record<string, string> = {}
|
|
29
|
+
for (const [k, v] of Object.entries(query)) {
|
|
30
|
+
if (v == null) continue
|
|
31
|
+
params[k] = Array.isArray(v) ? String(v[0]) : String(v)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// PayPal appends the seller's authorization code + shared id to the return_url
|
|
35
|
+
// (plus the env we pinned when generating the link). When present, complete the
|
|
36
|
+
// exchange right here so credentials are saved even if no other path runs.
|
|
37
|
+
const authCode = params.authCode || params.auth_code
|
|
38
|
+
const sharedId = params.sharedId || params.shared_id
|
|
39
|
+
const env =
|
|
40
|
+
params.env === "sandbox" || params.env === "live" ? params.env : undefined
|
|
41
|
+
|
|
42
|
+
if (authCode && sharedId) {
|
|
43
|
+
try {
|
|
44
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
45
|
+
await paypal.exchangeAndSaveSellerCredentials({ authCode, sharedId, env })
|
|
46
|
+
} catch (e: unknown) {
|
|
47
|
+
// Don't break the popup close on failure — relay the params so the opener
|
|
48
|
+
// (partner.js / admin polling) can still attempt to complete.
|
|
49
|
+
console.error(
|
|
50
|
+
"[PayPal] onboard-return exchange failed:",
|
|
51
|
+
e instanceof Error ? e.message : e
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Restrict the postMessage target to the configured admin origin instead of
|
|
57
|
+
// the "*" wildcard (which would deliver the relayed onboarding params to any
|
|
58
|
+
// origin that happens to open this popup). Prefer PAYPAL_ADMIN_ORIGIN, then
|
|
59
|
+
// the first entry of ADMIN_CORS; fall back to "*" only when neither is set,
|
|
60
|
+
// logging a warning so operators know to lock it down.
|
|
61
|
+
const resolveAdminOrigin = (): string => {
|
|
62
|
+
const explicit = (process.env.PAYPAL_ADMIN_ORIGIN || "").trim()
|
|
63
|
+
if (explicit) return explicit
|
|
64
|
+
const firstCors = (process.env.ADMIN_CORS || "")
|
|
65
|
+
.split(",")
|
|
66
|
+
.map((s) => s.trim())
|
|
67
|
+
.find(Boolean)
|
|
68
|
+
if (firstCors) return firstCors
|
|
69
|
+
console.warn(
|
|
70
|
+
"[PayPal] onboard-return: PAYPAL_ADMIN_ORIGIN/ADMIN_CORS not set \u2014 relaying onboarding result to postMessage origin '*'. Set PAYPAL_ADMIN_ORIGIN to your admin URL to restrict it."
|
|
71
|
+
)
|
|
72
|
+
return "*"
|
|
73
|
+
}
|
|
74
|
+
const targetOrigin = resolveAdminOrigin()
|
|
75
|
+
|
|
76
|
+
// JSON-encode then escape the characters that could break out of the inline
|
|
77
|
+
// <script> string/tag (including the U+2028/U+2029 separators that are legal in
|
|
78
|
+
// JSON but illegal in a JS string literal), so the relayed params embed safely.
|
|
79
|
+
const escapeForScript = (value: string) =>
|
|
80
|
+
value
|
|
81
|
+
.replace(/</g, "\\u003c")
|
|
82
|
+
.replace(/>/g, "\\u003e")
|
|
83
|
+
.replace(/&/g, "\\u0026")
|
|
84
|
+
.replace(
|
|
85
|
+
/[\u2028\u2029]/g,
|
|
86
|
+
(c) => "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const safePayload = escapeForScript(JSON.stringify(params))
|
|
90
|
+
const safeTargetOrigin = escapeForScript(JSON.stringify(targetOrigin))
|
|
91
|
+
|
|
92
|
+
const html = `<!doctype html>
|
|
93
|
+
<html lang="en">
|
|
94
|
+
<head><meta charset="utf-8" /><title>PayPal onboarding complete</title></head>
|
|
95
|
+
<body style="font-family: system-ui, sans-serif; padding: 24px; text-align: center; color: #1f2937;">
|
|
96
|
+
<p>PayPal onboarding complete. You can close this window.</p>
|
|
97
|
+
<script>
|
|
98
|
+
(function () {
|
|
99
|
+
try {
|
|
100
|
+
var message = { source: "paypal-onboarding-return", params: ${safePayload} };
|
|
101
|
+
var targetOrigin = ${safeTargetOrigin};
|
|
102
|
+
if (window.opener && !window.opener.closed) {
|
|
103
|
+
try { window.opener.postMessage(message, targetOrigin); } catch (e) {}
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {}
|
|
106
|
+
// Give the opener a moment to react, then close the popup.
|
|
107
|
+
setTimeout(function () { try { window.close(); } catch (e) {} }, 600);
|
|
108
|
+
})();
|
|
109
|
+
</script>
|
|
110
|
+
</body>
|
|
111
|
+
</html>`
|
|
112
|
+
|
|
113
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8")
|
|
114
|
+
res.setHeader("Cache-Control", "no-store")
|
|
115
|
+
return res.status(200).send(html)
|
|
116
|
+
}
|
|
@@ -1,19 +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
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
+
|
|
4
|
+
/** GET /store/paypal/settings — the subset of settings the storefront needs. */
|
|
5
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
7
|
+
try {
|
|
8
|
+
const settings = await paypal.getSettings()
|
|
9
|
+
const data = (settings?.data || {}) as Record<string, any>
|
|
10
|
+
const additionalSettings = (data.additional_settings || {}) as Record<
|
|
11
|
+
string,
|
|
12
|
+
any
|
|
13
|
+
>
|
|
14
|
+
const advancedCard = (data.advanced_card_payments || {}) as Record<
|
|
15
|
+
string,
|
|
16
|
+
any
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
return res.json({
|
|
20
|
+
paymentAction:
|
|
21
|
+
additionalSettings.paymentAction === "authorize"
|
|
22
|
+
? "authorize"
|
|
23
|
+
: "capture",
|
|
24
|
+
advancedCardEnabled: advancedCard.enabled !== false,
|
|
25
|
+
})
|
|
26
|
+
} catch {
|
|
27
|
+
return res.status(500).json({ message: "Failed to load PayPal settings" })
|
|
28
|
+
}
|
|
29
|
+
}
|