@easypayment/medusa-payment-paypal 0.9.18 → 0.9.20

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.
@@ -8,6 +8,7 @@ import type PayPalModuleService from "../../../../modules/paypal/service"
8
8
  type Body = {
9
9
  email?: string
10
10
  products?: string[]
11
+ environment?: "sandbox" | "live"
11
12
  }
12
13
 
13
14
  export async function POST(req: AuthenticatedMedusaRequest, res: MedusaResponse) {
@@ -19,10 +20,15 @@ export async function POST(req: AuthenticatedMedusaRequest, res: MedusaResponse)
19
20
  ? String(req.auth_context.user_metadata.email)
20
21
  : undefined
21
22
  const email = authEmail ?? body.email ?? "admin@paypal.com"
23
+ const env =
24
+ body.environment === "sandbox" || body.environment === "live"
25
+ ? body.environment
26
+ : undefined
22
27
 
23
28
  const link = await paypal.createOnboardingLink({
24
29
  email,
25
30
  products: body.products,
31
+ env,
26
32
  })
27
33
 
28
34
  return res.json({
@@ -493,10 +493,15 @@ class PayPalModuleService extends MedusaService({
493
493
  return await this.getCurrentRow()
494
494
  }
495
495
 
496
- async createOnboardingLink(input?: { email?: string; products?: string[] }) {
496
+ async createOnboardingLink(input?: { email?: string; products?: string[]; env?: Environment }) {
497
497
  const { onboarding } = await this.ensureSettingsDefaults()
498
498
  const return_url = `${String(onboarding.backend_url || "").replace(/\/$/, "")}/admin/paypal/onboard-complete`
499
- const env = await this.getCurrentEnvironment()
499
+ // Honor an explicit environment from the caller so the generated link can't
500
+ // depend on a racing "set environment" request having landed first.
501
+ const env =
502
+ input?.env === "sandbox" || input?.env === "live"
503
+ ? input.env
504
+ : await this.getCurrentEnvironment()
500
505
  const partner_merchant_id = await this.getPartnerMerchantId(env)
501
506
 
502
507
  const email = (input?.email || "").trim()