import { PAYPAL_PARTNER_ATTRIBUTION_ID } from "../utils/partner" /** * The seller nonce the hosted partner service (`partnerServiceUrl`) embeds in * every partner-referral it creates. The onboarding token exchange sends it as * the PKCE `code_verifier`, so it MUST equal the value the referral was minted * with — the link request does not send a nonce, so a locally generated one * makes every exchange fail with invalid_grant. It is not a secret: the * single-use authCode and sharedId are what protect the exchange. * Only override PAYPAL_SELLER_NONCE together with your own partner service. */ export const PARTNER_SELLER_NONCE = "a1233wtergfsdt4365tzrshgfbaewa36AGa1233wtergfsdt4365tzrshgfbaewa36AG" /** Partner-level configuration, resolved from env vars with built-in defaults. */ export type PayPalModuleConfig = { partnerServiceUrl: string partnerJsUrl: string backendUrl: string sellerNonce: string bnCode?: string partnerMerchantIdSandbox: string partnerMerchantIdLive: string alertWebhookUrls?: string[] } const STATIC_CFG: PayPalModuleConfig = { partnerServiceUrl: "https://mbjtechnolabs.com/ppcp-seller-onboarding/seller-onboarding.php?from=medusa", partnerJsUrl: "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js", backendUrl: "http://localhost:9000", sellerNonce: PARTNER_SELLER_NONCE, bnCode: PAYPAL_PARTNER_ATTRIBUTION_ID, partnerMerchantIdSandbox: "K6QLN2LPGQRHL", partnerMerchantIdLive: "GT5R877JNBPLL", alertWebhookUrls: [], } /** Resolve the module configuration from the environment. */ export function getPayPalConfig(): PayPalModuleConfig { const backendUrl = process.env.MEDUSA_BACKEND_URL || STATIC_CFG.backendUrl return { ...STATIC_CFG, partnerServiceUrl: process.env.PAYPAL_PARTNER_SERVICE_URL || STATIC_CFG.partnerServiceUrl, backendUrl, sellerNonce: process.env.PAYPAL_SELLER_NONCE || STATIC_CFG.sellerNonce, partnerMerchantIdSandbox: process.env.PAYPAL_PARTNER_MERCHANT_ID_SANDBOX || STATIC_CFG.partnerMerchantIdSandbox, partnerMerchantIdLive: process.env.PAYPAL_PARTNER_MERCHANT_ID_LIVE || STATIC_CFG.partnerMerchantIdLive, alertWebhookUrls: (process.env.PAYPAL_ALERT_WEBHOOK_URLS || "") .split(",") .map((url) => url.trim()) .filter(Boolean) || STATIC_CFG.alertWebhookUrls, } }