@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,265 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { IPaymentModuleService } from "@medusajs/framework/types"
|
|
3
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
4
|
+
import { randomUUID } from "crypto"
|
|
5
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
6
|
+
import { getPayPalAccessToken } from "../../../../modules/paypal/utils/paypal-auth"
|
|
7
|
+
import { isPayPalProviderId } from "../../../../modules/paypal/utils/provider-ids"
|
|
8
|
+
|
|
9
|
+
const BN_CODE = "MBJTechnolabs_SI_SPB"
|
|
10
|
+
|
|
11
|
+
type Body = {
|
|
12
|
+
cart_id: string
|
|
13
|
+
order_id: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function resolveIdempotencyKey(req: MedusaRequest, suffix: string, fallback: string) {
|
|
17
|
+
const header =
|
|
18
|
+
req.headers["idempotency-key"] ||
|
|
19
|
+
req.headers["Idempotency-Key"] ||
|
|
20
|
+
req.headers["x-idempotency-key"] ||
|
|
21
|
+
req.headers["X-Idempotency-Key"]
|
|
22
|
+
const key = Array.isArray(header) ? header[0] : header
|
|
23
|
+
if (key && String(key).trim()) {
|
|
24
|
+
return `${String(key).trim()}-${suffix}`
|
|
25
|
+
}
|
|
26
|
+
return fallback || `pp-${suffix}-${randomUUID()}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function findPayPalSessionForCart(
|
|
30
|
+
cartId: string,
|
|
31
|
+
scope: any
|
|
32
|
+
): Promise<{
|
|
33
|
+
session_id: string
|
|
34
|
+
session_data: Record<string, any>
|
|
35
|
+
session_status: string
|
|
36
|
+
} | null> {
|
|
37
|
+
try {
|
|
38
|
+
const query = scope.resolve("query")
|
|
39
|
+
const { data: carts } = await query.graph({
|
|
40
|
+
entity: "cart",
|
|
41
|
+
fields: [
|
|
42
|
+
"id",
|
|
43
|
+
"payment_collection.payment_sessions.id",
|
|
44
|
+
"payment_collection.payment_sessions.data",
|
|
45
|
+
"payment_collection.payment_sessions.status",
|
|
46
|
+
"payment_collection.payment_sessions.provider_id",
|
|
47
|
+
"payment_collection.payment_sessions.created_at",
|
|
48
|
+
],
|
|
49
|
+
filters: { id: cartId },
|
|
50
|
+
})
|
|
51
|
+
const cart = carts?.[0]
|
|
52
|
+
const sessions = cart?.payment_collection?.payment_sessions || []
|
|
53
|
+
const session = sessions
|
|
54
|
+
.filter((s: any) => isPayPalProviderId(s.provider_id))
|
|
55
|
+
.sort(
|
|
56
|
+
(a: any, b: any) =>
|
|
57
|
+
new Date(b.created_at || 0).getTime() - new Date(a.created_at || 0).getTime()
|
|
58
|
+
)[0]
|
|
59
|
+
|
|
60
|
+
if (!session) return null
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
session_id: session.id,
|
|
64
|
+
session_data: (session.data || {}) as Record<string, any>,
|
|
65
|
+
session_status: session.status,
|
|
66
|
+
}
|
|
67
|
+
} catch (e: any) {
|
|
68
|
+
console.warn("[PayPal] findPayPalSessionForCart failed:", e?.message)
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function updatePayPalSession(
|
|
74
|
+
sessionId: string,
|
|
75
|
+
status: string,
|
|
76
|
+
extraData: Record<string, any>,
|
|
77
|
+
scope: any
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
try {
|
|
80
|
+
const paymentModule = scope.resolve(Modules.PAYMENT) as IPaymentModuleService
|
|
81
|
+
const [existing] = await paymentModule.listPaymentSessions({ id: [sessionId] }, { take: 1 })
|
|
82
|
+
const mergedData = { ...(existing?.data || {}), ...extraData }
|
|
83
|
+
await (paymentModule as any).updatePaymentSession({
|
|
84
|
+
id: sessionId,
|
|
85
|
+
data: mergedData,
|
|
86
|
+
status: status as any,
|
|
87
|
+
amount: existing?.amount,
|
|
88
|
+
currency_code: existing?.currency_code,
|
|
89
|
+
})
|
|
90
|
+
} catch (e: any) {
|
|
91
|
+
console.error("[PayPal] updatePayPalSession failed:", e?.message)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function attachPayPalCaptureToSession(
|
|
96
|
+
cartId: string,
|
|
97
|
+
orderId: string,
|
|
98
|
+
capture: any,
|
|
99
|
+
scope: any
|
|
100
|
+
) {
|
|
101
|
+
try {
|
|
102
|
+
const session = await findPayPalSessionForCart(cartId, scope)
|
|
103
|
+
if (!session) {
|
|
104
|
+
console.warn("[PayPal] attachPayPalCaptureToSession: no session found for cart", cartId)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const captureId = capture?.purchase_units?.[0]?.payments?.captures?.[0]?.id || capture?.id
|
|
109
|
+
|
|
110
|
+
await updatePayPalSession(
|
|
111
|
+
session.session_id,
|
|
112
|
+
"captured",
|
|
113
|
+
{
|
|
114
|
+
paypal: {
|
|
115
|
+
...((session.session_data || {}).paypal || {}),
|
|
116
|
+
order_id: orderId,
|
|
117
|
+
capture_id: captureId,
|
|
118
|
+
capture,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
scope
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function attachPayPalAuthorizationToSession(
|
|
129
|
+
cartId: string,
|
|
130
|
+
orderId: string,
|
|
131
|
+
authorization: any,
|
|
132
|
+
scope: any
|
|
133
|
+
) {
|
|
134
|
+
try {
|
|
135
|
+
const session = await findPayPalSessionForCart(cartId, scope)
|
|
136
|
+
if (!session) {
|
|
137
|
+
console.warn("[PayPal] attachPayPalAuthorizationToSession: no session found for cart", cartId)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const authorizationId = authorization?.purchase_units?.[0]?.payments?.authorizations?.[0]?.id
|
|
142
|
+
|
|
143
|
+
await updatePayPalSession(
|
|
144
|
+
session.session_id,
|
|
145
|
+
"authorized",
|
|
146
|
+
{
|
|
147
|
+
paypal: {
|
|
148
|
+
...((session.session_data || {}).paypal || {}),
|
|
149
|
+
order_id: orderId,
|
|
150
|
+
authorization_id: authorizationId,
|
|
151
|
+
authorization,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
scope
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function getExistingCapture(cartId: string, orderId: string, scope: any) {
|
|
162
|
+
try {
|
|
163
|
+
const session = await findPayPalSessionForCart(cartId, scope)
|
|
164
|
+
if (!session) return null
|
|
165
|
+
|
|
166
|
+
const paypalData = (session.session_data || {}).paypal || {}
|
|
167
|
+
const existingOrderId = String(paypalData.order_id || "")
|
|
168
|
+
if (existingOrderId && existingOrderId !== orderId) return null
|
|
169
|
+
if (paypalData.capture) return paypalData.capture
|
|
170
|
+
if (paypalData.capture_id) return { id: paypalData.capture_id }
|
|
171
|
+
return null
|
|
172
|
+
} catch {
|
|
173
|
+
return null
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
178
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
179
|
+
const { scope } = req
|
|
180
|
+
let debugId: string | null = null
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
const body = (req.body || {}) as Body
|
|
184
|
+
const cartId = body.cart_id
|
|
185
|
+
const orderId = body.order_id
|
|
186
|
+
|
|
187
|
+
if (!cartId || !orderId) {
|
|
188
|
+
return res.status(400).json({ message: "cart_id and order_id are required" })
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const existingCapture = await getExistingCapture(cartId, orderId, scope)
|
|
192
|
+
if (existingCapture) {
|
|
193
|
+
return res.json({ capture: existingCapture })
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const creds = await paypal.getActiveCredentials()
|
|
197
|
+
const { accessToken, base } = await getPayPalAccessToken(creds)
|
|
198
|
+
const settings = await paypal.getSettings().catch(() => ({}))
|
|
199
|
+
const data =
|
|
200
|
+
settings && typeof settings === "object" && "data" in settings
|
|
201
|
+
? ((settings as { data?: Record<string, any> }).data ?? {})
|
|
202
|
+
: {}
|
|
203
|
+
const additionalSettings = (data.additional_settings || {}) as Record<string, any>
|
|
204
|
+
const paymentAction =
|
|
205
|
+
typeof additionalSettings.paymentAction === "string"
|
|
206
|
+
? additionalSettings.paymentAction
|
|
207
|
+
: "capture"
|
|
208
|
+
|
|
209
|
+
const requestId = resolveIdempotencyKey(req, "capture-order", `pp-capture-${orderId}`)
|
|
210
|
+
const endpoint =
|
|
211
|
+
paymentAction === "authorize"
|
|
212
|
+
? `${base}/v2/checkout/orders/${orderId}/authorize`
|
|
213
|
+
: `${base}/v2/checkout/orders/${orderId}/capture`
|
|
214
|
+
|
|
215
|
+
const ppResp = await fetch(endpoint, {
|
|
216
|
+
method: "POST",
|
|
217
|
+
headers: {
|
|
218
|
+
Authorization: `Bearer ${accessToken}`,
|
|
219
|
+
"Content-Type": "application/json",
|
|
220
|
+
"PayPal-Request-Id": requestId,
|
|
221
|
+
"PayPal-Partner-Attribution-Id": BN_CODE,
|
|
222
|
+
},
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
const ppText = await ppResp.text()
|
|
226
|
+
debugId = ppResp.headers.get("paypal-debug-id")
|
|
227
|
+
if (!ppResp.ok) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`PayPal capture error (${ppResp.status}): ${ppText}${debugId ? ` debug_id=${debugId}` : ""}`
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const payload = JSON.parse(ppText)
|
|
234
|
+
if (paymentAction === "authorize") {
|
|
235
|
+
await attachPayPalAuthorizationToSession(cartId, orderId, payload, req.scope)
|
|
236
|
+
} else {
|
|
237
|
+
await attachPayPalCaptureToSession(cartId, orderId, payload, req.scope)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
await paypal.recordMetric(
|
|
243
|
+
paymentAction === "authorize" ? "authorize_order_success" : "capture_order_success"
|
|
244
|
+
)
|
|
245
|
+
} catch {
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return paymentAction === "authorize"
|
|
249
|
+
? res.json({ authorization: payload })
|
|
250
|
+
: res.json({ capture: payload })
|
|
251
|
+
} catch (e: any) {
|
|
252
|
+
try {
|
|
253
|
+
const body = (req.body || {}) as Body
|
|
254
|
+
await paypal.recordAuditEvent("capture_order_failed", {
|
|
255
|
+
cart_id: body.cart_id,
|
|
256
|
+
order_id: body.order_id,
|
|
257
|
+
debug_id: debugId,
|
|
258
|
+
message: e?.message || String(e),
|
|
259
|
+
})
|
|
260
|
+
await paypal.recordMetric("capture_order_failed")
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
return res.status(500).json({ message: e?.message || "Failed to capture PayPal order" })
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type PayPalModuleService from "../../../../modules/paypal/service"
|
|
3
|
+
import {
|
|
4
|
+
getPayPalCurrencyCompatibility,
|
|
5
|
+
getPayPalSupportedCurrencies,
|
|
6
|
+
normalizeCurrencyCode,
|
|
7
|
+
} from "../../../../modules/paypal/utils/currencies"
|
|
8
|
+
|
|
9
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
10
|
+
const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
|
|
11
|
+
try {
|
|
12
|
+
const creds = await paypal.getActiveCredentials()
|
|
13
|
+
const apiDetails = await paypal.getApiDetails().catch(() => null)
|
|
14
|
+
const client_token = await paypal.generateClientToken({ locale: "en_US" }).catch(() => "")
|
|
15
|
+
const cartId = (req.query?.cart_id as string) || ""
|
|
16
|
+
const query = req.scope.resolve("query")
|
|
17
|
+
let currency = normalizeCurrencyCode(
|
|
18
|
+
apiDetails?.apiDetails?.currency_code || process.env.PAYPAL_CURRENCY || "EUR"
|
|
19
|
+
)
|
|
20
|
+
if (cartId) {
|
|
21
|
+
const { data: carts } = await query.graph({
|
|
22
|
+
entity: "cart",
|
|
23
|
+
fields: ["id", "currency_code", "region.currency_code"],
|
|
24
|
+
filters: { id: cartId },
|
|
25
|
+
})
|
|
26
|
+
const cart = carts?.[0]
|
|
27
|
+
if (cart) {
|
|
28
|
+
currency = normalizeCurrencyCode(
|
|
29
|
+
cart.region?.currency_code || cart.currency_code || currency
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const compatibility = getPayPalCurrencyCompatibility({
|
|
34
|
+
currencyCode: currency,
|
|
35
|
+
paypalCurrencyOverride:
|
|
36
|
+
apiDetails?.apiDetails?.currency_code || process.env.PAYPAL_CURRENCY,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const settings = await paypal.getSettings().catch(() => ({}))
|
|
40
|
+
const data =
|
|
41
|
+
settings && typeof settings === "object" && "data" in settings
|
|
42
|
+
? ((settings as any).data || {})
|
|
43
|
+
: {}
|
|
44
|
+
|
|
45
|
+
const additionalSettings =
|
|
46
|
+
data && typeof data === "object"
|
|
47
|
+
? ((data as Record<string, any>).additional_settings || {})
|
|
48
|
+
: {}
|
|
49
|
+
|
|
50
|
+
const paypalSettings =
|
|
51
|
+
data && typeof data === "object"
|
|
52
|
+
? ((data as Record<string, any>).paypal_settings || {})
|
|
53
|
+
: {}
|
|
54
|
+
|
|
55
|
+
const paymentAction =
|
|
56
|
+
typeof additionalSettings.paymentAction === "string"
|
|
57
|
+
? additionalSettings.paymentAction
|
|
58
|
+
: "capture"
|
|
59
|
+
|
|
60
|
+
if (paypalSettings.enabled === false) {
|
|
61
|
+
return res.status(403).json({ message: "PayPal is currently disabled." })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const advancedCardSettings =
|
|
66
|
+
data && typeof data === "object"
|
|
67
|
+
? ((data as Record<string, any>).advanced_card_payments || {})
|
|
68
|
+
: {}
|
|
69
|
+
|
|
70
|
+
const cardEnabled: boolean = advancedCardSettings.enabled !== false
|
|
71
|
+
|
|
72
|
+
const cardThreeDS =
|
|
73
|
+
typeof advancedCardSettings.threeDS === "string"
|
|
74
|
+
? advancedCardSettings.threeDS
|
|
75
|
+
: "when_required"
|
|
76
|
+
|
|
77
|
+
return res.json({
|
|
78
|
+
environment: creds.environment,
|
|
79
|
+
client_id: creds.client_id,
|
|
80
|
+
currency: compatibility.currency,
|
|
81
|
+
currency_supported: compatibility.supported,
|
|
82
|
+
currency_errors: compatibility.errors,
|
|
83
|
+
supported_currencies: getPayPalSupportedCurrencies(),
|
|
84
|
+
client_token,
|
|
85
|
+
intent: paymentAction,
|
|
86
|
+
paypal_enabled: paypalSettings.enabled ?? true,
|
|
87
|
+
paypal_title: paypalSettings.title || "PayPal",
|
|
88
|
+
card_enabled: cardEnabled,
|
|
89
|
+
card_title: advancedCardSettings.title || "Credit or Debit Card",
|
|
90
|
+
card_three_ds: cardThreeDS,
|
|
91
|
+
button_color: paypalSettings.buttonColor || "gold",
|
|
92
|
+
button_shape: paypalSettings.buttonShape || "rect",
|
|
93
|
+
button_width: paypalSettings.buttonWidth || "responsive",
|
|
94
|
+
button_height: paypalSettings.buttonHeight ?? 45,
|
|
95
|
+
button_label: paypalSettings.buttonLabel || "paypal",
|
|
96
|
+
})
|
|
97
|
+
} catch (e: any) {
|
|
98
|
+
return res.status(500).json({ message: e?.message || "Failed to load PayPal config" })
|
|
99
|
+
}
|
|
100
|
+
}
|