@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,128 +1,184 @@
|
|
|
1
|
-
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
-
import type { IPaymentModuleService, Logger } from "@medusajs/framework/types"
|
|
3
|
-
import {
|
|
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
|
-
if (
|
|
53
|
-
return res.
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { IPaymentModuleService, Logger } from "@medusajs/framework/types"
|
|
3
|
+
import {
|
|
4
|
+
ContainerRegistrationKeys,
|
|
5
|
+
MedusaError,
|
|
6
|
+
Modules,
|
|
7
|
+
} from "@medusajs/framework/utils"
|
|
8
|
+
import { randomUUID } from "crypto"
|
|
9
|
+
import { isPayPalProviderId } from "../../../modules/paypal/utils/provider-ids"
|
|
10
|
+
import { runCoreWorkflow } from "../../../modules/paypal/utils/core-workflow"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* POST /store/paypal-complete — finalize a cart after the buyer's PayPal
|
|
14
|
+
* payment was captured/authorized.
|
|
15
|
+
*
|
|
16
|
+
* Authorizes the PayPal payment session (which re-verifies the payment against
|
|
17
|
+
* PayPal) and then runs the core complete-cart workflow. A cart completed by a
|
|
18
|
+
* concurrent request (e.g. the webhook safety net) is reported as success.
|
|
19
|
+
*/
|
|
20
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
21
|
+
const logger = req.scope.resolve<Logger>(ContainerRegistrationKeys.LOGGER)
|
|
22
|
+
const requestId = randomUUID()
|
|
23
|
+
const { cart_id } = (req.body || {}) as { cart_id: string }
|
|
24
|
+
|
|
25
|
+
if (!cart_id || typeof cart_id !== "string") {
|
|
26
|
+
return res.status(400).json({ message: "cart_id is required" })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!cart_id.startsWith("cart_")) {
|
|
30
|
+
return res.status(400).json({ message: "Invalid cart_id format" })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const query = req.scope.resolve("query")
|
|
35
|
+
const { data: carts } = await query.graph({
|
|
36
|
+
entity: "cart",
|
|
37
|
+
fields: [
|
|
38
|
+
"id",
|
|
39
|
+
"completed_at",
|
|
40
|
+
"payment_collection.payment_sessions.id",
|
|
41
|
+
"payment_collection.payment_sessions.data",
|
|
42
|
+
"payment_collection.payment_sessions.status",
|
|
43
|
+
"payment_collection.payment_sessions.provider_id",
|
|
44
|
+
"payment_collection.payment_sessions.created_at",
|
|
45
|
+
"payment_collection.payment_sessions.amount",
|
|
46
|
+
"payment_collection.payment_sessions.currency_code",
|
|
47
|
+
],
|
|
48
|
+
filters: { id: cart_id },
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const cart = carts?.[0]
|
|
52
|
+
if (cart?.completed_at) {
|
|
53
|
+
return res.json({ success: true, cart_id, already_completed: true })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const sessions = cart?.payment_collection?.payment_sessions || []
|
|
57
|
+
const session = sessions
|
|
58
|
+
.filter((s: any) => isPayPalProviderId(s.provider_id))
|
|
59
|
+
.sort(
|
|
60
|
+
(a: any, b: any) =>
|
|
61
|
+
new Date(b.created_at || 0).getTime() -
|
|
62
|
+
new Date(a.created_at || 0).getTime()
|
|
63
|
+
)[0]
|
|
64
|
+
|
|
65
|
+
if (!session) {
|
|
66
|
+
return res
|
|
67
|
+
.status(400)
|
|
68
|
+
.json({ message: "No PayPal payment session found for cart" })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const paymentModule = req.scope.resolve(
|
|
72
|
+
Modules.PAYMENT
|
|
73
|
+
) as IPaymentModuleService
|
|
74
|
+
|
|
75
|
+
// Do NOT fabricate captured_at/authorized_at here. The authoritative
|
|
76
|
+
// timestamp and status are set by the provider's authorizePayment (invoked
|
|
77
|
+
// via authorizePaymentSession below) only after it verifies the capture /
|
|
78
|
+
// authorization against PayPal. Stamping it ourselves would mark an unpaid
|
|
79
|
+
// session as paid.
|
|
80
|
+
|
|
81
|
+
const currentStatus = String(session.status || "")
|
|
82
|
+
if (currentStatus !== "authorized") {
|
|
83
|
+
try {
|
|
84
|
+
await (paymentModule as any).authorizePaymentSession(session.id, {})
|
|
85
|
+
logger.info(
|
|
86
|
+
`[paypal] paypal-complete authorizePaymentSession succeeded (request_id=${requestId}, session_id=${session.id})`
|
|
87
|
+
)
|
|
88
|
+
} catch (e: any) {
|
|
89
|
+
logger.warn(
|
|
90
|
+
`[paypal] paypal-complete authorizePaymentSession failed (request_id=${requestId}, session_id=${session.id}): ${
|
|
91
|
+
e?.message ?? String(e)
|
|
92
|
+
}`
|
|
93
|
+
)
|
|
94
|
+
// The providers throw NOT_ALLOWED when PayPal has no approved /
|
|
95
|
+
// captured payment for the session (buyer never approved, capture
|
|
96
|
+
// declined, …). Nothing was charged, so say so — the generic
|
|
97
|
+
// "payment was processed but the order could not be finalized" below
|
|
98
|
+
// would tell a storefront to show "do not pay again" for a payment
|
|
99
|
+
// that never happened. Anything else (transient DB/PayPal errors) is
|
|
100
|
+
// still allowed to fall through to the completion attempt and its
|
|
101
|
+
// retryable 5xx. Checked via the `__isMedusaError` flag, not
|
|
102
|
+
// `instanceof`: the provider runs inside the payment module's own
|
|
103
|
+
// loader and its MedusaError is a different class instance than ours.
|
|
104
|
+
if (
|
|
105
|
+
MedusaError.isMedusaError(e) &&
|
|
106
|
+
(e as MedusaError).type === MedusaError.Types.NOT_ALLOWED
|
|
107
|
+
) {
|
|
108
|
+
return res.status(402).json({
|
|
109
|
+
success: false,
|
|
110
|
+
cart_id,
|
|
111
|
+
session_id: session.id,
|
|
112
|
+
payment_authorized: false,
|
|
113
|
+
message:
|
|
114
|
+
e.message ||
|
|
115
|
+
"The PayPal payment for this cart has not been approved.",
|
|
116
|
+
request_id: requestId,
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const { result } = await runCoreWorkflow<{ id: string }, { id?: string }>(
|
|
124
|
+
req.scope,
|
|
125
|
+
"complete-cart",
|
|
126
|
+
{ id: cart_id }
|
|
127
|
+
)
|
|
128
|
+
logger.info(
|
|
129
|
+
`[paypal] paypal-complete cart completed (request_id=${requestId}, cart_id=${cart_id}, order_id=${result?.id})`
|
|
130
|
+
)
|
|
131
|
+
return res.json({
|
|
132
|
+
success: true,
|
|
133
|
+
cart_id,
|
|
134
|
+
order_id: result?.id,
|
|
135
|
+
request_id: requestId,
|
|
136
|
+
})
|
|
137
|
+
} catch (e: any) {
|
|
138
|
+
// The cart may have been completed by a concurrent request between our
|
|
139
|
+
// initial check and now — treat that as success, not an error.
|
|
140
|
+
const recheck = await query
|
|
141
|
+
.graph({
|
|
142
|
+
entity: "cart",
|
|
143
|
+
fields: ["id", "completed_at"],
|
|
144
|
+
filters: { id: cart_id },
|
|
145
|
+
})
|
|
146
|
+
.catch(() => ({ data: [] as any[] }))
|
|
147
|
+
if (recheck?.data?.[0]?.completed_at) {
|
|
148
|
+
return res.json({
|
|
149
|
+
success: true,
|
|
150
|
+
cart_id,
|
|
151
|
+
already_completed: true,
|
|
152
|
+
request_id: requestId,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
logger.error(
|
|
157
|
+
`[paypal] paypal-complete completeCartWorkflow failed (request_id=${requestId}, cart_id=${cart_id}): ${
|
|
158
|
+
e?.message ?? String(e)
|
|
159
|
+
}`,
|
|
160
|
+
e instanceof Error ? e : undefined
|
|
161
|
+
)
|
|
162
|
+
// The payment may have been captured at PayPal but the order was not
|
|
163
|
+
// finalized. Report failure (not a false success) so the storefront can
|
|
164
|
+
// surface a "payment taken, contact support" state.
|
|
165
|
+
return res.status(500).json({
|
|
166
|
+
success: false,
|
|
167
|
+
cart_id,
|
|
168
|
+
session_id: session.id,
|
|
169
|
+
message: "Payment was processed but the order could not be finalized.",
|
|
170
|
+
request_id: requestId,
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
} catch (e: any) {
|
|
174
|
+
logger.error(
|
|
175
|
+
`[paypal] paypal-complete failed (request_id=${requestId}, cart_id=${cart_id}): ${
|
|
176
|
+
e?.message ?? String(e)
|
|
177
|
+
}`,
|
|
178
|
+
e instanceof Error ? e : undefined
|
|
179
|
+
)
|
|
180
|
+
return res
|
|
181
|
+
.status(500)
|
|
182
|
+
.json({ message: "Internal error", request_id: requestId })
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -1,129 +1,143 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
const
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
1
|
+
import type {
|
|
2
|
+
MedusaNextFunction,
|
|
3
|
+
MedusaRequest,
|
|
4
|
+
MedusaResponse,
|
|
5
|
+
} from "@medusajs/framework/http"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Lightweight in-memory rate limiter for the public store payment routes.
|
|
9
|
+
*
|
|
10
|
+
* The store PayPal routes (create-order, capture-order, paypal-complete) are
|
|
11
|
+
* unauthenticated by necessity, so without a limit a caller can hammer them —
|
|
12
|
+
* e.g. enumerate cart ids and create unbounded PayPal orders against the
|
|
13
|
+
* merchant account. This applies a fixed-window per-client cap.
|
|
14
|
+
*
|
|
15
|
+
* OPT-IN: disabled unless `PAYPAL_RATE_LIMIT_MAX` is set to a positive number.
|
|
16
|
+
* This is deliberate — behind a load balancer / CDN that doesn't forward the
|
|
17
|
+
* real client IP, every request would share one bucket and a low limit could
|
|
18
|
+
* block legitimate checkouts. Merchants opt in once they've confirmed the real
|
|
19
|
+
* client IP reaches the app (e.g. `x-forwarded-for` is set correctly).
|
|
20
|
+
*
|
|
21
|
+
* NOTE: the counter lives in process memory, so the limit is enforced per
|
|
22
|
+
* server instance, not globally across a horizontally-scaled deployment. It is
|
|
23
|
+
* a pragmatic first line of defense and a backstop; a shared store (Redis) or
|
|
24
|
+
* an edge/CDN limiter is the right tool for a hard global guarantee. Tunable via
|
|
25
|
+
* PAYPAL_RATE_LIMIT_MAX (requests) and PAYPAL_RATE_LIMIT_WINDOW_MS (window).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const DEFAULT_WINDOW_MS = 60_000
|
|
29
|
+
|
|
30
|
+
// Cap the number of distinct client buckets we retain so a flood of unique
|
|
31
|
+
// client keys can't grow the map unbounded (a memory-exhaustion vector of its
|
|
32
|
+
// own). Oldest buckets are evicted first once the cap is hit.
|
|
33
|
+
const MAX_BUCKETS = 10_000
|
|
34
|
+
|
|
35
|
+
type Bucket = { count: number; resetAt: number }
|
|
36
|
+
|
|
37
|
+
function readEnvInt(name: string, fallback: number): number {
|
|
38
|
+
const v = Number(process.env[name])
|
|
39
|
+
return Number.isFinite(v) && v > 0 ? v : fallback
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The configured max, or null when rate limiting is disabled (opt-in). */
|
|
43
|
+
function readConfiguredMax(envVar: string): number | null {
|
|
44
|
+
const raw = process.env[envVar]
|
|
45
|
+
if (raw === undefined || raw === "") return null
|
|
46
|
+
const v = Number(raw)
|
|
47
|
+
return Number.isFinite(v) && v > 0 ? v : null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function clientKey(req: MedusaRequest): string {
|
|
51
|
+
// Use the RIGHT-most x-forwarded-for entry: proxies append the address they
|
|
52
|
+
// received the request from, so the right-most value was written by the
|
|
53
|
+
// merchant's own edge proxy and cannot be forged by the client. The
|
|
54
|
+
// left-most entry is fully client-controlled — keying on it would let an
|
|
55
|
+
// attacker rotate a header value to get a fresh bucket per request,
|
|
56
|
+
// bypassing the limiter entirely.
|
|
57
|
+
const fwd = req.headers["x-forwarded-for"]
|
|
58
|
+
const fwdRaw = Array.isArray(fwd) ? fwd[fwd.length - 1] : fwd
|
|
59
|
+
const parts = fwdRaw
|
|
60
|
+
? fwdRaw
|
|
61
|
+
.split(",")
|
|
62
|
+
.map((s) => s.trim())
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
: []
|
|
65
|
+
const ip = parts[parts.length - 1] || req.socket?.remoteAddress || "unknown"
|
|
66
|
+
return ip
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type RateLimiterOptions = {
|
|
70
|
+
/**
|
|
71
|
+
* Env var holding the request cap for this limiter. Defaults to the shared
|
|
72
|
+
* PAYPAL_RATE_LIMIT_MAX. The webhook routes pass their own dedicated var:
|
|
73
|
+
* PayPal delivers from a handful of egress IPs, so a cap sized for
|
|
74
|
+
* individual buyers would throttle legitimate webhook bursts (a sale spike)
|
|
75
|
+
* into 429-driven redelivery loops.
|
|
76
|
+
*/
|
|
77
|
+
maxEnvVar?: string
|
|
78
|
+
/** Env var for the window; defaults to PAYPAL_RATE_LIMIT_WINDOW_MS. */
|
|
79
|
+
windowEnvVar?: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Build a fixed-window rate-limit middleware with its own bucket map. `scope`
|
|
84
|
+
* namespaces the buckets so limiters on different routes never share counts.
|
|
85
|
+
*/
|
|
86
|
+
export function createRateLimiter(
|
|
87
|
+
scope: string,
|
|
88
|
+
options: RateLimiterOptions = {}
|
|
89
|
+
) {
|
|
90
|
+
const buckets = new Map<string, Bucket>()
|
|
91
|
+
const maxEnvVar = options.maxEnvVar || "PAYPAL_RATE_LIMIT_MAX"
|
|
92
|
+
const windowEnvVar = options.windowEnvVar || "PAYPAL_RATE_LIMIT_WINDOW_MS"
|
|
93
|
+
|
|
94
|
+
return function rateLimit(
|
|
95
|
+
req: MedusaRequest,
|
|
96
|
+
res: MedusaResponse,
|
|
97
|
+
next: MedusaNextFunction
|
|
98
|
+
) {
|
|
99
|
+
// Opt-in: with no configured max, this middleware is a pass-through so
|
|
100
|
+
// existing deployments (especially behind a shared-IP proxy) are unaffected.
|
|
101
|
+
const max = readConfiguredMax(maxEnvVar)
|
|
102
|
+
if (max === null) {
|
|
103
|
+
return next()
|
|
104
|
+
}
|
|
105
|
+
const windowMs = readEnvInt(windowEnvVar, DEFAULT_WINDOW_MS)
|
|
106
|
+
const now = Date.now()
|
|
107
|
+
const key = `${scope}:${clientKey(req)}`
|
|
108
|
+
|
|
109
|
+
let bucket = buckets.get(key)
|
|
110
|
+
if (!bucket || bucket.resetAt <= now) {
|
|
111
|
+
bucket = { count: 0, resetAt: now + windowMs }
|
|
112
|
+
buckets.set(key, bucket)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
bucket.count += 1
|
|
116
|
+
|
|
117
|
+
if (buckets.size > MAX_BUCKETS) {
|
|
118
|
+
// Evict expired buckets first; if still over, drop the oldest inserted.
|
|
119
|
+
for (const [k, b] of buckets) {
|
|
120
|
+
if (b.resetAt <= now) buckets.delete(k)
|
|
121
|
+
if (buckets.size <= MAX_BUCKETS) break
|
|
122
|
+
}
|
|
123
|
+
while (buckets.size > MAX_BUCKETS) {
|
|
124
|
+
const oldest = buckets.keys().next().value
|
|
125
|
+
if (oldest === undefined) break
|
|
126
|
+
buckets.delete(oldest)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (bucket.count > max) {
|
|
131
|
+
const retryAfterSec = Math.max(
|
|
132
|
+
1,
|
|
133
|
+
Math.ceil((bucket.resetAt - now) / 1000)
|
|
134
|
+
)
|
|
135
|
+
res.setHeader("Retry-After", String(retryAfterSec))
|
|
136
|
+
return res
|
|
137
|
+
.status(429)
|
|
138
|
+
.json({ message: "Too many requests. Please slow down and try again." })
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return next()
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from "./modules/paypal"
|
|
1
|
+
export { default } from "./modules/paypal"
|