@easypayment/medusa-paypal 0.1.0
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 +2127 -0
- package/.medusa/server/src/admin/index.mjs +2128 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +25 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/audit-logs/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/audit-logs/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/audit-logs/route.js +12 -0
- package/.medusa/server/src/api/admin/paypal/audit-logs/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js +9 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.js +17 -0
- package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disputes/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/disputes/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disputes/route.js +27 -0
- package/.medusa/server/src/api/admin/paypal/disputes/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disputes/summary/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/disputes/summary/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/disputes/summary/route.js +17 -0
- package/.medusa/server/src/api/admin/paypal/disputes/summary/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.js +23 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +8 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +41 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +35 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +20 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.js +8 -0
- package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.js +9 -0
- package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +13 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.js +14 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -0
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/status/route.js +11 -0
- package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +3 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +43 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +215 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/config/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal/config/route.js +45 -0
- package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.js +305 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/disputes/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal/disputes/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal/disputes/route.js +46 -0
- package/.medusa/server/src/api/store/paypal/disputes/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal/settings/route.js +14 -0
- package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.js +203 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -0
- package/.medusa/server/src/jobs/paypal-reconcile.d.ts +7 -0
- package/.medusa/server/src/jobs/paypal-reconcile.d.ts.map +1 -0
- package/.medusa/server/src/jobs/paypal-reconcile.js +131 -0
- package/.medusa/server/src/jobs/paypal-reconcile.js.map +1 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +7 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.js +78 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts +14 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js +65 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js.map +1 -0
- package/.medusa/server/src/modules/paypal/index.d.ts +92 -0
- package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/index.js +13 -0
- package/.medusa/server/src/modules/paypal/index.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +36 -0
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +25 -0
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +32 -0
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.js +29 -0
- package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +30 -0
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.js +43 -0
- package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +34 -0
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_audit_log.d.ts +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_audit_log.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_audit_log.js +10 -0
- package/.medusa/server/src/modules/paypal/models/paypal_audit_log.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +14 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js +17 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_dispute.d.ts +16 -0
- package/.medusa/server/src/modules/paypal/models/paypal_dispute.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_dispute.js +19 -0
- package/.medusa/server/src/modules/paypal/models/paypal_dispute.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js +10 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js +9 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +17 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +20 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +35 -0
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +569 -0
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +10 -0
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/index.js +22 -0
- package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +44 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +825 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.d.ts +3 -0
- package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.js +74 -0
- package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.js.map +1 -0
- package/.medusa/server/src/modules/paypal/service.d.ts +362 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/service.js +1180 -0
- package/.medusa/server/src/modules/paypal/service.js.map +1 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts +14 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/types/config.js +33 -0
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +3 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.js +40 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/crypto.d.ts +4 -0
- package/.medusa/server/src/modules/paypal/utils/crypto.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/crypto.js +47 -0
- package/.medusa/server/src/modules/paypal/utils/crypto.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +19 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.js +69 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +9 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js +50 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +38 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.js +265 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/package.json +61 -0
- package/postcss.config.cjs +3 -0
- package/src/admin/index.ts +7 -0
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +55 -0
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +51 -0
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +346 -0
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +381 -0
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +5 -0
- package/src/admin/routes/settings/paypal/audit-logs/page.tsx +131 -0
- package/src/admin/routes/settings/paypal/connection/page.tsx +750 -0
- package/src/admin/routes/settings/paypal/disputes/page.tsx +259 -0
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +5 -0
- package/src/admin/routes/settings/paypal/page.tsx +16 -0
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +5 -0
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +557 -0
- package/src/admin/routes/settings/paypal/reconciliation-status/page.tsx +165 -0
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +32 -0
- package/src/api/admin/paypal/audit-logs/route.ts +13 -0
- package/src/api/admin/paypal/disconnect/route.ts +8 -0
- package/src/api/admin/paypal/disputes/[id]/route.ts +19 -0
- package/src/api/admin/paypal/disputes/route.ts +30 -0
- package/src/api/admin/paypal/disputes/summary/route.ts +18 -0
- package/src/api/admin/paypal/environment/route.ts +25 -0
- package/src/api/admin/paypal/onboard-complete/route.ts +44 -0
- package/src/api/admin/paypal/onboarding-link/route.ts +45 -0
- package/src/api/admin/paypal/onboarding-status/route.ts +18 -0
- package/src/api/admin/paypal/reconciliation-status/route.ts +7 -0
- package/src/api/admin/paypal/rotate-credentials/route.ts +8 -0
- package/src/api/admin/paypal/save-credentials/route.ts +14 -0
- package/src/api/admin/paypal/settings/route.ts +14 -0
- package/src/api/admin/paypal/status/route.ts +12 -0
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +51 -0
- package/src/api/store/paypal/capture-order/route.ts +270 -0
- package/src/api/store/paypal/config/route.ts +59 -0
- package/src/api/store/paypal/create-order/route.ts +374 -0
- package/src/api/store/paypal/disputes/route.ts +67 -0
- package/src/api/store/paypal/settings/route.ts +12 -0
- package/src/api/store/paypal/webhook/route.ts +247 -0
- package/src/jobs/paypal-reconcile.ts +135 -0
- package/src/jobs/paypal-webhook-retry.ts +86 -0
- package/src/modules/paypal/clients/paypal-seller.client.ts +59 -0
- package/src/modules/paypal/index.ts +8 -0
- package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -0
- package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -0
- package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -0
- package/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.ts +26 -0
- package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -0
- package/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.ts +40 -0
- package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -0
- package/src/modules/paypal/models/paypal_audit_log.ts +9 -0
- package/src/modules/paypal/models/paypal_connection.ts +21 -0
- package/src/modules/paypal/models/paypal_dispute.ts +18 -0
- package/src/modules/paypal/models/paypal_metric.ts +9 -0
- package/src/modules/paypal/models/paypal_settings.ts +8 -0
- package/src/modules/paypal/models/paypal_webhook_event.ts +19 -0
- package/src/modules/paypal/payment-provider/README.md +22 -0
- package/src/modules/paypal/payment-provider/card-service.ts +710 -0
- package/src/modules/paypal/payment-provider/index.ts +19 -0
- package/src/modules/paypal/payment-provider/service.ts +1035 -0
- package/src/modules/paypal/payment-provider/webhook-utils.ts +88 -0
- package/src/modules/paypal/service.ts +1422 -0
- package/src/modules/paypal/types/config.ts +47 -0
- package/src/modules/paypal/utils/amounts.ts +41 -0
- package/src/modules/paypal/utils/crypto.ts +51 -0
- package/src/modules/paypal/utils/currencies.ts +84 -0
- package/src/modules/paypal/utils/provider-ids.ts +53 -0
- package/src/modules/paypal/webhook-processor.ts +313 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type PayPalModuleConfig = {
|
|
2
|
+
partnerServiceUrl: string
|
|
3
|
+
partnerJsUrl: string
|
|
4
|
+
backendUrl: string
|
|
5
|
+
sellerNonce: string
|
|
6
|
+
bnCode?: string
|
|
7
|
+
partnerMerchantIdSandbox: string
|
|
8
|
+
partnerMerchantIdLive: string
|
|
9
|
+
credentialsEncryptionKey?: string
|
|
10
|
+
credentialsEncryptionKeyPrevious?: string[]
|
|
11
|
+
alertWebhookUrls?: string[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const STATIC_CFG: PayPalModuleConfig = {
|
|
15
|
+
partnerServiceUrl: "https://mbjtechnolabs.com/ppcp-seller-onboarding/seller-onboarding.php",
|
|
16
|
+
partnerJsUrl: "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js",
|
|
17
|
+
backendUrl: "http://localhost:9000",
|
|
18
|
+
sellerNonce: "a1233wtergfsdt4365tzrshgfbaewa36AGa1233wtergfsdt4365tzrshgfbaewa36AG",
|
|
19
|
+
bnCode: "",
|
|
20
|
+
partnerMerchantIdSandbox: "K6QLN2LPGQRHL",
|
|
21
|
+
partnerMerchantIdLive: "GT5R877JNBPLL",
|
|
22
|
+
credentialsEncryptionKey: "",
|
|
23
|
+
credentialsEncryptionKeyPrevious: [],
|
|
24
|
+
alertWebhookUrls: [],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getPayPalConfig(): PayPalModuleConfig {
|
|
28
|
+
const previousKeys = (process.env.PAYPAL_CREDENTIALS_ENCRYPTION_KEY_PREVIOUS || "")
|
|
29
|
+
.split(",")
|
|
30
|
+
.map((key) => key.trim())
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
...STATIC_CFG,
|
|
35
|
+
backendUrl: process.env.MEDUSA_BACKEND_URL || STATIC_CFG.backendUrl,
|
|
36
|
+
credentialsEncryptionKey:
|
|
37
|
+
process.env.PAYPAL_CREDENTIALS_ENCRYPTION_KEY ||
|
|
38
|
+
STATIC_CFG.credentialsEncryptionKey,
|
|
39
|
+
credentialsEncryptionKeyPrevious:
|
|
40
|
+
previousKeys.length > 0 ? previousKeys : STATIC_CFG.credentialsEncryptionKeyPrevious,
|
|
41
|
+
alertWebhookUrls:
|
|
42
|
+
(process.env.PAYPAL_ALERT_WEBHOOK_URLS || "")
|
|
43
|
+
.split(",")
|
|
44
|
+
.map((url) => url.trim())
|
|
45
|
+
.filter(Boolean) || STATIC_CFG.alertWebhookUrls,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const ZERO_DECIMAL_CURRENCIES = new Set([
|
|
2
|
+
"BIF",
|
|
3
|
+
"CLP",
|
|
4
|
+
"DJF",
|
|
5
|
+
"GNF",
|
|
6
|
+
"JPY",
|
|
7
|
+
"KMF",
|
|
8
|
+
"KRW",
|
|
9
|
+
"MGA",
|
|
10
|
+
"PYG",
|
|
11
|
+
"RWF",
|
|
12
|
+
"UGX",
|
|
13
|
+
"VND",
|
|
14
|
+
"VUV",
|
|
15
|
+
"XAF",
|
|
16
|
+
"XOF",
|
|
17
|
+
"XPF",
|
|
18
|
+
])
|
|
19
|
+
|
|
20
|
+
const THREE_DECIMAL_CURRENCIES = new Set(["BHD", "JOD", "KWD", "OMR", "TND"])
|
|
21
|
+
|
|
22
|
+
export function getCurrencyExponent(currencyCode: string) {
|
|
23
|
+
const code = currencyCode.toUpperCase()
|
|
24
|
+
if (ZERO_DECIMAL_CURRENCIES.has(code)) {
|
|
25
|
+
return 0
|
|
26
|
+
}
|
|
27
|
+
if (THREE_DECIMAL_CURRENCIES.has(code)) {
|
|
28
|
+
return 3
|
|
29
|
+
}
|
|
30
|
+
return 2
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function formatAmountForPayPal(
|
|
34
|
+
minorAmount: number,
|
|
35
|
+
currencyCode: string
|
|
36
|
+
) {
|
|
37
|
+
const exponent = getCurrencyExponent(currencyCode)
|
|
38
|
+
const factor = 10 ** exponent
|
|
39
|
+
const majorAmount = Number(minorAmount || 0) / factor
|
|
40
|
+
return majorAmount.toFixed(exponent)
|
|
41
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto"
|
|
2
|
+
|
|
3
|
+
const ENCRYPTED_PREFIX = "enc:"
|
|
4
|
+
const ALGORITHM = "aes-256-gcm"
|
|
5
|
+
const IV_LENGTH = 12
|
|
6
|
+
|
|
7
|
+
function deriveKey(secret: string) {
|
|
8
|
+
return createHash("sha256").update(secret).digest()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isEncryptedSecret(value?: string | null) {
|
|
12
|
+
return typeof value === "string" && value.startsWith(ENCRYPTED_PREFIX)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function encryptSecret(value: string, secret: string) {
|
|
16
|
+
if (!value || isEncryptedSecret(value)) {
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const iv = randomBytes(IV_LENGTH)
|
|
21
|
+
const cipher = createCipheriv(ALGORITHM, deriveKey(secret), iv)
|
|
22
|
+
const encrypted = Buffer.concat([cipher.update(value, "utf8"), cipher.final()])
|
|
23
|
+
const tag = cipher.getAuthTag()
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
ENCRYPTED_PREFIX.slice(0, -1),
|
|
27
|
+
iv.toString("base64"),
|
|
28
|
+
tag.toString("base64"),
|
|
29
|
+
encrypted.toString("base64"),
|
|
30
|
+
].join(":")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function decryptSecret(value: string, secret: string) {
|
|
34
|
+
if (!isEncryptedSecret(value)) {
|
|
35
|
+
return value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const [, ivBase64, tagBase64, payloadBase64] = value.split(":")
|
|
39
|
+
if (!ivBase64 || !tagBase64 || !payloadBase64) {
|
|
40
|
+
throw new Error("Invalid encrypted PayPal secret format.")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const iv = Buffer.from(ivBase64, "base64")
|
|
44
|
+
const tag = Buffer.from(tagBase64, "base64")
|
|
45
|
+
const payload = Buffer.from(payloadBase64, "base64")
|
|
46
|
+
const decipher = createDecipheriv(ALGORITHM, deriveKey(secret), iv)
|
|
47
|
+
decipher.setAuthTag(tag)
|
|
48
|
+
const decrypted = Buffer.concat([decipher.update(payload), decipher.final()])
|
|
49
|
+
|
|
50
|
+
return decrypted.toString("utf8")
|
|
51
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const PAYPAL_SUPPORTED_CURRENCIES = new Set([
|
|
2
|
+
"AUD",
|
|
3
|
+
"BRL",
|
|
4
|
+
"CAD",
|
|
5
|
+
"CHF",
|
|
6
|
+
"CZK",
|
|
7
|
+
"DKK",
|
|
8
|
+
"EUR",
|
|
9
|
+
"GBP",
|
|
10
|
+
"HKD",
|
|
11
|
+
"HUF",
|
|
12
|
+
"ILS",
|
|
13
|
+
"JPY",
|
|
14
|
+
"MXN",
|
|
15
|
+
"MYR",
|
|
16
|
+
"NOK",
|
|
17
|
+
"NZD",
|
|
18
|
+
"PHP",
|
|
19
|
+
"PLN",
|
|
20
|
+
"SEK",
|
|
21
|
+
"SGD",
|
|
22
|
+
"THB",
|
|
23
|
+
"TWD",
|
|
24
|
+
"USD",
|
|
25
|
+
])
|
|
26
|
+
|
|
27
|
+
type CurrencyCheck = {
|
|
28
|
+
currency: string
|
|
29
|
+
overrideCurrency?: string
|
|
30
|
+
supported: boolean
|
|
31
|
+
errors: string[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function normalizeCurrencyCode(code?: string, fallback = "USD") {
|
|
35
|
+
const trimmed = String(code || "").trim()
|
|
36
|
+
return (trimmed || fallback).toUpperCase()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isPayPalCurrencySupported(currencyCode: string) {
|
|
40
|
+
return PAYPAL_SUPPORTED_CURRENCIES.has(normalizeCurrencyCode(currencyCode))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getPayPalCurrencyCompatibility(input: {
|
|
44
|
+
currencyCode?: string
|
|
45
|
+
paypalCurrencyOverride?: string
|
|
46
|
+
}): CurrencyCheck {
|
|
47
|
+
const currency = normalizeCurrencyCode(input.currencyCode)
|
|
48
|
+
const overrideCurrency = input.paypalCurrencyOverride
|
|
49
|
+
? normalizeCurrencyCode(input.paypalCurrencyOverride)
|
|
50
|
+
: undefined
|
|
51
|
+
const errors: string[] = []
|
|
52
|
+
|
|
53
|
+
if (!isPayPalCurrencySupported(currency)) {
|
|
54
|
+
errors.push(`PayPal does not support currency "${currency}".`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (overrideCurrency && overrideCurrency !== currency) {
|
|
58
|
+
errors.push(
|
|
59
|
+
`PayPal is configured for "${overrideCurrency}", but the store cart uses "${currency}".`
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
currency,
|
|
65
|
+
overrideCurrency,
|
|
66
|
+
supported: errors.length === 0,
|
|
67
|
+
errors,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function assertPayPalCurrencySupported(input: {
|
|
72
|
+
currencyCode?: string
|
|
73
|
+
paypalCurrencyOverride?: string
|
|
74
|
+
}) {
|
|
75
|
+
const result = getPayPalCurrencyCompatibility(input)
|
|
76
|
+
if (!result.supported) {
|
|
77
|
+
throw new Error(result.errors.join(" "))
|
|
78
|
+
}
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getPayPalSupportedCurrencies() {
|
|
83
|
+
return Array.from(PAYPAL_SUPPORTED_CURRENCIES.values())
|
|
84
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const PAYPAL_WALLET_PROVIDER_IDS = ["paypal"] as const
|
|
2
|
+
export const PAYPAL_CARD_PROVIDER_IDS = ["paypal_card"] as const
|
|
3
|
+
export const PAYPAL_LEGACY_PROVIDER_IDS = [
|
|
4
|
+
"pp_paypal_paypal",
|
|
5
|
+
"pp_paypal_card_paypal",
|
|
6
|
+
"pp",
|
|
7
|
+
"card",
|
|
8
|
+
] as const
|
|
9
|
+
|
|
10
|
+
export const PAYPAL_PROVIDER_IDS = [
|
|
11
|
+
...PAYPAL_WALLET_PROVIDER_IDS,
|
|
12
|
+
...PAYPAL_CARD_PROVIDER_IDS,
|
|
13
|
+
] as const
|
|
14
|
+
|
|
15
|
+
export const PAYPAL_PROVIDER_IDS_WITH_LEGACY = [
|
|
16
|
+
...PAYPAL_PROVIDER_IDS,
|
|
17
|
+
...PAYPAL_LEGACY_PROVIDER_IDS,
|
|
18
|
+
] as const
|
|
19
|
+
|
|
20
|
+
export const isPayPalProviderId = (providerId?: string | null) => {
|
|
21
|
+
if (!providerId) return false
|
|
22
|
+
return PAYPAL_PROVIDER_IDS.includes(providerId as (typeof PAYPAL_PROVIDER_IDS)[number])
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const isLegacyPayPalProviderId = (providerId?: string | null) => {
|
|
26
|
+
if (!providerId) return false
|
|
27
|
+
return PAYPAL_LEGACY_PROVIDER_IDS.includes(
|
|
28
|
+
providerId as (typeof PAYPAL_LEGACY_PROVIDER_IDS)[number]
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const LEGACY_PROVIDER_ID_MAP: Record<
|
|
33
|
+
(typeof PAYPAL_LEGACY_PROVIDER_IDS)[number],
|
|
34
|
+
(typeof PAYPAL_PROVIDER_IDS)[number]
|
|
35
|
+
> = {
|
|
36
|
+
pp_paypal_paypal: "paypal",
|
|
37
|
+
pp_paypal_card_paypal: "paypal_card",
|
|
38
|
+
pp: "paypal",
|
|
39
|
+
card: "paypal_card",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const normalizePayPalProviderId = (providerId?: string | null) => {
|
|
43
|
+
if (!providerId) return null
|
|
44
|
+
if (isPayPalProviderId(providerId)) {
|
|
45
|
+
return providerId as (typeof PAYPAL_PROVIDER_IDS)[number]
|
|
46
|
+
}
|
|
47
|
+
if (isLegacyPayPalProviderId(providerId)) {
|
|
48
|
+
return LEGACY_PROVIDER_ID_MAP[
|
|
49
|
+
providerId as (typeof PAYPAL_LEGACY_PROVIDER_IDS)[number]
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import type { MedusaContainer } from "@medusajs/framework/types"
|
|
2
|
+
import type PayPalModuleService from "./service"
|
|
3
|
+
import { isPayPalProviderId } from "./utils/provider-ids"
|
|
4
|
+
|
|
5
|
+
export const EVENT_STATUS_MAP: Record<string, "authorized" | "captured" | "canceled" | "error"> = {
|
|
6
|
+
"CHECKOUT.ORDER.APPROVED": "authorized",
|
|
7
|
+
"CHECKOUT.ORDER.CANCELLED": "canceled",
|
|
8
|
+
"PAYMENT.CAPTURE.COMPLETED": "captured",
|
|
9
|
+
"PAYMENT.CAPTURE.DENIED": "error",
|
|
10
|
+
"PAYMENT.CAPTURE.REFUNDED": "canceled",
|
|
11
|
+
"PAYMENT.CAPTURE.REVERSED": "canceled",
|
|
12
|
+
"PAYMENT.AUTHORIZATION.CREATED": "authorized",
|
|
13
|
+
"PAYMENT.AUTHORIZATION.VOIDED": "canceled",
|
|
14
|
+
"PAYMENT.AUTHORIZATION.DENIED": "error",
|
|
15
|
+
"PAYMENT.REFUND.COMPLETED": "canceled",
|
|
16
|
+
"PAYMENT.REFUND.DENIED": "error",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const REQUIRED_EVENT_PREFIXES = [
|
|
20
|
+
"PAYMENT.CAPTURE.",
|
|
21
|
+
"CHECKOUT.ORDER.",
|
|
22
|
+
"PAYMENT.AUTHORIZATION.",
|
|
23
|
+
"PAYMENT.REFUND.",
|
|
24
|
+
"CUSTOMER.DISPUTE.",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
export function isAllowedEventType(eventType: string) {
|
|
28
|
+
return REQUIRED_EVENT_PREFIXES.some((prefix) => eventType.startsWith(prefix))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function normalizeResource(payload: Record<string, any>) {
|
|
32
|
+
const resource = payload?.resource
|
|
33
|
+
if (!resource) {
|
|
34
|
+
return {}
|
|
35
|
+
}
|
|
36
|
+
if (typeof resource === "string") {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(resource)
|
|
39
|
+
} catch {
|
|
40
|
+
return {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return resource
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function normalizeEventVersion(payload: Record<string, any>) {
|
|
47
|
+
const raw =
|
|
48
|
+
payload?.event_version ??
|
|
49
|
+
payload?.resource_version ??
|
|
50
|
+
payload?.resource?.resource_version ??
|
|
51
|
+
payload?.resource?.version ??
|
|
52
|
+
null
|
|
53
|
+
|
|
54
|
+
if (!raw) {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return String(raw).trim().replace(/^v/i, "")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function extractIdentifiers(resource: any) {
|
|
62
|
+
const relatedIds = resource?.supplementary_data?.related_ids || {}
|
|
63
|
+
const orderId =
|
|
64
|
+
relatedIds?.order_id ||
|
|
65
|
+
resource?.purchase_units?.[0]?.custom_id ||
|
|
66
|
+
resource?.custom_id ||
|
|
67
|
+
resource?.purchase_units?.[0]?.reference_id
|
|
68
|
+
const captureId =
|
|
69
|
+
relatedIds?.capture_id ||
|
|
70
|
+
resource?.id ||
|
|
71
|
+
resource?.purchase_units?.[0]?.payments?.captures?.[0]?.id
|
|
72
|
+
const refundId =
|
|
73
|
+
relatedIds?.refund_id ||
|
|
74
|
+
resource?.id ||
|
|
75
|
+
resource?.purchase_units?.[0]?.payments?.refunds?.[0]?.id
|
|
76
|
+
const cartId =
|
|
77
|
+
resource?.custom_id ||
|
|
78
|
+
resource?.purchase_units?.[0]?.custom_id ||
|
|
79
|
+
resource?.purchase_units?.[0]?.reference_id
|
|
80
|
+
|
|
81
|
+
return { orderId, captureId, refundId, cartId, resource }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function extractDisputeDetails(resource: any) {
|
|
85
|
+
const disputeId = String(resource?.dispute_id || resource?.id || "")
|
|
86
|
+
const disputedTx = Array.isArray(resource?.disputed_transactions)
|
|
87
|
+
? resource.disputed_transactions[0]
|
|
88
|
+
: null
|
|
89
|
+
const transactionId = disputedTx?.transaction_id || undefined
|
|
90
|
+
const sellerTransactionId = disputedTx?.seller_transaction_id || undefined
|
|
91
|
+
const customId = disputedTx?.custom_id || resource?.custom_id || undefined
|
|
92
|
+
const orderId =
|
|
93
|
+
resource?.order_id ||
|
|
94
|
+
resource?.supplementary_data?.related_ids?.order_id ||
|
|
95
|
+
customId ||
|
|
96
|
+
undefined
|
|
97
|
+
const cartId = customId || undefined
|
|
98
|
+
const amount =
|
|
99
|
+
resource?.dispute_amount?.value ||
|
|
100
|
+
resource?.amount?.value ||
|
|
101
|
+
resource?.dispute_amount?.amount ||
|
|
102
|
+
undefined
|
|
103
|
+
const currencyCode =
|
|
104
|
+
resource?.dispute_amount?.currency_code ||
|
|
105
|
+
resource?.amount?.currency_code ||
|
|
106
|
+
resource?.dispute_amount?.currency ||
|
|
107
|
+
undefined
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
disputeId,
|
|
111
|
+
status: resource?.status || null,
|
|
112
|
+
reason: resource?.reason || null,
|
|
113
|
+
stage: resource?.dispute_life_cycle_stage || resource?.stage || null,
|
|
114
|
+
amount: amount ? String(amount) : null,
|
|
115
|
+
currencyCode: currencyCode ? String(currencyCode) : null,
|
|
116
|
+
transactionId: transactionId ? String(transactionId) : null,
|
|
117
|
+
sellerTransactionId: sellerTransactionId ? String(sellerTransactionId) : null,
|
|
118
|
+
orderId: orderId ? String(orderId) : null,
|
|
119
|
+
cartId: cartId ? String(cartId) : null,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function resolveDisputeOrderId(
|
|
124
|
+
container: MedusaContainer,
|
|
125
|
+
orderId?: string | null,
|
|
126
|
+
cartId?: string | null
|
|
127
|
+
) {
|
|
128
|
+
const query = container.resolve("query") as any
|
|
129
|
+
const cleanedOrderId = orderId?.trim()
|
|
130
|
+
const cleanedCartId = cartId?.trim()
|
|
131
|
+
|
|
132
|
+
if (cleanedOrderId) {
|
|
133
|
+
try {
|
|
134
|
+
const { data } = await query.graph({
|
|
135
|
+
entity: "order",
|
|
136
|
+
fields: ["id"],
|
|
137
|
+
filters: { id: cleanedOrderId },
|
|
138
|
+
})
|
|
139
|
+
const match = data?.[0]?.id
|
|
140
|
+
if (match) {
|
|
141
|
+
return String(match)
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
// ignore order lookup failures
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (cleanedCartId) {
|
|
149
|
+
try {
|
|
150
|
+
const { data } = await query.graph({
|
|
151
|
+
entity: "order",
|
|
152
|
+
fields: ["id", "cart_id"],
|
|
153
|
+
filters: { cart_id: cleanedCartId },
|
|
154
|
+
})
|
|
155
|
+
const match = data?.[0]?.id
|
|
156
|
+
if (match) {
|
|
157
|
+
return String(match)
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
// ignore order lookup failures
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return null
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function mergeRefunds(existing: any[], incoming: any[]) {
|
|
168
|
+
const seen = new Set<string>()
|
|
169
|
+
const merged: any[] = []
|
|
170
|
+
|
|
171
|
+
for (const refund of [...existing, ...incoming]) {
|
|
172
|
+
const id = refund?.id ? String(refund.id) : ""
|
|
173
|
+
if (id && seen.has(id)) {
|
|
174
|
+
continue
|
|
175
|
+
}
|
|
176
|
+
if (id) {
|
|
177
|
+
seen.add(id)
|
|
178
|
+
}
|
|
179
|
+
merged.push(refund)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return merged
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function updatePaymentSession(
|
|
186
|
+
container: MedusaContainer,
|
|
187
|
+
cartId: string,
|
|
188
|
+
status: string,
|
|
189
|
+
data: Record<string, unknown>
|
|
190
|
+
) {
|
|
191
|
+
const paymentCollectionService = container.resolve("payment_collection") as any
|
|
192
|
+
const paymentSessionService = container.resolve("payment_session") as any
|
|
193
|
+
|
|
194
|
+
const pc = await paymentCollectionService.retrieveByCartId(cartId).catch(() => null)
|
|
195
|
+
if (!pc?.id) {
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const sessions = await paymentSessionService.list({ payment_collection_id: pc.id })
|
|
200
|
+
const paypalSession = sessions?.find((s: any) => isPayPalProviderId(s.provider_id))
|
|
201
|
+
if (!paypalSession) {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const existingData = (paypalSession.data || {}) as Record<string, any>
|
|
206
|
+
const existingPaypal = (existingData.paypal || {}) as Record<string, any>
|
|
207
|
+
const existingRefunds = Array.isArray(existingPaypal.refunds) ? existingPaypal.refunds : []
|
|
208
|
+
const incomingRefunds = Array.isArray(data.refunds) ? data.refunds : null
|
|
209
|
+
const nextRefunds = incomingRefunds
|
|
210
|
+
? mergeRefunds(existingRefunds, incomingRefunds)
|
|
211
|
+
: existingRefunds
|
|
212
|
+
|
|
213
|
+
await paymentSessionService.update(paypalSession.id, {
|
|
214
|
+
status,
|
|
215
|
+
data: {
|
|
216
|
+
...existingData,
|
|
217
|
+
paypal: {
|
|
218
|
+
...existingPaypal,
|
|
219
|
+
...data,
|
|
220
|
+
refunds: nextRefunds,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function computeNextRetryAt(attemptCount: number) {
|
|
227
|
+
const scheduleMinutes = [5, 15, 30, 60, 120]
|
|
228
|
+
const delayMinutes = scheduleMinutes[Math.min(attemptCount - 1, scheduleMinutes.length - 1)]
|
|
229
|
+
if (!delayMinutes || attemptCount <= 0) {
|
|
230
|
+
return null
|
|
231
|
+
}
|
|
232
|
+
return new Date(Date.now() + delayMinutes * 60 * 1000)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export async function processPayPalWebhookEvent(
|
|
236
|
+
container: MedusaContainer,
|
|
237
|
+
input: {
|
|
238
|
+
eventType: string
|
|
239
|
+
payload: Record<string, any>
|
|
240
|
+
}
|
|
241
|
+
) {
|
|
242
|
+
const paypal = container.resolve<PayPalModuleService>("paypal_onboarding")
|
|
243
|
+
const resource = normalizeResource(input.payload)
|
|
244
|
+
const { orderId, captureId, refundId, cartId } = extractIdentifiers(resource)
|
|
245
|
+
const disputeDetails =
|
|
246
|
+
input.eventType.startsWith("CUSTOMER.DISPUTE.") ? extractDisputeDetails(resource) : null
|
|
247
|
+
const refundReason =
|
|
248
|
+
String(resource?.note_to_payer || resource?.reason || resource?.seller_note || "").trim() ||
|
|
249
|
+
undefined
|
|
250
|
+
const refundReasonCode =
|
|
251
|
+
String(resource?.reason_code || resource?.reasonCode || "").trim() || undefined
|
|
252
|
+
|
|
253
|
+
if (input.eventType.startsWith("CUSTOMER.DISPUTE.")) {
|
|
254
|
+
if (disputeDetails?.disputeId) {
|
|
255
|
+
const resolvedOrderId = await resolveDisputeOrderId(
|
|
256
|
+
container,
|
|
257
|
+
disputeDetails.orderId,
|
|
258
|
+
disputeDetails.cartId
|
|
259
|
+
)
|
|
260
|
+
await paypal.upsertDispute({
|
|
261
|
+
dispute_id: disputeDetails.disputeId,
|
|
262
|
+
status: disputeDetails.status,
|
|
263
|
+
reason: disputeDetails.reason,
|
|
264
|
+
stage: disputeDetails.stage,
|
|
265
|
+
amount: disputeDetails.amount,
|
|
266
|
+
currency_code: disputeDetails.currencyCode,
|
|
267
|
+
transaction_id: disputeDetails.transactionId,
|
|
268
|
+
seller_transaction_id: disputeDetails.sellerTransactionId,
|
|
269
|
+
order_id: resolvedOrderId || disputeDetails.orderId,
|
|
270
|
+
cart_id: disputeDetails.cartId,
|
|
271
|
+
payload: resource,
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const status = EVENT_STATUS_MAP[input.eventType]
|
|
277
|
+
if (status && cartId) {
|
|
278
|
+
const refundEntry =
|
|
279
|
+
refundId || resource?.status
|
|
280
|
+
? [
|
|
281
|
+
{
|
|
282
|
+
id: refundId,
|
|
283
|
+
status: resource?.status,
|
|
284
|
+
reason: refundReason,
|
|
285
|
+
reason_code: refundReasonCode,
|
|
286
|
+
amount: (resource as any)?.amount,
|
|
287
|
+
raw: resource,
|
|
288
|
+
},
|
|
289
|
+
]
|
|
290
|
+
: null
|
|
291
|
+
|
|
292
|
+
await updatePaymentSession(container, cartId, status, {
|
|
293
|
+
order_id: orderId,
|
|
294
|
+
capture_id: captureId,
|
|
295
|
+
refund_id: refundId,
|
|
296
|
+
refund_status: resource?.status,
|
|
297
|
+
refund_reason: refundReason,
|
|
298
|
+
refund_reason_code: refundReasonCode,
|
|
299
|
+
refunds: refundEntry || undefined,
|
|
300
|
+
webhook_event_type: input.eventType,
|
|
301
|
+
webhook_resource: resource,
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
orderId,
|
|
307
|
+
captureId,
|
|
308
|
+
refundId,
|
|
309
|
+
cartId,
|
|
310
|
+
disputeId: disputeDetails?.disputeId,
|
|
311
|
+
resource,
|
|
312
|
+
}
|
|
313
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES2022",
|
|
6
|
+
"DOM"
|
|
7
|
+
],
|
|
8
|
+
"module": "NodeNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
|
+
"rootDir": ".",
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"allowSyntheticDefaultImports": true,
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"strict": false
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src/**/*.ts",
|
|
24
|
+
"src/**/*.tsx"
|
|
25
|
+
],
|
|
26
|
+
"exclude": [
|
|
27
|
+
"node_modules",
|
|
28
|
+
"dist",
|
|
29
|
+
".medusa"
|
|
30
|
+
]
|
|
31
|
+
}
|