@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../src/modules/paypal/service.ts"],"names":[],"mappings":"AAYA,KAAK,WAAW,GAAG,SAAS,GAAG,MAAM,CAAA;AAErC,KAAK,MAAM,GACP,cAAc,GACd,SAAS,GACT,qBAAqB,GACrB,WAAW,GACX,SAAS,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../src/modules/paypal/service.ts"],"names":[],"mappings":"AAYA,KAAK,WAAW,GAAG,SAAS,GAAG,MAAM,CAAA;AAErC,KAAK,MAAM,GACP,cAAc,GACd,SAAS,GACT,qBAAqB,GACrB,WAAW,GACX,SAAS,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;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IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACnC;CA2CF;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -29,10 +29,21 @@ function redactSensitive(value, depth = 0) {
|
|
|
29
29
|
}
|
|
30
30
|
const out = {};
|
|
31
31
|
for (const [k, v] of Object.entries(value)) {
|
|
32
|
-
out[k] = SENSITIVE_KEY_RE.test(k)
|
|
32
|
+
out[k] = SENSITIVE_KEY_RE.test(k)
|
|
33
|
+
? "[REDACTED]"
|
|
34
|
+
: redactSensitive(v, depth + 1);
|
|
33
35
|
}
|
|
34
36
|
return out;
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Application-container service for the PayPal module.
|
|
40
|
+
*
|
|
41
|
+
* Owns the merchant's PayPal connection (partner onboarding, seller
|
|
42
|
+
* credentials, cached app access token), the plugin settings singleton,
|
|
43
|
+
* webhook registration/event records, metrics, and audit logging. The payment
|
|
44
|
+
* providers run in the isolated payment-module container and therefore read
|
|
45
|
+
* the same tables through `PayPalCredentialResolver` instead of this service.
|
|
46
|
+
*/
|
|
36
47
|
class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
37
48
|
PayPalConnection: paypal_connection_1.default,
|
|
38
49
|
PayPalMetric: paypal_metric_1.default,
|
|
@@ -44,6 +55,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
44
55
|
// Raw knex connection for the atomic metric upsert; null when the container
|
|
45
56
|
// doesn't expose it (recordMetric then falls back to the ORM path).
|
|
46
57
|
pgForMetrics = null;
|
|
58
|
+
// Only probe PayPal for a stale legacy webhook URL once per process per
|
|
59
|
+
// environment — this runs on admin status reads and must stay cheap.
|
|
60
|
+
webhookUrlMigrationChecked = {};
|
|
61
|
+
webhookHealScheduled = {};
|
|
47
62
|
constructor(...args) {
|
|
48
63
|
// MedusaService's generated constructor signature varies across framework
|
|
49
64
|
// versions — pass everything through untouched.
|
|
@@ -117,6 +132,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
117
132
|
}
|
|
118
133
|
return { onboarding, apiDetails };
|
|
119
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Onboarding + API-detail settings with plugin defaults filled in (and
|
|
137
|
+
* persisted) for any key that is still unset.
|
|
138
|
+
*/
|
|
120
139
|
async getApiDetails() {
|
|
121
140
|
const { onboarding, apiDetails } = await this.ensureSettingsDefaults();
|
|
122
141
|
return {
|
|
@@ -125,11 +144,15 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
125
144
|
};
|
|
126
145
|
}
|
|
127
146
|
getAlertWebhookUrls() {
|
|
128
|
-
return (this.cfg.alertWebhookUrls || [])
|
|
147
|
+
return (this.cfg.alertWebhookUrls || [])
|
|
148
|
+
.map((url) => url.trim())
|
|
149
|
+
.filter(Boolean);
|
|
129
150
|
}
|
|
130
151
|
async getPartnerMerchantId(env) {
|
|
131
152
|
const { onboarding } = await this.ensureSettingsDefaults();
|
|
132
|
-
return env === "live"
|
|
153
|
+
return env === "live"
|
|
154
|
+
? onboarding.partner_merchant_id_live
|
|
155
|
+
: onboarding.partner_merchant_id_sandbox;
|
|
133
156
|
}
|
|
134
157
|
async getCurrentRow() {
|
|
135
158
|
const rows = await this.listPayPalConnections({}, { take: 1, order: { created_at: "DESC" } });
|
|
@@ -220,7 +243,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
220
243
|
throw new Error("Missing PayPal partner merchant id configuration.");
|
|
221
244
|
}
|
|
222
245
|
const baseUrl = (0, paypal_auth_1.getPayPalApiBase)(env);
|
|
223
|
-
const accessToken = accessTokenOverride ?? await this.getAppAccessToken();
|
|
246
|
+
const accessToken = accessTokenOverride ?? (await this.getAppAccessToken());
|
|
224
247
|
const resp = await (0, paypal_fetch_1.paypalFetch)(`${baseUrl}/v1/customer/partners/${encodeURIComponent(partnerMerchantId)}/merchant-integrations/${encodeURIComponent(merchantId)}`, {
|
|
225
248
|
method: "GET",
|
|
226
249
|
headers: {
|
|
@@ -290,7 +313,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
290
313
|
accessToken = await this.getAppAccessToken();
|
|
291
314
|
}
|
|
292
315
|
let sellerEmail = this.extractSellerEmail(tokenPayload || undefined);
|
|
293
|
-
let sellerMerchantId = String(tokenPayload?.merchant_id ||
|
|
316
|
+
let sellerMerchantId = String(tokenPayload?.merchant_id ||
|
|
317
|
+
tokenPayload?.payer_id ||
|
|
318
|
+
tokenPayload?.account_id ||
|
|
319
|
+
"").trim() || null;
|
|
294
320
|
try {
|
|
295
321
|
const userInfoResp = await (0, paypal_fetch_1.paypalFetch)(`${baseUrl}/v1/identity/oauth2/userinfo?schema=paypalv1`, {
|
|
296
322
|
method: "GET",
|
|
@@ -306,7 +332,11 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
306
332
|
sellerEmail = sellerEmail || this.extractSellerEmail(userInfo);
|
|
307
333
|
sellerMerchantId =
|
|
308
334
|
sellerMerchantId ||
|
|
309
|
-
String(userInfo?.merchant_id ||
|
|
335
|
+
String(userInfo?.merchant_id ||
|
|
336
|
+
userInfo?.payer_id ||
|
|
337
|
+
userInfo?.user_id ||
|
|
338
|
+
userInfo?.sub ||
|
|
339
|
+
"").trim() ||
|
|
310
340
|
null;
|
|
311
341
|
}
|
|
312
342
|
}
|
|
@@ -326,7 +356,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
326
356
|
if (credsResp.ok) {
|
|
327
357
|
const credsJson = await credsResp.json().catch(() => ({}));
|
|
328
358
|
sellerEmail = sellerEmail || this.extractSellerEmail(credsJson);
|
|
329
|
-
sellerMerchantId =
|
|
359
|
+
sellerMerchantId =
|
|
360
|
+
sellerMerchantId ||
|
|
361
|
+
String(credsJson?.merchant_id || "").trim() ||
|
|
362
|
+
null;
|
|
330
363
|
}
|
|
331
364
|
}
|
|
332
365
|
catch (e) {
|
|
@@ -376,6 +409,12 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
376
409
|
},
|
|
377
410
|
});
|
|
378
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Switch the active environment (`sandbox` | `live`). Credentials are stored
|
|
414
|
+
* per environment, so switching never discards the other environment's
|
|
415
|
+
* credentials — it only changes which set is active and clears the cached
|
|
416
|
+
* app token.
|
|
417
|
+
*/
|
|
379
418
|
async setEnvironment(env) {
|
|
380
419
|
const nextEnv = env === "sandbox" ? "sandbox" : "live";
|
|
381
420
|
const row = await this.getCurrentRow();
|
|
@@ -420,6 +459,11 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
420
459
|
});
|
|
421
460
|
return await this.getCurrentRow();
|
|
422
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* Request a PayPal partner-referral onboarding URL from the partner service.
|
|
464
|
+
* Returns the URL to open in PayPal's mini-browser plus the `return_url` the
|
|
465
|
+
* popup lands on afterwards.
|
|
466
|
+
*/
|
|
423
467
|
async createOnboardingLink(input) {
|
|
424
468
|
const { onboarding } = await this.ensureSettingsDefaults();
|
|
425
469
|
// Honor an explicit environment from the caller so the generated link can't
|
|
@@ -488,7 +532,9 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
488
532
|
throw new Error(`Onboarding wrapper JSON 'body' is not valid JSON / URL: ${typeof inner === "string" ? inner.slice(0, 200) : "[object]"}`);
|
|
489
533
|
}
|
|
490
534
|
}
|
|
491
|
-
if (json?.name &&
|
|
535
|
+
if (json?.name &&
|
|
536
|
+
json?.message &&
|
|
537
|
+
(json?.debug_id || json?.details || json?.links)) {
|
|
492
538
|
const debug = json.debug_id ? ` debug_id=${json.debug_id}` : "";
|
|
493
539
|
const details = Array.isArray(json.details)
|
|
494
540
|
? json.details
|
|
@@ -504,12 +550,15 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
504
550
|
: "";
|
|
505
551
|
throw new Error(`PayPal onboarding error: ${json.name}: ${json.message}.${debug}${details ? ` Details: ${details}` : ""}`);
|
|
506
552
|
}
|
|
507
|
-
if (json?.onboarding_url &&
|
|
553
|
+
if (json?.onboarding_url &&
|
|
554
|
+
String(json.onboarding_url).startsWith("http")) {
|
|
508
555
|
return { onboarding_url: String(json.onboarding_url), return_url };
|
|
509
556
|
}
|
|
510
557
|
const links = Array.isArray(json?.links) ? json.links : null;
|
|
511
558
|
if (links) {
|
|
512
|
-
const action = links.find((l) => l?.rel === "action_url" ||
|
|
559
|
+
const action = links.find((l) => l?.rel === "action_url" ||
|
|
560
|
+
l?.rel === "actionUrl" ||
|
|
561
|
+
l?.rel === "action-url");
|
|
513
562
|
const href = action?.href ? String(action.href) : null;
|
|
514
563
|
if (href && href.startsWith("http")) {
|
|
515
564
|
return { onboarding_url: href, return_url };
|
|
@@ -517,6 +566,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
517
566
|
}
|
|
518
567
|
throw new Error(`Onboarding JSON missing action_url link. Keys: ${Object.keys(json || {}).join(", ")}`);
|
|
519
568
|
}
|
|
569
|
+
/** Mark the connection as onboarding-in-progress (creates the row if needed). */
|
|
520
570
|
async startOnboarding() {
|
|
521
571
|
const row = await this.getCurrentRow();
|
|
522
572
|
const env = await this.getCurrentEnvironment();
|
|
@@ -530,6 +580,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
530
580
|
metadata: {},
|
|
531
581
|
});
|
|
532
582
|
}
|
|
583
|
+
/** Persist the `authCode`/`sharedId` PayPal hands back after onboarding. */
|
|
533
584
|
async saveOnboardCallback(input) {
|
|
534
585
|
const row = await this.getCurrentRow();
|
|
535
586
|
const env = await this.getCurrentEnvironment();
|
|
@@ -549,8 +600,15 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
549
600
|
shared_id: input.sharedId,
|
|
550
601
|
});
|
|
551
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* Complete partner onboarding: exchange the single-use `authCode` for a
|
|
605
|
+
* seller access token, fetch the seller's REST credentials, and store them.
|
|
606
|
+
* Idempotent — a repeated exchange of an already-consumed code is a no-op
|
|
607
|
+
* when credentials for that environment are already saved.
|
|
608
|
+
*/
|
|
552
609
|
async exchangeAndSaveSellerCredentials(input) {
|
|
553
|
-
const env = (input.env ||
|
|
610
|
+
const env = (input.env ||
|
|
611
|
+
(await this.getCurrentEnvironment()));
|
|
554
612
|
// Onboarding completion can now arrive via several redundant paths
|
|
555
613
|
// (partner.js's onboardingCallback in the opener, the return_url bridge that
|
|
556
614
|
// runs inside the popup, and admin status polling). PayPal's authorization
|
|
@@ -564,7 +622,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
564
622
|
return;
|
|
565
623
|
}
|
|
566
624
|
}
|
|
567
|
-
await this.saveOnboardCallback({
|
|
625
|
+
await this.saveOnboardCallback({
|
|
626
|
+
authCode: input.authCode,
|
|
627
|
+
sharedId: input.sharedId,
|
|
628
|
+
});
|
|
568
629
|
const baseUrl = (0, paypal_auth_1.getPayPalApiBase)(env);
|
|
569
630
|
const { onboarding } = await this.ensureSettingsDefaults();
|
|
570
631
|
const sellerNonce = (onboarding.seller_nonce || "").trim();
|
|
@@ -628,7 +689,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
628
689
|
credJson = credText ? JSON.parse(credText) : {};
|
|
629
690
|
}
|
|
630
691
|
catch (e) {
|
|
631
|
-
console.warn("[PayPal] Failed to parse
|
|
692
|
+
console.warn("[PayPal] Failed to parse credentials response JSON:", e?.message);
|
|
632
693
|
}
|
|
633
694
|
if (!credRes.ok) {
|
|
634
695
|
throw new Error(`PayPal credentials fetch failed (${credRes.status}): ${credText || JSON.stringify(credJson)}`);
|
|
@@ -639,15 +700,20 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
639
700
|
throw new Error(`PayPal credentials response missing client_id/client_secret. Keys: ${Object.keys(credJson || {}).join(", ")}`);
|
|
640
701
|
}
|
|
641
702
|
let sellerEmail = this.extractSellerEmail(credJson, tokenJson);
|
|
642
|
-
let sellerMerchantId = String(credJson.payer_id ||
|
|
643
|
-
|
|
703
|
+
let sellerMerchantId = String(credJson.payer_id ||
|
|
704
|
+
credJson.merchant_id ||
|
|
705
|
+
tokenJson.payer_id ||
|
|
706
|
+
tokenJson.merchant_id ||
|
|
707
|
+
"").trim() || null;
|
|
644
708
|
if (!sellerEmail) {
|
|
645
709
|
const merchantCandidates = [
|
|
646
710
|
String(credJson.payer_id || "").trim(),
|
|
647
711
|
String(credJson.merchant_id || "").trim(),
|
|
648
712
|
String(tokenJson.payer_id || "").trim(),
|
|
649
713
|
String(tokenJson.merchant_id || "").trim(),
|
|
650
|
-
]
|
|
714
|
+
]
|
|
715
|
+
.filter(Boolean)
|
|
716
|
+
.filter((v, i, arr) => arr.indexOf(v) === i);
|
|
651
717
|
for (const merchantId of merchantCandidates) {
|
|
652
718
|
try {
|
|
653
719
|
const merchantDetails = await this.fetchMerchantIntegrationDetails(env, merchantId, sellerAccessToken);
|
|
@@ -674,7 +740,12 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
674
740
|
const details = await this.fetchMerchantIntegrationDetails(env, sellerMerchantId, appAccessToken);
|
|
675
741
|
sellerEmail = this.extractSellerEmail(details);
|
|
676
742
|
if (sellerEmail) {
|
|
677
|
-
await this.saveSellerCredentials({
|
|
743
|
+
await this.saveSellerCredentials({
|
|
744
|
+
clientId,
|
|
745
|
+
clientSecret,
|
|
746
|
+
sellerMerchantId,
|
|
747
|
+
sellerEmail,
|
|
748
|
+
});
|
|
678
749
|
}
|
|
679
750
|
}
|
|
680
751
|
catch (e) {
|
|
@@ -682,13 +753,23 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
682
753
|
}
|
|
683
754
|
}
|
|
684
755
|
}
|
|
756
|
+
/**
|
|
757
|
+
* Store seller REST credentials for an environment (encrypted at rest when
|
|
758
|
+
* `PAYPAL_ENCRYPTION_KEY` is set) and make sure a webhook is registered.
|
|
759
|
+
*/
|
|
685
760
|
async saveSellerCredentials(input) {
|
|
686
761
|
const row = await this.getCurrentRow();
|
|
687
762
|
const currentEnv = await this.getCurrentEnvironment();
|
|
688
763
|
const env = (input.environment || currentEnv);
|
|
689
764
|
const existingCreds = row ? this.getEnvCreds(row, env) : {};
|
|
690
|
-
const nextSellerMerchantId = (input.sellerMerchantId || "").trim() ||
|
|
691
|
-
|
|
765
|
+
const nextSellerMerchantId = (input.sellerMerchantId || "").trim() ||
|
|
766
|
+
existingCreds.sellerMerchantId ||
|
|
767
|
+
row?.seller_merchant_id ||
|
|
768
|
+
null;
|
|
769
|
+
const nextSellerEmail = (input.sellerEmail || "").trim() ||
|
|
770
|
+
existingCreds.sellerEmail ||
|
|
771
|
+
row?.seller_email ||
|
|
772
|
+
null;
|
|
692
773
|
// Encrypt once and store the same ciphertext in both the metadata copy and
|
|
693
774
|
// the denormalized column (no-op when encryption is disabled).
|
|
694
775
|
const storedClientSecret = (0, secret_crypto_1.encryptSecret)(input.clientSecret);
|
|
@@ -751,8 +832,13 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
751
832
|
await this.ensureWebhookRegistration();
|
|
752
833
|
return updated;
|
|
753
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* Save manually-entered credentials, then best-effort look up the seller's
|
|
837
|
+
* merchant id / email from PayPal so the admin UI can display them.
|
|
838
|
+
*/
|
|
754
839
|
async saveAndHydrateSellerCredentials(input) {
|
|
755
|
-
const env = (input.environment ||
|
|
840
|
+
const env = (input.environment ||
|
|
841
|
+
(await this.getCurrentEnvironment()));
|
|
756
842
|
await this.saveSellerCredentials({
|
|
757
843
|
clientId: input.clientId,
|
|
758
844
|
clientSecret: input.clientSecret,
|
|
@@ -812,10 +898,6 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
812
898
|
return false;
|
|
813
899
|
}
|
|
814
900
|
}
|
|
815
|
-
// Only probe PayPal for a stale legacy webhook URL once per process per
|
|
816
|
-
// environment — this runs on admin status reads and must stay cheap.
|
|
817
|
-
webhookUrlMigrationChecked = {};
|
|
818
|
-
webhookHealScheduled = {};
|
|
819
901
|
async migrateLegacyWebhookUrl(env, webhookId) {
|
|
820
902
|
if (this.webhookUrlMigrationChecked[env])
|
|
821
903
|
return;
|
|
@@ -846,9 +928,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
846
928
|
"Content-Type": "application/json",
|
|
847
929
|
"PayPal-Partner-Attribution-Id": this.bnCode,
|
|
848
930
|
},
|
|
849
|
-
body: JSON.stringify([
|
|
850
|
-
{ op: "replace", path: "/url", value: newUrl },
|
|
851
|
-
]),
|
|
931
|
+
body: JSON.stringify([{ op: "replace", path: "/url", value: newUrl }]),
|
|
852
932
|
});
|
|
853
933
|
if (patchResp.ok) {
|
|
854
934
|
await this.recordAuditEvent("webhook_url_migrated", {
|
|
@@ -969,7 +1049,11 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
969
1049
|
const row = await this.getCurrentRow();
|
|
970
1050
|
const env = envOverride ?? (await this.getCurrentEnvironment());
|
|
971
1051
|
if (!row) {
|
|
972
|
-
return {
|
|
1052
|
+
return {
|
|
1053
|
+
environment: env,
|
|
1054
|
+
status: "disconnected",
|
|
1055
|
+
seller_client_id_present: false,
|
|
1056
|
+
};
|
|
973
1057
|
}
|
|
974
1058
|
const c = this.getEnvCreds(row, env);
|
|
975
1059
|
const hasCreds = !!(c.clientId && c.clientSecret);
|
|
@@ -1001,9 +1085,14 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1001
1085
|
const refreshedRow = await this.getCurrentRow();
|
|
1002
1086
|
if (refreshedRow) {
|
|
1003
1087
|
const refreshedCreds = this.getEnvCreds(refreshedRow, env);
|
|
1004
|
-
sellerEmail =
|
|
1088
|
+
sellerEmail =
|
|
1089
|
+
refreshedCreds.sellerEmail ||
|
|
1090
|
+
refreshedRow.seller_email ||
|
|
1091
|
+
sellerEmail;
|
|
1005
1092
|
sellerMerchantId =
|
|
1006
|
-
refreshedCreds.sellerMerchantId ||
|
|
1093
|
+
refreshedCreds.sellerMerchantId ||
|
|
1094
|
+
refreshedRow.seller_merchant_id ||
|
|
1095
|
+
sellerMerchantId;
|
|
1007
1096
|
}
|
|
1008
1097
|
}
|
|
1009
1098
|
}
|
|
@@ -1024,6 +1113,11 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1024
1113
|
updated_at: row.updated_at?.toISOString?.() ?? null,
|
|
1025
1114
|
};
|
|
1026
1115
|
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Remove the active environment's credentials. The other environment (if
|
|
1118
|
+
* connected) is untouched, so the row stays "connected" when it still holds
|
|
1119
|
+
* a usable credential set.
|
|
1120
|
+
*/
|
|
1027
1121
|
async disconnect() {
|
|
1028
1122
|
const row = await this.getCurrentRow();
|
|
1029
1123
|
if (!row)
|
|
@@ -1033,7 +1127,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1033
1127
|
const creds = { ...(meta.credentials || {}) };
|
|
1034
1128
|
delete creds[env];
|
|
1035
1129
|
const hasAnyCreds = Object.values(creds).some((v) => {
|
|
1036
|
-
return v &&
|
|
1130
|
+
return (v &&
|
|
1131
|
+
typeof v === "object" &&
|
|
1132
|
+
v.client_id &&
|
|
1133
|
+
v.client_secret);
|
|
1037
1134
|
});
|
|
1038
1135
|
await this.updatePayPalConnections({
|
|
1039
1136
|
id: row.id,
|
|
@@ -1058,12 +1155,19 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1058
1155
|
}
|
|
1059
1156
|
await this.recordAuditEvent("disconnected", { environment: env });
|
|
1060
1157
|
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Cached client-credentials access token for the active environment.
|
|
1160
|
+
* Refreshes single-flight when the stored token is within two minutes of
|
|
1161
|
+
* expiry so concurrent callers never race to mint duplicate tokens.
|
|
1162
|
+
*/
|
|
1061
1163
|
async getAppAccessToken() {
|
|
1062
1164
|
const row = await this.getCurrentRow();
|
|
1063
1165
|
if (!row) {
|
|
1064
1166
|
throw new Error("PayPal connection row not found. Please complete onboarding.");
|
|
1065
1167
|
}
|
|
1066
|
-
const expiresAt = row.app_access_token_expires_at
|
|
1168
|
+
const expiresAt = row.app_access_token_expires_at
|
|
1169
|
+
? new Date(row.app_access_token_expires_at)
|
|
1170
|
+
: null;
|
|
1067
1171
|
if (row.app_access_token && expiresAt) {
|
|
1068
1172
|
const msLeft = expiresAt.getTime() - Date.now();
|
|
1069
1173
|
// Token is encrypted at rest when a key is configured; decrypt the cached
|
|
@@ -1112,6 +1216,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1112
1216
|
});
|
|
1113
1217
|
return accessToken;
|
|
1114
1218
|
}
|
|
1219
|
+
/** Mint a browser `client_token` (required by the hosted card fields SDK). */
|
|
1115
1220
|
async generateClientToken(opts) {
|
|
1116
1221
|
const env = await this.getCurrentEnvironment();
|
|
1117
1222
|
const baseUrl = (0, paypal_auth_1.getPayPalApiBase)(env);
|
|
@@ -1136,6 +1241,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1136
1241
|
}
|
|
1137
1242
|
return token;
|
|
1138
1243
|
}
|
|
1244
|
+
/** The plugin settings singleton (`{ data }`), never null. */
|
|
1139
1245
|
async getSettings() {
|
|
1140
1246
|
// Deterministic singleton read: always the OLDEST row. If a first-boot race
|
|
1141
1247
|
// ever created a duplicate settings row, every reader (here and the
|
|
@@ -1164,6 +1270,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1164
1270
|
}
|
|
1165
1271
|
return result;
|
|
1166
1272
|
}
|
|
1273
|
+
/** Deep-merge `patch` into the settings singleton and return the result. */
|
|
1167
1274
|
async saveSettings(patch) {
|
|
1168
1275
|
// Same deterministic ordering as getSettings so reads and writes always
|
|
1169
1276
|
// target the same singleton row.
|
|
@@ -1188,6 +1295,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1188
1295
|
await this.updatePayPalSettings({ id: row.id, data: next });
|
|
1189
1296
|
return { data: next };
|
|
1190
1297
|
}
|
|
1298
|
+
/** Decrypted REST credentials for the active environment; throws if unset. */
|
|
1191
1299
|
async getActiveCredentials() {
|
|
1192
1300
|
const row = await this.getCurrentRow();
|
|
1193
1301
|
const env = await this.getCurrentEnvironment();
|
|
@@ -1205,6 +1313,7 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1205
1313
|
client_secret: clientSecret,
|
|
1206
1314
|
};
|
|
1207
1315
|
}
|
|
1316
|
+
/** Fetch a PayPal order (`GET /v2/checkout/orders/{id}`). */
|
|
1208
1317
|
async getOrderDetails(orderId) {
|
|
1209
1318
|
if (!orderId) {
|
|
1210
1319
|
throw new Error("PayPal orderId is required");
|
|
@@ -1227,6 +1336,11 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1227
1336
|
}
|
|
1228
1337
|
return JSON.parse(text);
|
|
1229
1338
|
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Insert a webhook event row. Returns `{ created: false, event }` instead of
|
|
1341
|
+
* throwing when `event_id` already exists, so the webhook route can treat a
|
|
1342
|
+
* redelivery as a duplicate.
|
|
1343
|
+
*/
|
|
1230
1344
|
async createWebhookEventRecord(input) {
|
|
1231
1345
|
try {
|
|
1232
1346
|
const created = await this.createPayPalWebhookEvents({
|
|
@@ -1251,12 +1365,15 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1251
1365
|
if (message.includes("paypal_webhook_event_event_id_unique") ||
|
|
1252
1366
|
code === "23505" ||
|
|
1253
1367
|
(message.includes("unique") && message.includes("event_id"))) {
|
|
1254
|
-
const existing = await this.listPayPalWebhookEvents({
|
|
1368
|
+
const existing = await this.listPayPalWebhookEvents({
|
|
1369
|
+
event_id: input.event_id,
|
|
1370
|
+
});
|
|
1255
1371
|
return { created: false, event: existing?.[0] ?? null };
|
|
1256
1372
|
}
|
|
1257
1373
|
throw error;
|
|
1258
1374
|
}
|
|
1259
1375
|
}
|
|
1376
|
+
/** Update processing state on a webhook event row. */
|
|
1260
1377
|
async updateWebhookEventRecord(input) {
|
|
1261
1378
|
return await this.updatePayPalWebhookEvents({
|
|
1262
1379
|
id: input.id,
|
|
@@ -1291,6 +1408,10 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1291
1408
|
}
|
|
1292
1409
|
return null;
|
|
1293
1410
|
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Increment a named counter in `paypal_metric`, merging any metadata.
|
|
1413
|
+
* Best-effort — never throws.
|
|
1414
|
+
*/
|
|
1294
1415
|
async recordMetric(name, metadata) {
|
|
1295
1416
|
// Preferred path: single atomic INSERT ... ON CONFLICT (same statement the
|
|
1296
1417
|
// credential resolver uses), so concurrent routes/webhooks never lose
|
|
@@ -1341,9 +1462,14 @@ class PayPalModuleService extends (0, utils_1.MedusaService)({
|
|
|
1341
1462
|
return null;
|
|
1342
1463
|
}
|
|
1343
1464
|
}
|
|
1465
|
+
/** Audit-log a payment event under the `payment_` prefix. */
|
|
1344
1466
|
async recordPaymentLog(eventType, metadata) {
|
|
1345
1467
|
return await this.recordAuditEvent(`payment_${eventType}`, metadata);
|
|
1346
1468
|
}
|
|
1469
|
+
/**
|
|
1470
|
+
* POST an operational alert to every configured `PAYPAL_ALERT_WEBHOOK_URLS`
|
|
1471
|
+
* endpoint. Delivery results are audit-logged; failures never throw.
|
|
1472
|
+
*/
|
|
1347
1473
|
async sendAlert(input) {
|
|
1348
1474
|
const urls = this.getAlertWebhookUrls();
|
|
1349
1475
|
if (urls.length === 0) {
|