@easypayment/medusa-payment-paypal 1.2.2 → 1.2.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 +390 -136
- package/.medusa/server/src/admin/index.mjs +390 -136
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +5 -1
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/environment/route.js +2 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +9 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +9 -4
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +7 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +9 -2
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +10 -3
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/settings/route.js +9 -2
- package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/status/route.js +9 -1
- package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +4 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +5 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +23 -3
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.d.ts +5 -0
- package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.js +12 -5
- package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.js +54 -20
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js +19 -19
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts +1 -0
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/settings/route.js +4 -1
- package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +7 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.js +34 -3
- package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.js +33 -6
- package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.d.ts +4 -0
- package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.js +9 -4
- package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +5 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.js +13 -2
- package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
- package/.medusa/server/src/modules/paypal/index.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/index.js +1 -0
- package/.medusa/server/src/modules/paypal/index.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +22 -22
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +11 -11
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +18 -18
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +16 -16
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +20 -20
- package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +14 -14
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js +15 -15
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js +6 -6
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +4 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js +4 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +14 -6
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +55 -32
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +6 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.js +6 -4
- package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +8 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +39 -12
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +72 -2
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +159 -33
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +5 -2
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.js +15 -5
- package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +3 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +9 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/currencies.js +13 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts +12 -0
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.js +4 -3
- package/.medusa/server/src/modules/paypal/utils/payment-session.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts +11 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +17 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js +6 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js +6 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +43 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.js +57 -5
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
- package/.medusa/server/src/providers/paypal/index.d.ts +1 -0
- package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal/index.js +1 -0
- package/.medusa/server/src/providers/paypal/index.js.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.d.ts +1 -0
- package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.js +1 -0
- package/.medusa/server/src/providers/paypal_card/index.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts +6 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js +9 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts +1 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.js +17 -4
- package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +184 -175
- package/package.json +24 -5
- package/src/admin/index.ts +1 -1
- package/src/admin/routes/settings/paypal/_components/FieldRow.tsx +38 -29
- package/src/admin/routes/settings/paypal/_components/SectionCard.tsx +29 -26
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +49 -48
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +63 -52
- package/src/admin/routes/settings/paypal/_utils/adminFetch.ts +52 -32
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +246 -139
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +208 -123
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/connection/page.tsx +974 -908
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/page.tsx +14 -13
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +304 -273
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +48 -39
- package/src/api/admin/paypal/disconnect/route.ts +15 -14
- package/src/api/admin/paypal/environment/route.ts +34 -32
- package/src/api/admin/paypal/onboard-complete/route.ts +61 -50
- package/src/api/admin/paypal/onboarding-link/route.ts +91 -76
- package/src/api/admin/paypal/onboarding-status/route.ts +21 -20
- package/src/api/admin/paypal/save-credentials/route.ts +48 -37
- package/src/api/admin/paypal/settings/route.ts +63 -45
- package/src/api/admin/paypal/status/route.ts +29 -17
- package/src/api/hooks/paypal/onboard-return/route.ts +15 -15
- package/src/api/hooks/paypal/webhook/route.ts +17 -17
- package/src/api/middlewares.ts +61 -61
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +63 -54
- package/src/api/store/paypal/capture-order/route.ts +416 -370
- package/src/api/store/paypal/config/route.ts +121 -115
- package/src/api/store/paypal/create-order/route.ts +586 -539
- package/src/api/store/paypal/onboard-return/route.ts +116 -113
- package/src/api/store/paypal/settings/route.ts +29 -19
- package/src/api/store/paypal/webhook/route.ts +380 -314
- package/src/api/store/paypal-complete/route.ts +157 -128
- package/src/api/utils/rate-limit.ts +143 -129
- package/src/index.ts +1 -1
- package/src/jobs/paypal-webhook-retry.ts +257 -241
- package/src/modules/paypal/index.ts +9 -8
- package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -33
- package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -22
- package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -29
- package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -27
- package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -31
- package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -25
- package/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.ts +26 -26
- package/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.ts +15 -11
- package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +15 -11
- package/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.ts +15 -11
- package/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.ts +17 -17
- package/src/modules/paypal/migrations/20270202000000_align_nullable_defaults.ts +44 -44
- package/src/modules/paypal/migrations/20270301000000_add_webhook_transmission_id_index.ts +15 -15
- package/src/modules/paypal/models/paypal_connection.ts +28 -23
- package/src/modules/paypal/models/paypal_metric.ts +13 -9
- package/src/modules/paypal/models/paypal_settings.ts +13 -8
- package/src/modules/paypal/models/paypal_webhook_event.ts +26 -19
- package/src/modules/paypal/payment-provider/base-provider.ts +287 -275
- package/src/modules/paypal/payment-provider/card-service.ts +927 -855
- package/src/modules/paypal/payment-provider/index.ts +14 -15
- package/src/modules/paypal/payment-provider/service.ts +906 -836
- package/src/modules/paypal/payment-provider/status-utils.ts +59 -59
- package/src/modules/paypal/payment-provider/webhook-utils.ts +109 -109
- package/src/modules/paypal/service.ts +362 -115
- package/src/modules/paypal/types/config.ts +70 -65
- package/src/modules/paypal/utils/amounts.ts +123 -107
- package/src/modules/paypal/utils/core-workflow.ts +46 -46
- package/src/modules/paypal/utils/credential-resolver.ts +275 -271
- package/src/modules/paypal/utils/currencies.ts +97 -84
- package/src/modules/paypal/utils/partner.ts +8 -8
- package/src/modules/paypal/utils/payment-session.ts +144 -138
- package/src/modules/paypal/utils/paypal-auth.ts +6 -5
- package/src/modules/paypal/utils/paypal-fetch.ts +197 -181
- package/src/modules/paypal/utils/provider-ids.ts +21 -15
- package/src/modules/paypal/utils/secret-crypto.ts +226 -197
- package/src/modules/paypal/utils/webhook-verify.ts +61 -61
- package/src/modules/paypal/webhook-processor.ts +641 -573
- package/src/providers/paypal/index.ts +9 -8
- package/src/providers/paypal_card/index.ts +9 -8
- package/src/subscribers/paypal-order-invoice.ts +180 -173
- package/src/subscribers/paypal-webhook-process.ts +147 -131
- package/tsconfig.json +21 -31
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import { model } from "@medusajs/framework/utils"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { model } from "@medusajs/framework/utils"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Durable record of every verified webhook delivery. `event_id` and
|
|
5
|
+
* `transmission_id` drive deduplication; `status` / `attempt_count` /
|
|
6
|
+
* `next_retry_at` drive the async subscriber and the retry cron
|
|
7
|
+
* (`pending` → `processing` → `processed` | `failed` | `dead_letter` |
|
|
8
|
+
* `ignored`).
|
|
9
|
+
*/
|
|
10
|
+
const PayPalWebhookEvent = model.define("paypal_webhook_event", {
|
|
11
|
+
id: model.id().primaryKey(),
|
|
12
|
+
event_id: model.text().unique(),
|
|
13
|
+
event_type: model.text(),
|
|
14
|
+
event_version: model.text().nullable(),
|
|
15
|
+
transmission_id: model.text().nullable(),
|
|
16
|
+
transmission_time: model.dateTime().nullable(),
|
|
17
|
+
status: model.text().default("pending"),
|
|
18
|
+
attempt_count: model.number().default(0),
|
|
19
|
+
next_retry_at: model.dateTime().nullable(),
|
|
20
|
+
processed_at: model.dateTime().nullable(),
|
|
21
|
+
last_error: model.text().nullable(),
|
|
22
|
+
resource_id: model.text().nullable(),
|
|
23
|
+
payload: model.json().default({}),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export default PayPalWebhookEvent
|
|
@@ -1,275 +1,287 @@
|
|
|
1
|
-
import { AbstractPaymentProvider } from "@medusajs/framework/utils"
|
|
2
|
-
import { randomUUID } from "crypto"
|
|
3
|
-
import type {
|
|
4
|
-
CreateAccountHolderInput,
|
|
5
|
-
CreateAccountHolderOutput,
|
|
6
|
-
DeletePaymentInput,
|
|
7
|
-
DeletePaymentOutput,
|
|
8
|
-
ProviderWebhookPayload,
|
|
9
|
-
WebhookActionResult,
|
|
10
|
-
} from "@medusajs/framework/types"
|
|
11
|
-
import { formatAmountForPayPal, toAmountNumber } from "../utils/amounts"
|
|
12
|
-
import {
|
|
13
|
-
assertPayPalCurrencySupported,
|
|
14
|
-
normalizeCurrencyCode,
|
|
15
|
-
} from "../utils/currencies"
|
|
16
|
-
import { PayPalCredentialResolver } from "../utils/credential-resolver"
|
|
17
|
-
import { PAYPAL_PARTNER_ATTRIBUTION_ID } from "../utils/partner"
|
|
18
|
-
import { paypalFetch } from "../utils/paypal-fetch"
|
|
19
|
-
import { getPayPalWebhookActionAndData } from "./webhook-utils"
|
|
20
|
-
import { mapPayPalCaptureStatus } from "./status-utils"
|
|
21
|
-
|
|
22
|
-
export type Options = {}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Shared base for the two PayPal payment providers (wallet buttons and advanced
|
|
26
|
-
* card fields). Both providers ran nearly identical credential/token handling,
|
|
27
|
-
* order-detail fetching, idempotency-key generation, amount normalization, and
|
|
28
|
-
* PayPal→Medusa status mapping — that logic lives here once. Each provider
|
|
29
|
-
* supplies its own `sessionPrefix` / `idempotencyPrefix` and keeps the pieces
|
|
30
|
-
* that genuinely differ (create/authorize/capture/refund/cancel business logic,
|
|
31
|
-
* metric recording, 3-D Secure handling, provider-id passthrough).
|
|
32
|
-
*/
|
|
33
|
-
export abstract class PayPalProviderBase extends AbstractPaymentProvider<Options> {
|
|
34
|
-
protected readonly options_: Options
|
|
35
|
-
protected paypal: PayPalCredentialResolver
|
|
36
|
-
|
|
37
|
-
/** Prefix for generated session ids (e.g. "pp" or "pp_card"). */
|
|
38
|
-
protected abstract readonly sessionPrefix: string
|
|
39
|
-
/** Prefix for generated idempotency keys (e.g. "pp" or "pp-card"). */
|
|
40
|
-
protected abstract readonly idempotencyPrefix: string
|
|
41
|
-
|
|
42
|
-
constructor(cradle: Record<string, any>, options: Options) {
|
|
43
|
-
super(cradle, options)
|
|
44
|
-
this.options_ = options
|
|
45
|
-
const pg = PayPalProviderBase.resolvePgConnection(cradle)
|
|
46
|
-
this.paypal = new PayPalCredentialResolver(pg)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
protected static resolvePgConnection(cradle: Record<string, any>): any {
|
|
50
|
-
for (const key of ["__pg_connection__", "pgConnection", "pg_connection"]) {
|
|
51
|
-
try {
|
|
52
|
-
const val = cradle[key]
|
|
53
|
-
if (val) return val
|
|
54
|
-
} catch {}
|
|
55
|
-
}
|
|
56
|
-
throw new Error(
|
|
57
|
-
"Could not resolve pgConnection from the payment module container. " +
|
|
58
|
-
"Ensure the paypal module is registered in medusa-config and the database is accessible."
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Serialize an error for audit metadata without losing cause chains. */
|
|
63
|
-
protected serializeError(error: unknown) {
|
|
64
|
-
if (error instanceof Error) {
|
|
65
|
-
const errorWithCause = error as Error & { cause?: unknown }
|
|
66
|
-
const cause = errorWithCause.cause
|
|
67
|
-
return {
|
|
68
|
-
name: error.name,
|
|
69
|
-
message: error.message,
|
|
70
|
-
stack: error.stack,
|
|
71
|
-
cause:
|
|
72
|
-
cause instanceof Error
|
|
73
|
-
? { name: cause.name, message: cause.message, stack: cause.stack }
|
|
74
|
-
: cause,
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return { message: String(error) }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
protected async recordFailure(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
if (["
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
1
|
+
import { AbstractPaymentProvider } from "@medusajs/framework/utils"
|
|
2
|
+
import { randomUUID } from "crypto"
|
|
3
|
+
import type {
|
|
4
|
+
CreateAccountHolderInput,
|
|
5
|
+
CreateAccountHolderOutput,
|
|
6
|
+
DeletePaymentInput,
|
|
7
|
+
DeletePaymentOutput,
|
|
8
|
+
ProviderWebhookPayload,
|
|
9
|
+
WebhookActionResult,
|
|
10
|
+
} from "@medusajs/framework/types"
|
|
11
|
+
import { formatAmountForPayPal, toAmountNumber } from "../utils/amounts"
|
|
12
|
+
import {
|
|
13
|
+
assertPayPalCurrencySupported,
|
|
14
|
+
normalizeCurrencyCode,
|
|
15
|
+
} from "../utils/currencies"
|
|
16
|
+
import { PayPalCredentialResolver } from "../utils/credential-resolver"
|
|
17
|
+
import { PAYPAL_PARTNER_ATTRIBUTION_ID } from "../utils/partner"
|
|
18
|
+
import { paypalFetch } from "../utils/paypal-fetch"
|
|
19
|
+
import { getPayPalWebhookActionAndData } from "./webhook-utils"
|
|
20
|
+
import { mapPayPalCaptureStatus } from "./status-utils"
|
|
21
|
+
|
|
22
|
+
export type Options = {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Shared base for the two PayPal payment providers (wallet buttons and advanced
|
|
26
|
+
* card fields). Both providers ran nearly identical credential/token handling,
|
|
27
|
+
* order-detail fetching, idempotency-key generation, amount normalization, and
|
|
28
|
+
* PayPal→Medusa status mapping — that logic lives here once. Each provider
|
|
29
|
+
* supplies its own `sessionPrefix` / `idempotencyPrefix` and keeps the pieces
|
|
30
|
+
* that genuinely differ (create/authorize/capture/refund/cancel business logic,
|
|
31
|
+
* metric recording, 3-D Secure handling, provider-id passthrough).
|
|
32
|
+
*/
|
|
33
|
+
export abstract class PayPalProviderBase extends AbstractPaymentProvider<Options> {
|
|
34
|
+
protected readonly options_: Options
|
|
35
|
+
protected paypal: PayPalCredentialResolver
|
|
36
|
+
|
|
37
|
+
/** Prefix for generated session ids (e.g. "pp" or "pp_card"). */
|
|
38
|
+
protected abstract readonly sessionPrefix: string
|
|
39
|
+
/** Prefix for generated idempotency keys (e.g. "pp" or "pp-card"). */
|
|
40
|
+
protected abstract readonly idempotencyPrefix: string
|
|
41
|
+
|
|
42
|
+
constructor(cradle: Record<string, any>, options: Options) {
|
|
43
|
+
super(cradle, options)
|
|
44
|
+
this.options_ = options
|
|
45
|
+
const pg = PayPalProviderBase.resolvePgConnection(cradle)
|
|
46
|
+
this.paypal = new PayPalCredentialResolver(pg)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected static resolvePgConnection(cradle: Record<string, any>): any {
|
|
50
|
+
for (const key of ["__pg_connection__", "pgConnection", "pg_connection"]) {
|
|
51
|
+
try {
|
|
52
|
+
const val = cradle[key]
|
|
53
|
+
if (val) return val
|
|
54
|
+
} catch {}
|
|
55
|
+
}
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Could not resolve pgConnection from the payment module container. " +
|
|
58
|
+
"Ensure the paypal module is registered in medusa-config and the database is accessible."
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Serialize an error for audit metadata without losing cause chains. */
|
|
63
|
+
protected serializeError(error: unknown) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
const errorWithCause = error as Error & { cause?: unknown }
|
|
66
|
+
const cause = errorWithCause.cause
|
|
67
|
+
return {
|
|
68
|
+
name: error.name,
|
|
69
|
+
message: error.message,
|
|
70
|
+
stack: error.stack,
|
|
71
|
+
cause:
|
|
72
|
+
cause instanceof Error
|
|
73
|
+
? { name: cause.name, message: cause.message, stack: cause.stack }
|
|
74
|
+
: cause,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { message: String(error) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected async recordFailure(
|
|
81
|
+
eventType: string,
|
|
82
|
+
metadata?: Record<string, unknown>
|
|
83
|
+
) {
|
|
84
|
+
await this.paypal.recordAuditEvent(eventType, metadata)
|
|
85
|
+
await this.paypal.recordMetric(eventType, metadata)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected async recordSuccess(metricName: string) {
|
|
89
|
+
await this.paypal.recordMetric(metricName)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected async recordPaymentEvent(
|
|
93
|
+
eventType: string,
|
|
94
|
+
metadata?: Record<string, unknown>
|
|
95
|
+
) {
|
|
96
|
+
await this.paypal.recordAuditEvent(eventType, metadata)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected generateSessionId(): string {
|
|
100
|
+
try {
|
|
101
|
+
return randomUUID()
|
|
102
|
+
} catch {
|
|
103
|
+
return `${this.sessionPrefix}_${Date.now()}_${Math.random().toString(16).slice(2)}`
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async resolveSettings() {
|
|
108
|
+
return this.paypal.getSettings()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected async resolveCurrencyOverride(): Promise<string> {
|
|
112
|
+
const { apiDetails } = await this.resolveSettings()
|
|
113
|
+
const code = apiDetails.currency_code
|
|
114
|
+
if (typeof code === "string" && code.trim()) {
|
|
115
|
+
return normalizeCurrencyCode(code)
|
|
116
|
+
}
|
|
117
|
+
return normalizeCurrencyCode(process.env.PAYPAL_CURRENCY || "EUR")
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected async getPayPalAccessToken() {
|
|
121
|
+
return this.paypal.getAccessToken()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
protected async getOrderDetails(orderId: string) {
|
|
125
|
+
const { accessToken, base } = await this.getPayPalAccessToken()
|
|
126
|
+
const resp = await paypalFetch(
|
|
127
|
+
`${base}/v2/checkout/orders/${encodeURIComponent(orderId)}`,
|
|
128
|
+
{
|
|
129
|
+
method: "GET",
|
|
130
|
+
headers: {
|
|
131
|
+
Authorization: `Bearer ${accessToken}`,
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
"PayPal-Partner-Attribution-Id": PAYPAL_PARTNER_ATTRIBUTION_ID,
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
const text = await resp.text()
|
|
139
|
+
if (!resp.ok) {
|
|
140
|
+
throw new Error(`PayPal get order error (${resp.status}): ${text}`)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return JSON.parse(text)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
protected getIdempotencyKey(
|
|
147
|
+
input: { context?: { idempotency_key?: string } },
|
|
148
|
+
suffix: string
|
|
149
|
+
): string {
|
|
150
|
+
const key = input?.context?.idempotency_key?.trim()
|
|
151
|
+
if (key) {
|
|
152
|
+
return `${key}-${suffix}`
|
|
153
|
+
}
|
|
154
|
+
return `${this.idempotencyPrefix}-${suffix}-${this.generateSessionId()}`
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected async normalizePaymentData(input: {
|
|
158
|
+
data?: Record<string, unknown>
|
|
159
|
+
}) {
|
|
160
|
+
const data = (input.data || {}) as Record<string, any>
|
|
161
|
+
const amount = toAmountNumber(data.amount)
|
|
162
|
+
const currencyOverride = await this.resolveCurrencyOverride()
|
|
163
|
+
const currencyCode = normalizeCurrencyCode(
|
|
164
|
+
data.currency_code || currencyOverride || "EUR"
|
|
165
|
+
)
|
|
166
|
+
assertPayPalCurrencySupported({
|
|
167
|
+
currencyCode,
|
|
168
|
+
paypalCurrencyOverride: currencyOverride,
|
|
169
|
+
})
|
|
170
|
+
return { data, amount, currencyCode }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
protected formatAmount(amount: number, currencyCode?: string): string {
|
|
174
|
+
return formatAmountForPayPal(amount, currencyCode || "EUR")
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Amount to send to PayPal for a capture. Medusa invokes the provider's
|
|
179
|
+
* capturePayment with only `{ data, context: { idempotency_key } }` — the
|
|
180
|
+
* admin's requested (possibly partial) capture amount is never passed in the
|
|
181
|
+
* input. The idempotency_key IS the Medusa `capture` row id, so resolve the
|
|
182
|
+
* requested amount from that row; otherwise a partial capture would silently
|
|
183
|
+
* charge the buyer the full session total. Falls back to the session amount
|
|
184
|
+
* when the row can't be resolved (preserving full-capture behavior), and
|
|
185
|
+
* never returns more than the session amount.
|
|
186
|
+
*/
|
|
187
|
+
protected async resolveRequestedCaptureAmount(
|
|
188
|
+
input: { context?: { idempotency_key?: string } },
|
|
189
|
+
sessionAmount: number
|
|
190
|
+
): Promise<number> {
|
|
191
|
+
const captureRowId = input?.context?.idempotency_key?.trim()
|
|
192
|
+
if (!captureRowId) return sessionAmount
|
|
193
|
+
const requested = await this.paypal.getRequestedCaptureAmount(captureRowId)
|
|
194
|
+
if (requested === null || !Number.isFinite(requested) || requested <= 0) {
|
|
195
|
+
return sessionAmount
|
|
196
|
+
}
|
|
197
|
+
return Math.min(requested, sessionAmount)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* When the session amount or currency changes while a not-yet-approved PayPal
|
|
202
|
+
* order is stored on the session, drop the stored order reference so the next
|
|
203
|
+
* create-order call mints a fresh order at the correct total. Without this, a
|
|
204
|
+
* buyer who opens PayPal (order created for the old total), backs out, and
|
|
205
|
+
* changes the cart gets charged the stale amount. Returns a `{ paypal }`
|
|
206
|
+
* patch to spread into the updated session data, or `{}` when nothing needs
|
|
207
|
+
* invalidating. Sessions that already carry a capture/authorization are never
|
|
208
|
+
* touched.
|
|
209
|
+
*/
|
|
210
|
+
protected invalidateStaleOrder(
|
|
211
|
+
input: { data?: Record<string, unknown>; amount?: unknown },
|
|
212
|
+
nextCurrencyCode: string
|
|
213
|
+
): Record<string, unknown> {
|
|
214
|
+
const data = (input.data || {}) as Record<string, any>
|
|
215
|
+
const paypal = (data.paypal || {}) as Record<string, any>
|
|
216
|
+
if (!paypal.order_id) return {}
|
|
217
|
+
if (paypal.capture_id || paypal.authorization_id) return {}
|
|
218
|
+
const prevAmount = toAmountNumber(data.amount)
|
|
219
|
+
const nextAmount = toAmountNumber(input.amount)
|
|
220
|
+
const prevCurrency = String(data.currency_code || "").toUpperCase()
|
|
221
|
+
const amountChanged =
|
|
222
|
+
prevAmount > 0 && nextAmount > 0 && prevAmount !== nextAmount
|
|
223
|
+
const currencyChanged = !!prevCurrency && prevCurrency !== nextCurrencyCode
|
|
224
|
+
if (!amountChanged && !currencyChanged) return {}
|
|
225
|
+
const { order_id: _orderId, order: _order, ...rest } = paypal
|
|
226
|
+
return { paypal: rest }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
protected mapCaptureStatus(status?: string) {
|
|
230
|
+
// Delegate to the shared, unit-tested mapping so the card and wallet
|
|
231
|
+
// providers agree with each other and with the webhook processor. Notably a
|
|
232
|
+
// PARTIALLY_REFUNDED capture must stay "captured" (only part of the funds
|
|
233
|
+
// were returned) — mapping it to "canceled" would wrongly unwind a live
|
|
234
|
+
// capture.
|
|
235
|
+
return mapPayPalCaptureStatus(status)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
protected mapAuthorizationStatus(status?: string) {
|
|
239
|
+
const normalized = String(status || "").toUpperCase()
|
|
240
|
+
if (!normalized) return null
|
|
241
|
+
if (["CREATED", "APPROVED", "PENDING"].includes(normalized))
|
|
242
|
+
return "authorized"
|
|
243
|
+
if (["VOIDED", "EXPIRED"].includes(normalized)) return "canceled"
|
|
244
|
+
if (["DENIED", "DECLINED", "FAILED"].includes(normalized)) return "error"
|
|
245
|
+
return null
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
protected mapOrderStatus(status?: string) {
|
|
249
|
+
const normalized = String(status || "").toUpperCase()
|
|
250
|
+
if (!normalized) return "pending"
|
|
251
|
+
if (normalized === "COMPLETED") return "captured"
|
|
252
|
+
if (normalized === "APPROVED") return "authorized"
|
|
253
|
+
if (["VOIDED", "CANCELLED"].includes(normalized)) return "canceled"
|
|
254
|
+
if (["CREATED", "SAVED", "PAYER_ACTION_REQUIRED"].includes(normalized))
|
|
255
|
+
return "pending"
|
|
256
|
+
if (["FAILED", "EXPIRED"].includes(normalized)) return "error"
|
|
257
|
+
return "pending"
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async createAccountHolder(
|
|
261
|
+
input: CreateAccountHolderInput
|
|
262
|
+
): Promise<CreateAccountHolderOutput> {
|
|
263
|
+
const customerId = input.context?.customer?.id
|
|
264
|
+
const externalId = customerId
|
|
265
|
+
? `paypal_${customerId}`
|
|
266
|
+
: `paypal_${this.generateSessionId()}`
|
|
267
|
+
return {
|
|
268
|
+
id: externalId,
|
|
269
|
+
data: {
|
|
270
|
+
email: input.context?.customer?.email || null,
|
|
271
|
+
customer_id: customerId || null,
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async deletePayment(
|
|
277
|
+
_input: DeletePaymentInput
|
|
278
|
+
): Promise<DeletePaymentOutput> {
|
|
279
|
+
return { data: {} }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async getWebhookActionAndData(
|
|
283
|
+
payload: ProviderWebhookPayload["payload"]
|
|
284
|
+
): Promise<WebhookActionResult> {
|
|
285
|
+
return getPayPalWebhookActionAndData(payload)
|
|
286
|
+
}
|
|
287
|
+
}
|