@easypayment/medusa-payment-paypal 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +1267 -0
- package/.medusa/server/src/admin/index.mjs +1268 -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 +18 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/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/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 +4 -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 +31 -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 +19 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/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 +17 -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/middlewares.d.ts +3 -0
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -0
- package/.medusa/server/src/api/middlewares.js +16 -0
- package/.medusa/server/src/api/middlewares.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 +204 -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 +77 -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 +361 -0
- package/.medusa/server/src/api/store/paypal/create-order/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 +20 -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 +250 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts +3 -0
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -0
- package/.medusa/server/src/api/store/paypal-complete/route.js +76 -0
- package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -0
- package/.medusa/server/src/index.d.ts +2 -0
- package/.medusa/server/src/index.d.ts.map +1 -0
- package/.medusa/server/src/index.js +9 -0
- package/.medusa/server/src/index.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 +132 -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 +15 -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 +67 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js.map +1 -0
- package/.medusa/server/src/modules/paypal/index.d.ts +64 -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/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/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/migrations/20261101090000_remove_paypal_reconciliation_status.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +28 -0
- package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js +29 -0
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js +14 -0
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js +14 -0
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js +14 -0
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js +20 -0
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js.map +1 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +16 -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 +19 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.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 +32 -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 +625 -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 +6 -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 +18 -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 +39 -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 +869 -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 +266 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/service.js +1149 -0
- package/.medusa/server/src/modules/paypal/service.js.map +1 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts +12 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/types/config.js +24 -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/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/paypal-auth.d.ts +10 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +30 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +5 -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 +16 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +29 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.js +267 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -0
- package/.medusa/server/src/providers/paypal/index.d.ts +5 -0
- package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -0
- package/.medusa/server/src/providers/paypal/index.js +10 -0
- package/.medusa/server/src/providers/paypal/index.js.map +1 -0
- package/.medusa/server/src/providers/paypal_card/index.d.ts +5 -0
- package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -0
- package/.medusa/server/src/providers/paypal_card/index.js +10 -0
- package/.medusa/server/src/providers/paypal_card/index.js.map +1 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts +6 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.js +124 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/package.json +80 -0
- package/src/admin/index.ts +7 -0
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +48 -0
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +51 -0
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +199 -0
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +183 -0
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +5 -0
- package/src/admin/routes/settings/paypal/connection/page.tsx +699 -0
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +5 -0
- package/src/admin/routes/settings/paypal/page.tsx +13 -0
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +5 -0
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +351 -0
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +24 -0
- package/src/api/admin/paypal/disconnect/route.ts +8 -0
- package/src/api/admin/paypal/environment/route.ts +25 -0
- package/src/api/admin/paypal/onboard-complete/route.ts +34 -0
- package/src/api/admin/paypal/onboarding-link/route.ts +45 -0
- package/src/api/admin/paypal/onboarding-status/route.ts +17 -0
- package/src/api/admin/paypal/save-credentials/route.ts +22 -0
- package/src/api/admin/paypal/settings/route.ts +14 -0
- package/src/api/admin/paypal/status/route.ts +12 -0
- package/src/api/middlewares.ts +14 -0
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +56 -0
- package/src/api/store/paypal/capture-order/route.ts +265 -0
- package/src/api/store/paypal/config/route.ts +100 -0
- package/src/api/store/paypal/create-order/route.ts +449 -0
- package/src/api/store/paypal/settings/route.ts +19 -0
- package/src/api/store/paypal/webhook/route.ts +325 -0
- package/src/api/store/paypal-complete/route.ts +95 -0
- package/src/index.ts +1 -0
- package/src/jobs/paypal-webhook-retry.ts +149 -0
- package/src/modules/paypal/clients/paypal-seller.client.ts +62 -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/20260401090000_create_paypal_metric.ts +27 -0
- package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -0
- package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -0
- package/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.ts +26 -0
- package/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.ts +11 -0
- package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +11 -0
- package/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.ts +11 -0
- package/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.ts +17 -0
- package/src/modules/paypal/models/paypal_connection.ts +23 -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 +767 -0
- package/src/modules/paypal/payment-provider/index.ts +15 -0
- package/src/modules/paypal/payment-provider/service.ts +1039 -0
- package/src/modules/paypal/payment-provider/webhook-utils.ts +88 -0
- package/src/modules/paypal/service.ts +1416 -0
- package/src/modules/paypal/types/config.ts +33 -0
- package/src/modules/paypal/utils/amounts.ts +41 -0
- package/src/modules/paypal/utils/currencies.ts +84 -0
- package/src/modules/paypal/utils/paypal-auth.ts +31 -0
- package/src/modules/paypal/utils/provider-ids.ts +15 -0
- package/src/modules/paypal/webhook-processor.ts +363 -0
- package/src/providers/paypal/index.ts +8 -0
- package/src/providers/paypal_card/index.ts +8 -0
- package/src/subscribers/paypal-order-invoice.ts +171 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_WEBHOOK_ATTEMPTS = exports.SUPPORTED_EVENT_PREFIXES = exports.EVENT_STATUS_MAP = void 0;
|
|
4
|
+
exports.isTransitionAllowed = isTransitionAllowed;
|
|
5
|
+
exports.isAllowedEventType = isAllowedEventType;
|
|
6
|
+
exports.isRetryableError = isRetryableError;
|
|
7
|
+
exports.computeNextRetryAt = computeNextRetryAt;
|
|
8
|
+
exports.normalizeResource = normalizeResource;
|
|
9
|
+
exports.normalizeEventVersion = normalizeEventVersion;
|
|
10
|
+
exports.extractIdentifiers = extractIdentifiers;
|
|
11
|
+
exports.processPayPalWebhookEvent = processPayPalWebhookEvent;
|
|
12
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
13
|
+
const provider_ids_1 = require("./utils/provider-ids");
|
|
14
|
+
exports.EVENT_STATUS_MAP = {
|
|
15
|
+
"CHECKOUT.ORDER.APPROVED": "authorized",
|
|
16
|
+
"CHECKOUT.ORDER.CANCELLED": "canceled",
|
|
17
|
+
"PAYMENT.CAPTURE.COMPLETED": "captured",
|
|
18
|
+
"PAYMENT.CAPTURE.DENIED": "error",
|
|
19
|
+
"PAYMENT.CAPTURE.PENDING": "authorized",
|
|
20
|
+
"PAYMENT.CAPTURE.REFUNDED": "canceled",
|
|
21
|
+
"PAYMENT.CAPTURE.REVERSED": "canceled",
|
|
22
|
+
"PAYMENT.AUTHORIZATION.CREATED": "authorized",
|
|
23
|
+
"PAYMENT.AUTHORIZATION.VOIDED": "canceled",
|
|
24
|
+
"PAYMENT.AUTHORIZATION.DENIED": "error",
|
|
25
|
+
"PAYMENT.AUTHORIZATION.EXPIRED": "canceled",
|
|
26
|
+
"PAYMENT.REFUND.COMPLETED": "canceled",
|
|
27
|
+
"PAYMENT.REFUND.DENIED": "error",
|
|
28
|
+
};
|
|
29
|
+
const ALLOWED_TRANSITIONS = {
|
|
30
|
+
pending: new Set(["authorized", "captured", "canceled", "error"]),
|
|
31
|
+
authorized: new Set(["captured", "canceled", "error"]),
|
|
32
|
+
captured: new Set(["canceled"]),
|
|
33
|
+
canceled: new Set([]),
|
|
34
|
+
error: new Set(["authorized", "captured", "canceled"]),
|
|
35
|
+
};
|
|
36
|
+
function isTransitionAllowed(from, to) {
|
|
37
|
+
return ALLOWED_TRANSITIONS[from]?.has(to) ?? false;
|
|
38
|
+
}
|
|
39
|
+
exports.SUPPORTED_EVENT_PREFIXES = [
|
|
40
|
+
"PAYMENT.CAPTURE.",
|
|
41
|
+
"CHECKOUT.ORDER.",
|
|
42
|
+
"PAYMENT.AUTHORIZATION.",
|
|
43
|
+
"PAYMENT.REFUND.",
|
|
44
|
+
];
|
|
45
|
+
function isAllowedEventType(eventType) {
|
|
46
|
+
return exports.SUPPORTED_EVENT_PREFIXES.some((prefix) => eventType.startsWith(prefix));
|
|
47
|
+
}
|
|
48
|
+
const NON_RETRYABLE_PATTERNS = [
|
|
49
|
+
"payment collection not found",
|
|
50
|
+
"no paypal session",
|
|
51
|
+
"session not found",
|
|
52
|
+
"cart not found",
|
|
53
|
+
"no payment collection",
|
|
54
|
+
];
|
|
55
|
+
function isRetryableError(error) {
|
|
56
|
+
const message = String(error instanceof Error ? error.message : error ?? "").toLowerCase();
|
|
57
|
+
return !NON_RETRYABLE_PATTERNS.some((p) => message.includes(p));
|
|
58
|
+
}
|
|
59
|
+
const RETRY_SCHEDULE_MINUTES = [2, 10, 30, 60, 120];
|
|
60
|
+
exports.MAX_WEBHOOK_ATTEMPTS = RETRY_SCHEDULE_MINUTES.length + 1;
|
|
61
|
+
function computeNextRetryAt(attemptCount) {
|
|
62
|
+
const idx = attemptCount - 1;
|
|
63
|
+
const delayMinutes = RETRY_SCHEDULE_MINUTES[idx];
|
|
64
|
+
if (delayMinutes === undefined || attemptCount <= 0)
|
|
65
|
+
return null;
|
|
66
|
+
return new Date(Date.now() + delayMinutes * 60 * 1000);
|
|
67
|
+
}
|
|
68
|
+
function normalizeResource(payload) {
|
|
69
|
+
const resource = payload?.resource;
|
|
70
|
+
if (!resource)
|
|
71
|
+
return {};
|
|
72
|
+
if (typeof resource === "string") {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(resource);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return resource;
|
|
81
|
+
}
|
|
82
|
+
function normalizeEventVersion(payload) {
|
|
83
|
+
const raw = payload?.event_version ??
|
|
84
|
+
payload?.resource_version ??
|
|
85
|
+
payload?.resource?.resource_version ??
|
|
86
|
+
payload?.resource?.version ??
|
|
87
|
+
null;
|
|
88
|
+
if (!raw)
|
|
89
|
+
return null;
|
|
90
|
+
return String(raw).trim().replace(/^v/i, "");
|
|
91
|
+
}
|
|
92
|
+
function extractIdentifiers(resource, eventType) {
|
|
93
|
+
const related = resource?.supplementary_data?.related_ids || {};
|
|
94
|
+
const isOrder = eventType.startsWith("CHECKOUT.ORDER.");
|
|
95
|
+
const isCapture = eventType.startsWith("PAYMENT.CAPTURE.");
|
|
96
|
+
const isAuthorization = eventType.startsWith("PAYMENT.AUTHORIZATION.");
|
|
97
|
+
const isRefund = eventType.startsWith("PAYMENT.REFUND.");
|
|
98
|
+
let orderId = null;
|
|
99
|
+
let captureId = null;
|
|
100
|
+
let refundId = null;
|
|
101
|
+
let cartId = null;
|
|
102
|
+
if (isOrder) {
|
|
103
|
+
orderId = String(resource?.id || "").trim() || null;
|
|
104
|
+
cartId =
|
|
105
|
+
String(resource?.purchase_units?.[0]?.custom_id || resource?.custom_id || "").trim() || null;
|
|
106
|
+
captureId =
|
|
107
|
+
String(resource?.purchase_units?.[0]?.payments?.captures?.[0]?.id || "").trim() || null;
|
|
108
|
+
}
|
|
109
|
+
else if (isCapture) {
|
|
110
|
+
captureId = String(resource?.id || "").trim() || null;
|
|
111
|
+
orderId = String(related?.order_id || "").trim() || null;
|
|
112
|
+
cartId = String(resource?.custom_id || "").trim() || null;
|
|
113
|
+
}
|
|
114
|
+
else if (isAuthorization) {
|
|
115
|
+
orderId = String(related?.order_id || "").trim() || null;
|
|
116
|
+
cartId = String(resource?.custom_id || "").trim() || null;
|
|
117
|
+
}
|
|
118
|
+
else if (isRefund) {
|
|
119
|
+
refundId = String(resource?.id || "").trim() || null;
|
|
120
|
+
orderId = String(related?.order_id || "").trim() || null;
|
|
121
|
+
captureId = String(related?.capture_id || "").trim() || null;
|
|
122
|
+
cartId = null;
|
|
123
|
+
}
|
|
124
|
+
return { orderId, captureId, refundId, cartId };
|
|
125
|
+
}
|
|
126
|
+
async function findPayPalSession(container, cartId) {
|
|
127
|
+
const paymentModule = container.resolve(utils_1.Modules.PAYMENT);
|
|
128
|
+
let collections;
|
|
129
|
+
try {
|
|
130
|
+
collections = await paymentModule.listPaymentCollections({ cart_id: [cartId] }, { take: 1 });
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
throw new Error(`payment collection not found for cart ${cartId}: ${e?.message}`);
|
|
134
|
+
}
|
|
135
|
+
const collection = collections?.[0];
|
|
136
|
+
if (!collection?.id) {
|
|
137
|
+
throw new Error(`payment collection not found for cart ${cartId}`);
|
|
138
|
+
}
|
|
139
|
+
const sessions = await paymentModule.listPaymentSessions({
|
|
140
|
+
payment_collection_id: collection.id,
|
|
141
|
+
});
|
|
142
|
+
const paypalSession = (sessions || [])
|
|
143
|
+
.filter((s) => (0, provider_ids_1.isPayPalProviderId)(s.provider_id))
|
|
144
|
+
.sort((a, b) => new Date(b.created_at || 0).getTime() -
|
|
145
|
+
new Date(a.created_at || 0).getTime())[0];
|
|
146
|
+
if (!paypalSession) {
|
|
147
|
+
throw new Error(`no paypal session found in collection ${collection.id} for cart ${cartId}`);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
sessionId: paypalSession.id,
|
|
151
|
+
sessionData: (paypalSession.data || {}),
|
|
152
|
+
sessionStatus: String(paypalSession.status || "pending"),
|
|
153
|
+
collectionId: collection.id,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function mergeRefunds(existing, incoming) {
|
|
157
|
+
const seen = new Set();
|
|
158
|
+
const merged = [];
|
|
159
|
+
for (const refund of [...existing, ...incoming]) {
|
|
160
|
+
const id = String(refund?.id || "");
|
|
161
|
+
if (id && seen.has(id))
|
|
162
|
+
continue;
|
|
163
|
+
if (id)
|
|
164
|
+
seen.add(id);
|
|
165
|
+
merged.push(refund);
|
|
166
|
+
}
|
|
167
|
+
return merged;
|
|
168
|
+
}
|
|
169
|
+
async function applyStatusToSession(container, resolved, status, patch) {
|
|
170
|
+
const paymentModule = container.resolve(utils_1.Modules.PAYMENT);
|
|
171
|
+
if (!isTransitionAllowed(resolved.sessionStatus, status)) {
|
|
172
|
+
console.info(`[PayPal] webhook: skipping disallowed transition ${resolved.sessionStatus} → ${status} for session ${resolved.sessionId}`);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const existingPaypal = (resolved.sessionData.paypal || {});
|
|
176
|
+
const existingRefunds = Array.isArray(existingPaypal.refunds)
|
|
177
|
+
? existingPaypal.refunds
|
|
178
|
+
: [];
|
|
179
|
+
const incomingRefunds = Array.isArray(patch.refunds)
|
|
180
|
+
? patch.refunds
|
|
181
|
+
: null;
|
|
182
|
+
const nextRefunds = incomingRefunds
|
|
183
|
+
? mergeRefunds(existingRefunds, incomingRefunds)
|
|
184
|
+
: existingRefunds;
|
|
185
|
+
await paymentModule.updatePaymentSession({
|
|
186
|
+
id: resolved.sessionId,
|
|
187
|
+
status,
|
|
188
|
+
data: {
|
|
189
|
+
...resolved.sessionData,
|
|
190
|
+
paypal: {
|
|
191
|
+
...existingPaypal,
|
|
192
|
+
...patch,
|
|
193
|
+
refunds: nextRefunds,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async function processPayPalWebhookEvent(container, input) {
|
|
199
|
+
const resource = normalizeResource(input.payload);
|
|
200
|
+
const { orderId, captureId, refundId, cartId: rawCartId } = extractIdentifiers(resource, input.eventType);
|
|
201
|
+
const refundReason = String(resource?.note_to_payer || resource?.reason || resource?.seller_note || "").trim() || undefined;
|
|
202
|
+
const refundReasonCode = String(resource?.reason_code || resource?.reasonCode || "").trim() ||
|
|
203
|
+
undefined;
|
|
204
|
+
const targetStatus = exports.EVENT_STATUS_MAP[input.eventType];
|
|
205
|
+
if (!targetStatus) {
|
|
206
|
+
return { orderId, captureId, refundId, cartId: rawCartId, sessionUpdated: false };
|
|
207
|
+
}
|
|
208
|
+
let cartId = rawCartId;
|
|
209
|
+
if (!cartId) {
|
|
210
|
+
try {
|
|
211
|
+
const paymentModule = container.resolve(utils_1.Modules.PAYMENT);
|
|
212
|
+
const allSessions = await paymentModule.listPaymentSessions({
|
|
213
|
+
provider_id: ["pp_paypal_paypal", "pp_paypal_card_paypal_card"],
|
|
214
|
+
});
|
|
215
|
+
const matchedSession = (allSessions || []).find((s) => {
|
|
216
|
+
const pp = (s.data || {}).paypal || {};
|
|
217
|
+
if (orderId && pp.order_id === orderId)
|
|
218
|
+
return true;
|
|
219
|
+
if (captureId && pp.capture_id === captureId)
|
|
220
|
+
return true;
|
|
221
|
+
return false;
|
|
222
|
+
});
|
|
223
|
+
if (matchedSession?.payment_collection_id) {
|
|
224
|
+
const colls = await paymentModule.listPaymentCollections({ id: [matchedSession.payment_collection_id] }, { take: 1 });
|
|
225
|
+
cartId = String(colls?.[0]?.cart_id || "").trim() || null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
console.warn(`[PayPal] webhook: cartId fallback lookup failed for ${input.eventType}:`, e?.message);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
let sessionUpdated = false;
|
|
233
|
+
if (cartId) {
|
|
234
|
+
const resolved = await findPayPalSession(container, cartId);
|
|
235
|
+
if (resolved) {
|
|
236
|
+
const refundEntry = refundId
|
|
237
|
+
? [
|
|
238
|
+
{
|
|
239
|
+
id: refundId,
|
|
240
|
+
status: resource?.status,
|
|
241
|
+
reason: refundReason,
|
|
242
|
+
reason_code: refundReasonCode,
|
|
243
|
+
amount: resource?.amount,
|
|
244
|
+
raw: resource,
|
|
245
|
+
},
|
|
246
|
+
]
|
|
247
|
+
: null;
|
|
248
|
+
await applyStatusToSession(container, resolved, targetStatus, {
|
|
249
|
+
order_id: orderId,
|
|
250
|
+
capture_id: captureId ?? resolved.sessionData.paypal?.capture_id ?? undefined,
|
|
251
|
+
refund_id: refundId,
|
|
252
|
+
refund_status: refundId ? resource?.status : undefined,
|
|
253
|
+
refund_reason: refundReason,
|
|
254
|
+
refund_reason_code: refundReasonCode,
|
|
255
|
+
...(refundEntry ? { refunds: refundEntry } : {}),
|
|
256
|
+
webhook_event_type: input.eventType,
|
|
257
|
+
last_webhook_at: new Date().toISOString(),
|
|
258
|
+
});
|
|
259
|
+
sessionUpdated = true;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
console.warn(`[PayPal] webhook: could not resolve cartId for event ${input.eventType}`, { orderId, captureId, refundId });
|
|
264
|
+
}
|
|
265
|
+
return { orderId, captureId, refundId, cartId, sessionUpdated };
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=webhook-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-processor.js","sourceRoot":"","sources":["../../../../../src/modules/paypal/webhook-processor.ts"],"names":[],"mappings":";;;AAiCA,kDAEC;AAUD,gDAEC;AAWD,4CAKC;AAMD,gDAKC;AAGD,8CAWC;AAED,sDASC;AAUD,gDAwCC;AAuHD,8DA8FC;AAzWD,qDAAmD;AACnD,uDAAyD;AAG5C,QAAA,gBAAgB,GAGzB;IACF,yBAAyB,EAAE,YAAY;IACvC,0BAA0B,EAAE,UAAU;IACtC,2BAA2B,EAAE,UAAU;IACvC,wBAAwB,EAAE,OAAO;IACjC,yBAAyB,EAAE,YAAY;IACvC,0BAA0B,EAAE,UAAU;IACtC,0BAA0B,EAAE,UAAU;IACtC,+BAA+B,EAAE,YAAY;IAC7C,8BAA8B,EAAE,UAAU;IAC1C,8BAA8B,EAAE,OAAO;IACvC,+BAA+B,EAAE,UAAU;IAC3C,0BAA0B,EAAE,UAAU;IACtC,uBAAuB,EAAE,OAAO;CACjC,CAAA;AAGD,MAAM,mBAAmB,GAAgC;IACvD,OAAO,EAAE,IAAI,GAA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oot":"","sources":["../../../../../src/providers/paypal/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAA;;AAErF,wBAEE;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PayPalPaymentProvider = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const service_1 = require("../../modules/paypal/payment-provider/service");
|
|
6
|
+
Object.defineProperty(exports, "PayPalPaymentProvider", { enumerable: true, get: function () { return service_1.PayPalPaymentProvider; } });
|
|
7
|
+
exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.PAYMENT, {
|
|
8
|
+
services: [service_1.PayPalPaymentProvider],
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/providers/paypal/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmE;AACnE,2EAAqF;AAM5E,sGANA,+BAAqB,OAMA;AAJ9B,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,OAAO,EAAE;IAC7C,QAAQ,EAAE,CAAC,+BAAqB,CAAC;CAClC,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PayPalAdvancedCardProvider } from "../../modules/paypal/payment-provider/card-service";
|
|
2
|
+
declare const _default: import("@medusajs/types").ModuleProviderExports;
|
|
3
|
+
export default _default;
|
|
4
|
+
export { PayPalAdvancedCardProvider };
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/providers/paypal_card/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oDAAoD,CAAA;;AAE/F,wBAEE;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PayPalAdvancedCardProvider = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const card_service_1 = require("../../modules/paypal/payment-provider/card-service");
|
|
6
|
+
Object.defineProperty(exports, "PayPalAdvancedCardProvider", { enumerable: true, get: function () { return card_service_1.PayPalAdvancedCardProvider; } });
|
|
7
|
+
exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.PAYMENT, {
|
|
8
|
+
services: [card_service_1.PayPalAdvancedCardProvider],
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/providers/paypal_card/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmE;AACnE,qFAA+F;AAMtF,2GANA,yCAA0B,OAMA;AAJnC,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,OAAO,EAAE;IAC7C,QAAQ,EAAE,CAAC,yCAA0B,CAAC;CACvC,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
|
|
2
|
+
export default function paypalOrderInvoiceHandler({ event, container, }: SubscriberArgs<{
|
|
3
|
+
id: string;
|
|
4
|
+
}>): Promise<void>;
|
|
5
|
+
export declare const config: SubscriberConfig;
|
|
6
|
+
//# sourceMappingURL=paypal-order-invoice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paypal-order-invoice.d.ts","sourceRoot":"","sources":["../../../../src/subscribers/paypal-order-invoice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAO3E,wBAA8B,yBAAyB,CAAC,EACtD,KAAK,EACL,SAAS,GACV,EAAE,cAAc,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,iBA4JhC;AAED,eAAO,MAAM,MAAM,EAAE,gBAEpB,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.config = void 0;
|
|
4
|
+
exports.default = paypalOrderInvoiceHandler;
|
|
5
|
+
const paypal_auth_1 = require("../modules/paypal/utils/paypal-auth");
|
|
6
|
+
const provider_ids_1 = require("../modules/paypal/utils/provider-ids");
|
|
7
|
+
const PATCHABLE_STATUSES = new Set(["CREATED", "APPROVED", "SAVED"]);
|
|
8
|
+
async function paypalOrderInvoiceHandler({ event, container, }) {
|
|
9
|
+
const orderId = event?.data?.id;
|
|
10
|
+
if (!orderId)
|
|
11
|
+
return;
|
|
12
|
+
try {
|
|
13
|
+
const query = container.resolve("query");
|
|
14
|
+
const paypal = container.resolve("paypal_onboarding");
|
|
15
|
+
const { data: orders } = await query.graph({
|
|
16
|
+
entity: "order",
|
|
17
|
+
fields: [
|
|
18
|
+
"id",
|
|
19
|
+
"display_id",
|
|
20
|
+
"payment_collections.payment_sessions.id",
|
|
21
|
+
"payment_collections.payment_sessions.data",
|
|
22
|
+
"payment_collections.payment_sessions.provider_id",
|
|
23
|
+
"payment_collections.payment_sessions.status",
|
|
24
|
+
"payment_collections.payment_sessions.created_at",
|
|
25
|
+
],
|
|
26
|
+
filters: { id: orderId },
|
|
27
|
+
});
|
|
28
|
+
const order = orders?.[0];
|
|
29
|
+
if (!order)
|
|
30
|
+
return;
|
|
31
|
+
const sessions = (order.payment_collections || []).flatMap((pc) => pc.payment_sessions || []);
|
|
32
|
+
const paypalSession = sessions
|
|
33
|
+
.filter((s) => (0, provider_ids_1.isPayPalProviderId)(s.provider_id))
|
|
34
|
+
.sort((a, b) => new Date(b.created_at || 0).getTime() -
|
|
35
|
+
new Date(a.created_at || 0).getTime())[0];
|
|
36
|
+
if (!paypalSession) {
|
|
37
|
+
console.info("[PayPal] invoice subscriber: no PayPal session for order", orderId);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const paypalData = ((paypalSession.data || {}).paypal || {});
|
|
41
|
+
const paypalOrderId = String(paypalData.order_id || "");
|
|
42
|
+
if (!paypalOrderId) {
|
|
43
|
+
console.info("[PayPal] invoice subscriber: no order_id in session for order", orderId);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const settings = await paypal.getSettings().catch(() => ({}));
|
|
47
|
+
const settingsData = settings && typeof settings === "object" && "data" in settings
|
|
48
|
+
? (settings.data ?? {})
|
|
49
|
+
: {};
|
|
50
|
+
const additionalSettings = (settingsData.additional_settings || {});
|
|
51
|
+
const invoicePrefix = typeof additionalSettings.invoicePrefix === "string"
|
|
52
|
+
? additionalSettings.invoicePrefix
|
|
53
|
+
: "";
|
|
54
|
+
const displayId = String(order.display_id || "");
|
|
55
|
+
const invoiceId = `${invoicePrefix}${displayId}`.trim();
|
|
56
|
+
if (!invoiceId)
|
|
57
|
+
return;
|
|
58
|
+
const creds = await paypal.getActiveCredentials();
|
|
59
|
+
const { accessToken, base } = await (0, paypal_auth_1.getPayPalAccessToken)(creds);
|
|
60
|
+
let paypalOrderStatus = "";
|
|
61
|
+
let currentInvoiceId = "";
|
|
62
|
+
try {
|
|
63
|
+
const statusResp = await fetch(`${base}/v2/checkout/orders/${paypalOrderId}`, { headers: { Authorization: `Bearer ${accessToken}` } });
|
|
64
|
+
if (statusResp.ok) {
|
|
65
|
+
const currentOrder = await statusResp.json().catch(() => ({}));
|
|
66
|
+
paypalOrderStatus = String(currentOrder?.status || "").toUpperCase();
|
|
67
|
+
currentInvoiceId = currentOrder?.purchase_units?.[0]?.invoice_id || "";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.warn("[PayPal] invoice subscriber: order status fetch failed:", e?.message);
|
|
72
|
+
}
|
|
73
|
+
console.info("[PayPal] invoice reconciliation mapping:", {
|
|
74
|
+
medusaOrderId: orderId,
|
|
75
|
+
displayId,
|
|
76
|
+
invoiceId,
|
|
77
|
+
paypalOrderId,
|
|
78
|
+
paypalOrderStatus,
|
|
79
|
+
currentInvoiceId,
|
|
80
|
+
});
|
|
81
|
+
if (paypalOrderStatus && !PATCHABLE_STATUSES.has(paypalOrderStatus)) {
|
|
82
|
+
console.info(`[PayPal] invoice_id PATCH skipped — order status is ${paypalOrderStatus} (immutable).`, `Reconcile via: PayPal order ${paypalOrderId} = Medusa order #${displayId}`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (currentInvoiceId === invoiceId) {
|
|
86
|
+
console.info(`[PayPal] invoice_id already "${invoiceId}" — skipping PATCH`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const patchResp = await fetch(`${base}/v2/checkout/orders/${paypalOrderId}`, {
|
|
90
|
+
method: "PATCH",
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer ${accessToken}`,
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify([
|
|
96
|
+
{
|
|
97
|
+
op: "replace",
|
|
98
|
+
path: "/purchase_units/@reference_id=='default'/invoice_id",
|
|
99
|
+
value: invoiceId,
|
|
100
|
+
},
|
|
101
|
+
]),
|
|
102
|
+
});
|
|
103
|
+
if (patchResp.ok || patchResp.status === 204) {
|
|
104
|
+
console.info(`[PayPal] invoice_id updated to "${invoiceId}"`, `(PayPal order ${paypalOrderId} / Medusa #${displayId})`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const errText = await patchResp.text().catch(() => "");
|
|
108
|
+
console.warn("[PayPal] invoice_id PATCH failed", {
|
|
109
|
+
status: patchResp.status,
|
|
110
|
+
paypalOrderId,
|
|
111
|
+
invoiceId,
|
|
112
|
+
paypalOrderStatus,
|
|
113
|
+
errText,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
console.warn("[PayPal] paypalOrderInvoiceHandler error:", e?.message || e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.config = {
|
|
122
|
+
event: "order.placed",
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=paypal-order-invoice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paypal-order-invoice.js","sourceRoot":"","sources":["../../../../src/subscribers/paypal-order-invoice.ts"],"names":[],"mappings":";;;AAOA,4CA+JC;AApKD,qEAA0E;AAC1E,uEAAyE;AAEzE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AAErD,KAAK,UAAU,yBAAyB,CAAC,EACtD,KAAK,EACL,SAAS,GACsB;IAC/B,MAAM,OAAO,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAA;IAC/B,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAQ,CAAA;QAC/C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;QAE1E,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;YACzC,MAAM,EAAE,OAAO;YACf,MAAM,EAAE;gBACN,IAAI;gBACJ,YAAY;gBACZ,yCAAyC;gBACzC,2CAA2C;gBAC3C,kDAAkD;gBAClD,6CAA6C;gBAC7C,iDAAiD;aAClD;YACD,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE;SACzB,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,CAA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,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;YACtD,OAAO,CAAC,IAAI,CAAC,kCAAkC,EAAE;gBAC/C,MAAM,EAAE,SAAS,CAAC,MAAM;gBACxB,aAAa;gBACb,SAAS;gBACT,iBAAiB;gBACjB,OAAO;aACR,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,2CAA2C,EAAE,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC;AAEY,QAAA,MAAM,GAAqB;IACtC,KAAK,EAAE,cAAc;CACtB,CAAA"}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|