@easypayment/medusa-payment-paypal 1.2.3 → 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 +387 -133
- package/.medusa/server/src/admin/index.mjs +387 -133
- 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 +11 -0
- package/README.md +184 -184
- package/package.json +7 -4
- package/src/admin/index.ts +1 -1
- package/src/admin/routes/settings/paypal/_components/FieldRow.tsx +38 -29
- package/src/admin/routes/settings/paypal/_components/SectionCard.tsx +29 -26
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +49 -48
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +63 -52
- package/src/admin/routes/settings/paypal/_utils/adminFetch.ts +52 -32
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +246 -139
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +208 -123
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/connection/page.tsx +974 -908
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/page.tsx +14 -13
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +304 -273
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +48 -39
- package/src/api/admin/paypal/disconnect/route.ts +15 -14
- package/src/api/admin/paypal/environment/route.ts +34 -32
- package/src/api/admin/paypal/onboard-complete/route.ts +61 -50
- package/src/api/admin/paypal/onboarding-link/route.ts +91 -76
- package/src/api/admin/paypal/onboarding-status/route.ts +21 -20
- package/src/api/admin/paypal/save-credentials/route.ts +48 -37
- package/src/api/admin/paypal/settings/route.ts +63 -45
- package/src/api/admin/paypal/status/route.ts +29 -17
- package/src/api/hooks/paypal/onboard-return/route.ts +15 -15
- package/src/api/hooks/paypal/webhook/route.ts +17 -17
- package/src/api/middlewares.ts +61 -61
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +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,241 +1,257 @@
|
|
|
1
|
-
import type { MedusaContainer } from "@medusajs/framework/types"
|
|
2
|
-
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
3
|
-
import type PayPalModuleService from "../modules/paypal/service"
|
|
4
|
-
import {
|
|
5
|
-
computeNextRetryAt,
|
|
6
|
-
isAllowedEventType,
|
|
7
|
-
isRetryableError,
|
|
8
|
-
MAX_WEBHOOK_ATTEMPTS,
|
|
9
|
-
processPayPalWebhookEvent,
|
|
10
|
-
} from "../modules/paypal/webhook-processor"
|
|
11
|
-
|
|
12
|
-
// Bound how many failed events one run drains so the cron can't load an
|
|
13
|
-
// unbounded backlog into memory.
|
|
14
|
-
const RETRY_BATCH_SIZE = 100
|
|
15
|
-
|
|
16
|
-
// Events are persisted as "processing" and handed to the async subscriber. If
|
|
17
|
-
// the subscriber never runs (bus dropped the message, process restarted
|
|
18
|
-
// mid-flight), the event would otherwise sit in "processing" forever. Recover
|
|
19
|
-
// any left in "processing" past this age so async delivery is guaranteed.
|
|
20
|
-
const STALE_PROCESSING_MS = (() => {
|
|
21
|
-
const v = Number(process.env.PAYPAL_WEBHOOK_STALE_PROCESSING_MS)
|
|
22
|
-
return Number.isFinite(v) && v > 0 ? v : 5 * 60 * 1000
|
|
23
|
-
})()
|
|
24
|
-
|
|
25
|
-
// Stable key for the Postgres advisory lock that serializes this cron across
|
|
26
|
-
// instances. pg_try_advisory_xact_lock auto-releases at transaction end, so
|
|
27
|
-
// there is no unlock to pair (and no risk of a leaked lock).
|
|
28
|
-
const RETRY_ADVISORY_LOCK_KEY = 838907812
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
await
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
id: event.id,
|
|
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
|
-
await paypal
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
await paypal
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
1
|
+
import type { MedusaContainer } from "@medusajs/framework/types"
|
|
2
|
+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
3
|
+
import type PayPalModuleService from "../modules/paypal/service"
|
|
4
|
+
import {
|
|
5
|
+
computeNextRetryAt,
|
|
6
|
+
isAllowedEventType,
|
|
7
|
+
isRetryableError,
|
|
8
|
+
MAX_WEBHOOK_ATTEMPTS,
|
|
9
|
+
processPayPalWebhookEvent,
|
|
10
|
+
} from "../modules/paypal/webhook-processor"
|
|
11
|
+
|
|
12
|
+
// Bound how many failed events one run drains so the cron can't load an
|
|
13
|
+
// unbounded backlog into memory.
|
|
14
|
+
const RETRY_BATCH_SIZE = 100
|
|
15
|
+
|
|
16
|
+
// Events are persisted as "processing" and handed to the async subscriber. If
|
|
17
|
+
// the subscriber never runs (bus dropped the message, process restarted
|
|
18
|
+
// mid-flight), the event would otherwise sit in "processing" forever. Recover
|
|
19
|
+
// any left in "processing" past this age so async delivery is guaranteed.
|
|
20
|
+
const STALE_PROCESSING_MS = (() => {
|
|
21
|
+
const v = Number(process.env.PAYPAL_WEBHOOK_STALE_PROCESSING_MS)
|
|
22
|
+
return Number.isFinite(v) && v > 0 ? v : 5 * 60 * 1000
|
|
23
|
+
})()
|
|
24
|
+
|
|
25
|
+
// Stable key for the Postgres advisory lock that serializes this cron across
|
|
26
|
+
// instances. pg_try_advisory_xact_lock auto-releases at transaction end, so
|
|
27
|
+
// there is no unlock to pair (and no risk of a leaked lock).
|
|
28
|
+
const RETRY_ADVISORY_LOCK_KEY = 838907812
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Scheduled job: re-process failed webhook events whose backoff has elapsed
|
|
32
|
+
* and recover events stuck in "processing". Events that exhaust
|
|
33
|
+
* `MAX_WEBHOOK_ATTEMPTS` (or fail non-retryably) are dead-lettered.
|
|
34
|
+
*/
|
|
35
|
+
export default async function paypalWebhookRetry(container: MedusaContainer) {
|
|
36
|
+
// Run the sweep under a Postgres advisory lock so that with multiple server
|
|
37
|
+
// instances running this cron, only one drains the queue per cycle (each
|
|
38
|
+
// event is processed at most once). Falls back to running directly if the
|
|
39
|
+
// raw connection isn't resolvable, so the job degrades gracefully rather
|
|
40
|
+
// than breaking.
|
|
41
|
+
let pg: any = null
|
|
42
|
+
try {
|
|
43
|
+
pg = container.resolve(ContainerRegistrationKeys.PG_CONNECTION)
|
|
44
|
+
} catch {
|
|
45
|
+
pg = null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!pg?.transaction) {
|
|
49
|
+
await runRetrySweep(container)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
await pg.transaction(async (trx: any) => {
|
|
55
|
+
const res = await trx.raw(
|
|
56
|
+
"SELECT pg_try_advisory_xact_lock(?) AS locked",
|
|
57
|
+
[RETRY_ADVISORY_LOCK_KEY]
|
|
58
|
+
)
|
|
59
|
+
const locked = res?.rows?.[0]?.locked ?? res?.[0]?.locked ?? false
|
|
60
|
+
if (!locked) {
|
|
61
|
+
console.info(
|
|
62
|
+
"[PayPal] webhook-retry: another instance holds the lock, skipping"
|
|
63
|
+
)
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
await runRetrySweep(container)
|
|
67
|
+
})
|
|
68
|
+
} catch (e: any) {
|
|
69
|
+
console.warn(
|
|
70
|
+
"[PayPal] webhook-retry: advisory lock path failed, running unlocked:",
|
|
71
|
+
e?.message
|
|
72
|
+
)
|
|
73
|
+
await runRetrySweep(container)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function runRetrySweep(container: MedusaContainer) {
|
|
78
|
+
const paypal = container.resolve<PayPalModuleService>("paypal_onboarding")
|
|
79
|
+
const now = Date.now()
|
|
80
|
+
|
|
81
|
+
// 1. Failed events whose backoff has elapsed.
|
|
82
|
+
const failed = await paypal.listPayPalWebhookEvents(
|
|
83
|
+
{ status: "failed" },
|
|
84
|
+
{ take: RETRY_BATCH_SIZE, order: { next_retry_at: "ASC" } }
|
|
85
|
+
)
|
|
86
|
+
const dueFailed = (failed || []).filter((event: any) => {
|
|
87
|
+
const nextRetryAt = event?.next_retry_at
|
|
88
|
+
? new Date(event.next_retry_at).getTime()
|
|
89
|
+
: null
|
|
90
|
+
return nextRetryAt !== null && nextRetryAt <= now
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
// 2. Events stuck in "processing" past the staleness threshold — the async
|
|
94
|
+
// subscriber never finished them (dropped bus message / restart), so recover.
|
|
95
|
+
const processing = await paypal.listPayPalWebhookEvents(
|
|
96
|
+
{ status: "processing" },
|
|
97
|
+
{ take: RETRY_BATCH_SIZE, order: { updated_at: "ASC" } }
|
|
98
|
+
)
|
|
99
|
+
const staleProcessing = (processing || []).filter((event: any) => {
|
|
100
|
+
const stamp = event?.updated_at || event?.created_at
|
|
101
|
+
const ageMs = stamp ? now - new Date(stamp).getTime() : Infinity
|
|
102
|
+
return ageMs >= STALE_PROCESSING_MS
|
|
103
|
+
})
|
|
104
|
+
if (staleProcessing.length) {
|
|
105
|
+
console.warn(
|
|
106
|
+
`[PayPal] webhook-retry: recovering ${staleProcessing.length} stale "processing" event(s)`
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const candidates = [...dueFailed, ...staleProcessing]
|
|
111
|
+
if (!candidates.length) return
|
|
112
|
+
|
|
113
|
+
console.info(
|
|
114
|
+
`[PayPal] webhook-retry: evaluating ${candidates.length} event(s) (${dueFailed.length} failed, ${staleProcessing.length} stale)`
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
for (const event of candidates) {
|
|
118
|
+
await attemptRetry(paypal, container, event)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function attemptRetry(
|
|
123
|
+
paypal: PayPalModuleService,
|
|
124
|
+
container: MedusaContainer,
|
|
125
|
+
event: any
|
|
126
|
+
) {
|
|
127
|
+
const attemptCount = Number(event.attempt_count || 0)
|
|
128
|
+
|
|
129
|
+
if (attemptCount >= MAX_WEBHOOK_ATTEMPTS) {
|
|
130
|
+
await paypal
|
|
131
|
+
.updateWebhookEventRecord({
|
|
132
|
+
id: event.id,
|
|
133
|
+
status: "dead_letter",
|
|
134
|
+
next_retry_at: null,
|
|
135
|
+
last_error: `Exceeded max attempts (${MAX_WEBHOOK_ATTEMPTS})`,
|
|
136
|
+
})
|
|
137
|
+
.catch(() => {})
|
|
138
|
+
console.warn("[PayPal] webhook-retry: dead-lettered (max attempts)", {
|
|
139
|
+
id: event.id,
|
|
140
|
+
event_type: event.event_type,
|
|
141
|
+
attempts: attemptCount,
|
|
142
|
+
})
|
|
143
|
+
await paypal.recordMetric("webhook_dead_letter").catch(() => {})
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await paypal
|
|
148
|
+
.updateWebhookEventRecord({
|
|
149
|
+
id: event.id,
|
|
150
|
+
status: "processing",
|
|
151
|
+
attempt_count: attemptCount + 1,
|
|
152
|
+
next_retry_at: null,
|
|
153
|
+
last_error: null,
|
|
154
|
+
})
|
|
155
|
+
.catch(() => {})
|
|
156
|
+
|
|
157
|
+
const eventType = String(event.event_type || "")
|
|
158
|
+
|
|
159
|
+
if (!isAllowedEventType(eventType)) {
|
|
160
|
+
await paypal
|
|
161
|
+
.updateWebhookEventRecord({
|
|
162
|
+
id: event.id,
|
|
163
|
+
status: "ignored",
|
|
164
|
+
processed_at: new Date(),
|
|
165
|
+
})
|
|
166
|
+
.catch(() => {})
|
|
167
|
+
console.info("[PayPal] webhook-retry: ignored unsupported event type", {
|
|
168
|
+
id: event.id,
|
|
169
|
+
event_type: eventType,
|
|
170
|
+
})
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
const payload = (event.payload || {}) as Record<string, any>
|
|
176
|
+
const processed = await processPayPalWebhookEvent(container, {
|
|
177
|
+
eventType,
|
|
178
|
+
payload,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
await paypal
|
|
182
|
+
.updateWebhookEventRecord({
|
|
183
|
+
id: event.id,
|
|
184
|
+
status: "processed",
|
|
185
|
+
processed_at: new Date(),
|
|
186
|
+
resource_id:
|
|
187
|
+
processed.refundId ||
|
|
188
|
+
processed.captureId ||
|
|
189
|
+
processed.orderId ||
|
|
190
|
+
null,
|
|
191
|
+
})
|
|
192
|
+
.catch(() => {})
|
|
193
|
+
|
|
194
|
+
console.info("[PayPal] webhook-retry: processed successfully", {
|
|
195
|
+
id: event.id,
|
|
196
|
+
event_type: eventType,
|
|
197
|
+
attempt: attemptCount + 1,
|
|
198
|
+
order_id: processed.orderId,
|
|
199
|
+
capture_id: processed.captureId,
|
|
200
|
+
cart_id: processed.cartId,
|
|
201
|
+
session_updated: processed.sessionUpdated,
|
|
202
|
+
cart_completed: processed.cartCompleted,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
if (processed.cartCompleted) {
|
|
206
|
+
await paypal.recordMetric("webhook_cart_completed").catch(() => {})
|
|
207
|
+
}
|
|
208
|
+
await paypal.recordMetric("webhook_retry_success").catch(() => {})
|
|
209
|
+
} catch (error: any) {
|
|
210
|
+
const retryable = isRetryableError(error)
|
|
211
|
+
const nextAttempt = attemptCount + 1
|
|
212
|
+
|
|
213
|
+
if (!retryable || nextAttempt >= MAX_WEBHOOK_ATTEMPTS) {
|
|
214
|
+
await paypal
|
|
215
|
+
.updateWebhookEventRecord({
|
|
216
|
+
id: event.id,
|
|
217
|
+
status: "dead_letter",
|
|
218
|
+
attempt_count: nextAttempt,
|
|
219
|
+
next_retry_at: null,
|
|
220
|
+
last_error: error?.message || String(error),
|
|
221
|
+
})
|
|
222
|
+
.catch(() => {})
|
|
223
|
+
console.error("[PayPal] webhook-retry: dead-lettered after error", {
|
|
224
|
+
id: event.id,
|
|
225
|
+
event_type: eventType,
|
|
226
|
+
attempt: nextAttempt,
|
|
227
|
+
retryable,
|
|
228
|
+
error: error?.message,
|
|
229
|
+
})
|
|
230
|
+
await paypal.recordMetric("webhook_dead_letter").catch(() => {})
|
|
231
|
+
} else {
|
|
232
|
+
const nextRetry = computeNextRetryAt(nextAttempt)
|
|
233
|
+
await paypal
|
|
234
|
+
.updateWebhookEventRecord({
|
|
235
|
+
id: event.id,
|
|
236
|
+
status: "failed",
|
|
237
|
+
attempt_count: nextAttempt,
|
|
238
|
+
next_retry_at: nextRetry,
|
|
239
|
+
last_error: error?.message || String(error),
|
|
240
|
+
})
|
|
241
|
+
.catch(() => {})
|
|
242
|
+
console.warn("[PayPal] webhook-retry: scheduled retry", {
|
|
243
|
+
id: event.id,
|
|
244
|
+
event_type: eventType,
|
|
245
|
+
attempt: nextAttempt,
|
|
246
|
+
next_retry_at: nextRetry?.toISOString(),
|
|
247
|
+
error: error?.message,
|
|
248
|
+
})
|
|
249
|
+
await paypal.recordMetric("webhook_retry_failed").catch(() => {})
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export const config = {
|
|
255
|
+
name: "paypal-webhook-retry",
|
|
256
|
+
schedule: "*/10 * * * *",
|
|
257
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Module } from "@medusajs/framework/utils"
|
|
2
|
-
import PayPalModuleService from "./service"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Module } from "@medusajs/framework/utils"
|
|
2
|
+
import PayPalModuleService from "./service"
|
|
3
|
+
|
|
4
|
+
/** Container registration key for the module service. */
|
|
5
|
+
export const PAYPAL_MODULE = "paypal_onboarding"
|
|
6
|
+
|
|
7
|
+
export default Module(PAYPAL_MODULE, {
|
|
8
|
+
service: PayPalModuleService,
|
|
9
|
+
})
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Migration } from "@medusajs/framework/mikro-orm/migrations"
|
|
2
|
-
|
|
3
|
-
export class Migration20260115120000 extends Migration {
|
|
4
|
-
async up(): Promise<void> {
|
|
5
|
-
this.addSql(`
|
|
6
|
-
CREATE TABLE IF NOT EXISTS "paypal_connection" (
|
|
7
|
-
"id" text NOT NULL,
|
|
8
|
-
"environment" text NOT NULL DEFAULT 'sandbox',
|
|
9
|
-
"status" text NOT NULL DEFAULT 'disconnected',
|
|
10
|
-
"shared_id" text NULL,
|
|
11
|
-
"auth_code" text NULL,
|
|
12
|
-
"seller_client_id" text NULL,
|
|
13
|
-
"seller_client_secret" text NULL,
|
|
14
|
-
"app_access_token" text NULL,
|
|
15
|
-
"app_access_token_expires_at" timestamptz NULL,
|
|
16
|
-
"metadata" jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
17
|
-
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
18
|
-
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
|
19
|
-
"deleted_at" timestamptz NULL,
|
|
20
|
-
CONSTRAINT "paypal_connection_pkey" PRIMARY KEY ("id")
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
CREATE INDEX IF NOT EXISTS "idx_paypal_connection_deleted_at"
|
|
24
|
-
ON "paypal_connection" ("deleted_at");
|
|
25
|
-
`)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async down(): Promise<void> {
|
|
29
|
-
this.addSql(`
|
|
30
|
-
DROP TABLE IF EXISTS "paypal_connection" CASCADE;
|
|
31
|
-
`)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { Migration } from "@medusajs/framework/mikro-orm/migrations"
|
|
2
|
+
|
|
3
|
+
export class Migration20260115120000 extends Migration {
|
|
4
|
+
async up(): Promise<void> {
|
|
5
|
+
this.addSql(`
|
|
6
|
+
CREATE TABLE IF NOT EXISTS "paypal_connection" (
|
|
7
|
+
"id" text NOT NULL,
|
|
8
|
+
"environment" text NOT NULL DEFAULT 'sandbox',
|
|
9
|
+
"status" text NOT NULL DEFAULT 'disconnected',
|
|
10
|
+
"shared_id" text NULL,
|
|
11
|
+
"auth_code" text NULL,
|
|
12
|
+
"seller_client_id" text NULL,
|
|
13
|
+
"seller_client_secret" text NULL,
|
|
14
|
+
"app_access_token" text NULL,
|
|
15
|
+
"app_access_token_expires_at" timestamptz NULL,
|
|
16
|
+
"metadata" jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
17
|
+
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
18
|
+
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
|
19
|
+
"deleted_at" timestamptz NULL,
|
|
20
|
+
CONSTRAINT "paypal_connection_pkey" PRIMARY KEY ("id")
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
CREATE INDEX IF NOT EXISTS "idx_paypal_connection_deleted_at"
|
|
24
|
+
ON "paypal_connection" ("deleted_at");
|
|
25
|
+
`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async down(): Promise<void> {
|
|
29
|
+
this.addSql(`
|
|
30
|
+
DROP TABLE IF EXISTS "paypal_connection" CASCADE;
|
|
31
|
+
`)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Migration } from "@medusajs/framework/mikro-orm/migrations"
|
|
2
|
-
|
|
3
|
-
export class Migration20260123090000 extends Migration {
|
|
4
|
-
async up(): Promise<void> {
|
|
5
|
-
this.addSql(`
|
|
6
|
-
CREATE TABLE IF NOT EXISTS "paypal_settings" (
|
|
7
|
-
"id" text NOT NULL,
|
|
8
|
-
"data" jsonb NULL,
|
|
9
|
-
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
10
|
-
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
|
11
|
-
"deleted_at" timestamptz NULL,
|
|
12
|
-
CONSTRAINT "paypal_settings_pkey" PRIMARY KEY ("id")
|
|
13
|
-
);
|
|
14
|
-
CREATE INDEX IF NOT EXISTS "idx_paypal_settings_deleted_at"
|
|
15
|
-
ON "paypal_settings" ("deleted_at");
|
|
16
|
-
`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async down(): Promise<void> {
|
|
20
|
-
this.addSql(`DROP TABLE IF EXISTS "paypal_settings" CASCADE;`)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
import { Migration } from "@medusajs/framework/mikro-orm/migrations"
|
|
2
|
+
|
|
3
|
+
export class Migration20260123090000 extends Migration {
|
|
4
|
+
async up(): Promise<void> {
|
|
5
|
+
this.addSql(`
|
|
6
|
+
CREATE TABLE IF NOT EXISTS "paypal_settings" (
|
|
7
|
+
"id" text NOT NULL,
|
|
8
|
+
"data" jsonb NULL,
|
|
9
|
+
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
10
|
+
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
|
11
|
+
"deleted_at" timestamptz NULL,
|
|
12
|
+
CONSTRAINT "paypal_settings_pkey" PRIMARY KEY ("id")
|
|
13
|
+
);
|
|
14
|
+
CREATE INDEX IF NOT EXISTS "idx_paypal_settings_deleted_at"
|
|
15
|
+
ON "paypal_settings" ("deleted_at");
|
|
16
|
+
`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async down(): Promise<void> {
|
|
20
|
+
this.addSql(`DROP TABLE IF EXISTS "paypal_settings" CASCADE;`)
|
|
21
|
+
}
|
|
22
|
+
}
|