axm0121 commited on
Commit
9d67ff3
·
verified ·
1 Parent(s): dae0adf

Add PayPal US-VN-TR three-proxy flow

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. src/index.html +35 -24
  3. src/lib.rs +307 -171
README.md CHANGED
@@ -25,8 +25,8 @@ Configure the following Space Secret before starting the container:
25
  Optional Secrets:
26
 
27
  - `OPENAI_PAY_DEFAULT_PROXY`: retained only for legacy/internal compatibility.
28
- Browser extraction requires the operator to submit both the Checkout and
29
- Promotion Update proxy pools in the page instead of reading this Secret.
30
  - `LINUXDO_CLIENT_ID`, `LINUXDO_CLIENT_SECRET`, and `LINUXDO_REDIRECT_URI`: only
31
  needed when LinuxDo OAuth is enabled.
32
 
@@ -35,6 +35,8 @@ the Hugging Face Space settings and must not be committed to this repository.
35
 
36
  ## Fixed behavior
37
 
 
 
38
  - browser `link_type`: `ideal` or `paypal`
39
  - billing country: `NL`
40
  - currency: `EUR`
@@ -45,7 +47,7 @@ the Hugging Face Space settings and must not be committed to this repository.
45
  - approve attempts: `20`
46
  - approve concurrency: `1`
47
 
48
- PayPal keeps its existing BR → JP → BR proxy-stage routing and Chrome fingerprint, but its billing contract is fixed independently to `US / USD`. Checkout creation, Stripe tax-region update, baseline PayPal PaymentMethod, and inline-confirm PaymentMethod data all use the same US billing address/state.
49
 
50
  ## Run
51
 
@@ -68,10 +70,10 @@ Direct CLI extraction is not available; extraction is intentionally exposed only
68
  - `POST /api/cdk/bind` with `{ "cdk" }` to activate a browser session with a CDK when not logged in, or to bind a pre-provisioned CDK after the active CDK is exhausted and no jobs are pending.
69
  - `POST /api/extract` to enqueue a job:
70
  - iDEAL: `{ "access_token", "link_type": "ideal", "checkout_proxy_pool", "promotion_proxy_pool" }`; both pools are required newline-delimited strings.
71
- - PayPal: `{ "access_token", "link_type": "paypal", "paypal_main_proxy_pool", "paypal_update_proxy_pool" }`; both pools are required newline-delimited strings and the page prompts for United States proxy seeds.
72
  - `GET /api/extract/{job_id}` to poll queued/running/completed status.
73
 
74
- The server binds to the address you pass with `--listen`. Use loopback (`IP_REDACTED` or `localhost`) for local operation; the UI does not print the access token or proxy credentials in the result view. iDEAL browser extraction uses its Checkout pool for the main route and its Promotion pool only for the ChatGPT Promotion Update call. PayPal browser extraction uses its Main pool for Checkout, Stripe Init, PaymentMethod, confirm, approve/poll, and redirect resolution, while its Update pool is isolated to the existing Stripe PayPal tax-region update. Both pool pairs rotate independently per full rebuild attempt. The web API runs extraction through a bounded FIFO queue so concurrent browser submissions do not execute all at once; excess accepted jobs show queued status, and a full queue returns HTTP `429`.
75
 
76
  Extraction requests without an activated CDK/session return HTTP `401`. Activated users with no remaining CDK uses receive HTTP `403`.
77
 
 
25
  Optional Secrets:
26
 
27
  - `OPENAI_PAY_DEFAULT_PROXY`: retained only for legacy/internal compatibility.
28
+ Browser extraction reads its required proxy pools from the page instead of
29
+ this Secret.
30
  - `LINUXDO_CLIENT_ID`, `LINUXDO_CLIENT_SECRET`, and `LINUXDO_REDIRECT_URI`: only
31
  needed when LinuxDo OAuth is enabled.
32
 
 
35
 
36
  ## Fixed behavior
37
 
38
+ For iDEAL:
39
+
40
  - browser `link_type`: `ideal` or `paypal`
41
  - billing country: `NL`
42
  - currency: `EUR`
 
47
  - approve attempts: `20`
48
  - approve concurrency: `1`
49
 
50
+ PayPal uses a Chrome fingerprint with `US / USD` billing and the route `US Checkout → VN Promotion Update → TR Stripe/provider → US approve/poll`. The three submitted pools rotate independently for up to 10 full Checkout rebuilds. Final approve is attempted once per Checkout with concurrency 1. Checkout creation, Stripe tax-region update, baseline PayPal PaymentMethod, and inline-confirm PaymentMethod data all use the same US billing address/state.
51
 
52
  ## Run
53
 
 
70
  - `POST /api/cdk/bind` with `{ "cdk" }` to activate a browser session with a CDK when not logged in, or to bind a pre-provisioned CDK after the active CDK is exhausted and no jobs are pending.
71
  - `POST /api/extract` to enqueue a job:
72
  - iDEAL: `{ "access_token", "link_type": "ideal", "checkout_proxy_pool", "promotion_proxy_pool" }`; both pools are required newline-delimited strings.
73
+ - PayPal: `{ "access_token", "link_type": "paypal", "paypal_checkout_proxy_pool", "paypal_promotion_proxy_pool", "paypal_provider_proxy_pool" }`; all three pools are required newline-delimited strings for US Checkout/Approve, VN Promotion Update, and TR Provider respectively.
74
  - `GET /api/extract/{job_id}` to poll queued/running/completed status.
75
 
76
+ The server binds to the address you pass with `--listen`. Use loopback (`IP_REDACTED` or `localhost`) for local operation; the UI does not print the access token or proxy credentials in the result view. iDEAL browser extraction uses its Checkout pool for the main route and its Promotion pool only for the ChatGPT Promotion Update call. PayPal browser extraction uses the US pool for Checkout plus approve/poll, the VN pool only for ChatGPT Promotion Update, and the TR pool for Stripe Init, tax-region updates, PaymentMethod, confirm, and external PayPal redirect resolution. The three PayPal pools rotate independently per full rebuild attempt. The web API runs extraction through a bounded FIFO queue so concurrent browser submissions do not execute all at once; excess accepted jobs show queued status, and a full queue returns HTTP `429`.
77
 
78
  Extraction requests without an activated CDK/session return HTTP `401`. Activated users with no remaining CDK uses receive HTTP `403`.
79
 
src/index.html CHANGED
@@ -210,14 +210,19 @@
210
 
211
  <div id="paypal-proxy-fields" class="grid hidden">
212
  <div class="field">
213
- <label for="paypal-main-proxy-pool">PayPal Checkout 主代理池(每行一个,请使用美国代理)</label>
214
- <textarea id="paypal-main-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@us-host:port&#10;user:pass@us-host:port"></textarea>
215
- <small>用于 Checkout、Stripe Init、PaymentMethod、confirm、approve、poll 和 PayPal 跳转解析。</small>
216
  </div>
217
  <div class="field">
218
- <label for="paypal-update-proxy-pool">PayPal Update 代理池(每行一个,请使用美国代理)</label>
219
- <textarea id="paypal-update-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@us-host:port&#10;user:pass@us-host:port"></textarea>
220
- <small>只用于现有 Stripe PayPal Tax Region Update,完成后立即切回本轮主代理。</small>
 
 
 
 
 
221
  </div>
222
  </div>
223
 
@@ -254,8 +259,9 @@
254
  const tokenInput = $("access-token");
255
  const checkoutPoolInput = $("checkout-proxy-pool");
256
  const promotionPoolInput = $("promotion-proxy-pool");
257
- const paypalMainPoolInput = $("paypal-main-proxy-pool");
258
- const paypalUpdatePoolInput = $("paypal-update-proxy-pool");
 
259
  const generateButton = $("generate");
260
  const cancelButton = $("cancel");
261
  const modeButtons = Array.from(document.querySelectorAll(".mode-button"));
@@ -277,8 +283,9 @@
277
  tokenInput.disabled = busy;
278
  checkoutPoolInput.disabled = busy;
279
  promotionPoolInput.disabled = busy;
280
- paypalMainPoolInput.disabled = busy;
281
- paypalUpdatePoolInput.disabled = busy;
 
282
  generateButton.disabled = busy;
283
  $("clear").disabled = busy;
284
  $("task-control").classList.toggle("hidden", !busy);
@@ -302,17 +309,17 @@
302
  }
303
  $("page-title").textContent = `${linkLabel()} 链接提取器`;
304
  $("page-description").textContent = isPaypal
305
- ? "调用当前 Rust PayPal 链路;主代理与 Tax Region Update 分别使用两个美国代理池。"
306
  : "固定 NL/EUR/custom/Safari。Checkout 全链路与 Promotion Update 分别使用下方两个代理池。";
307
  $("stat-link").textContent = isPaypal ? "PayPal" : "iDEAL";
308
  $("stat-billing").textContent = isPaypal ? "US / USD" : "NL / EUR";
309
  $("stat-attempts").textContent = isPaypal ? "10 轮" : "5 轮";
310
- $("stat-route").textContent = isPaypal ? "BR → JP → BR" : "代理池依次轮换";
311
- $("stat-proxy").textContent = "双代理池";
312
- $("stat-proxy-note").textContent = isPaypal ? "主链路 / Update 独立轮换" : "输入即用于本轮链路";
313
  generateButton.textContent = `提取 ${linkLabel()} 链`;
314
  $("open-link").textContent = `打开 ${linkLabel()} 链`;
315
- setStatus(isPaypal ? "PayPal 主代理池和 Update 代理池都必须填写。" : "两个代理池都必须填写。");
316
  $("result").classList.remove("show");
317
  renderSteps([]);
318
  }
@@ -428,13 +435,15 @@
428
  const accessToken = tokenInput.value.trim();
429
  const checkoutPool = proxyLines(checkoutPoolInput.value);
430
  const promotionPool = proxyLines(promotionPoolInput.value);
431
- const paypalMainPool = proxyLines(paypalMainPoolInput.value);
432
- const paypalUpdatePool = proxyLines(paypalUpdatePoolInput.value);
 
433
  if (!accessToken) return setStatus("Access Token 不能为空。", "error");
434
  if (currentLinkType === "ideal" && !checkoutPool.length) return setStatus("iDEAL Checkout 主代理池不能为空。", "error");
435
  if (currentLinkType === "ideal" && !promotionPool.length) return setStatus("iDEAL Promotion Update 代理池不能为空。", "error");
436
- if (currentLinkType === "paypal" && !paypalMainPool.length) return setStatus("PayPal Checkout 主代理池不能为空。", "error");
437
- if (currentLinkType === "paypal" && !paypalUpdatePool.length) return setStatus("PayPal Update 代理池不能为空。", "error");
 
438
 
439
  $("result").classList.remove("show");
440
  renderSteps([{ name: "queued", status: "queued", detail: "正在提交任务。" }]);
@@ -449,8 +458,9 @@
449
  link_type: currentLinkType,
450
  checkout_proxy_pool: currentLinkType === "ideal" ? checkoutPool.join("\n") : "",
451
  promotion_proxy_pool: currentLinkType === "ideal" ? promotionPool.join("\n") : "",
452
- paypal_main_proxy_pool: currentLinkType === "paypal" ? paypalMainPool.join("\n") : "",
453
- paypal_update_proxy_pool: currentLinkType === "paypal" ? paypalUpdatePool.join("\n") : "",
 
454
  }),
455
  });
456
  const payload = await readJson(response);
@@ -471,11 +481,12 @@
471
  tokenInput.value = "";
472
  checkoutPoolInput.value = "";
473
  promotionPoolInput.value = "";
474
- paypalMainPoolInput.value = "";
475
- paypalUpdatePoolInput.value = "";
 
476
  $("result").classList.remove("show");
477
  renderSteps([]);
478
- setStatus(currentLinkType === "paypal" ? "PayPal 主代理池和 Update 代理池都必须填写。" : "两个代理池都必须填写。");
479
  });
480
  cancelButton.addEventListener("click", async () => {
481
  if (!activeJobId) return;
 
210
 
211
  <div id="paypal-proxy-fields" class="grid hidden">
212
  <div class="field">
213
+ <label for="paypal-checkout-proxy-pool">PayPal US Checkout / Approve 代理池(每行一个)</label>
214
+ <textarea id="paypal-checkout-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@us-host:port&#10;user:pass@us-host:port"></textarea>
215
+ <small>用于 US Checkout、最终 approve 和 Stripe redirect polling。</small>
216
  </div>
217
  <div class="field">
218
+ <label for="paypal-promotion-proxy-pool">PayPal VN Promotion Update 代理池(每行一个)</label>
219
+ <textarea id="paypal-promotion-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@vn-host:port&#10;user:pass@vn-host:port"></textarea>
220
+ <small>只用于同一个 Checkout 的 VN Promotion Update。</small>
221
+ </div>
222
+ <div class="field">
223
+ <label for="paypal-provider-proxy-pool">PayPal TR Provider 代理池(每行一个)</label>
224
+ <textarea id="paypal-provider-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@tr-host:port&#10;user:pass@tr-host:port"></textarea>
225
+ <small>用于 Stripe Init、税务、PaymentMethod、confirm 和 PayPal 跳转解析。</small>
226
  </div>
227
  </div>
228
 
 
259
  const tokenInput = $("access-token");
260
  const checkoutPoolInput = $("checkout-proxy-pool");
261
  const promotionPoolInput = $("promotion-proxy-pool");
262
+ const paypalCheckoutPoolInput = $("paypal-checkout-proxy-pool");
263
+ const paypalPromotionPoolInput = $("paypal-promotion-proxy-pool");
264
+ const paypalProviderPoolInput = $("paypal-provider-proxy-pool");
265
  const generateButton = $("generate");
266
  const cancelButton = $("cancel");
267
  const modeButtons = Array.from(document.querySelectorAll(".mode-button"));
 
283
  tokenInput.disabled = busy;
284
  checkoutPoolInput.disabled = busy;
285
  promotionPoolInput.disabled = busy;
286
+ paypalCheckoutPoolInput.disabled = busy;
287
+ paypalPromotionPoolInput.disabled = busy;
288
+ paypalProviderPoolInput.disabled = busy;
289
  generateButton.disabled = busy;
290
  $("clear").disabled = busy;
291
  $("task-control").classList.toggle("hidden", !busy);
 
309
  }
310
  $("page-title").textContent = `${linkLabel()} 链接提取器`;
311
  $("page-description").textContent = isPaypal
312
+ ? "固定 US/USD/Chrome;依次使用 US Checkout、VN Promotion、TR Provider、US Approve。"
313
  : "固定 NL/EUR/custom/Safari。Checkout 全链路与 Promotion Update 分别使用下方两个代理池。";
314
  $("stat-link").textContent = isPaypal ? "PayPal" : "iDEAL";
315
  $("stat-billing").textContent = isPaypal ? "US / USD" : "NL / EUR";
316
  $("stat-attempts").textContent = isPaypal ? "10 轮" : "5 轮";
317
+ $("stat-route").textContent = isPaypal ? "US → VN → TR → US" : "代理池依次轮换";
318
+ $("stat-proxy").textContent = isPaypal ? "三代理池" : "双代理池";
319
+ $("stat-proxy-note").textContent = isPaypal ? "US / VN / TR 独立轮换" : "输入即用于本轮链路";
320
  generateButton.textContent = `提取 ${linkLabel()} 链`;
321
  $("open-link").textContent = `打开 ${linkLabel()} 链`;
322
+ setStatus(isPaypal ? "PayPal US、VN、TR 三个代理池都必须填写。" : "两个代理��都必须填写。");
323
  $("result").classList.remove("show");
324
  renderSteps([]);
325
  }
 
435
  const accessToken = tokenInput.value.trim();
436
  const checkoutPool = proxyLines(checkoutPoolInput.value);
437
  const promotionPool = proxyLines(promotionPoolInput.value);
438
+ const paypalCheckoutPool = proxyLines(paypalCheckoutPoolInput.value);
439
+ const paypalPromotionPool = proxyLines(paypalPromotionPoolInput.value);
440
+ const paypalProviderPool = proxyLines(paypalProviderPoolInput.value);
441
  if (!accessToken) return setStatus("Access Token 不能为空。", "error");
442
  if (currentLinkType === "ideal" && !checkoutPool.length) return setStatus("iDEAL Checkout 主代理池不能为空。", "error");
443
  if (currentLinkType === "ideal" && !promotionPool.length) return setStatus("iDEAL Promotion Update 代理池不能为空。", "error");
444
+ if (currentLinkType === "paypal" && !paypalCheckoutPool.length) return setStatus("PayPal US Checkout / Approve 代理池不能为空。", "error");
445
+ if (currentLinkType === "paypal" && !paypalPromotionPool.length) return setStatus("PayPal VN Promotion Update 代理池不能为空。", "error");
446
+ if (currentLinkType === "paypal" && !paypalProviderPool.length) return setStatus("PayPal TR Provider 代理池不能为空。", "error");
447
 
448
  $("result").classList.remove("show");
449
  renderSteps([{ name: "queued", status: "queued", detail: "正在提交任务。" }]);
 
458
  link_type: currentLinkType,
459
  checkout_proxy_pool: currentLinkType === "ideal" ? checkoutPool.join("\n") : "",
460
  promotion_proxy_pool: currentLinkType === "ideal" ? promotionPool.join("\n") : "",
461
+ paypal_checkout_proxy_pool: currentLinkType === "paypal" ? paypalCheckoutPool.join("\n") : "",
462
+ paypal_promotion_proxy_pool: currentLinkType === "paypal" ? paypalPromotionPool.join("\n") : "",
463
+ paypal_provider_proxy_pool: currentLinkType === "paypal" ? paypalProviderPool.join("\n") : "",
464
  }),
465
  });
466
  const payload = await readJson(response);
 
481
  tokenInput.value = "";
482
  checkoutPoolInput.value = "";
483
  promotionPoolInput.value = "";
484
+ paypalCheckoutPoolInput.value = "";
485
+ paypalPromotionPoolInput.value = "";
486
+ paypalProviderPoolInput.value = "";
487
  $("result").classList.remove("show");
488
  renderSteps([]);
489
+ setStatus(currentLinkType === "paypal" ? "PayPal US、VN、TR 三个代理池都必须填写。" : "两个代理池都必须填写。");
490
  });
491
  cancelButton.addEventListener("click", async () => {
492
  if (!activeJobId) return;
src/lib.rs CHANGED
@@ -59,12 +59,14 @@ const PAYPAL_ACCEPT_LANGUAGE: &str = "pt-BR,pt;q=0.9,en;q=0.8";
59
  const PAYPAL_BROWSER_LOCALE: &str = "pt-BR";
60
  const PAYPAL_ELEMENTS_LOCALE: &str = "pt-BR";
61
  const PAYPAL_BROWSER_TIMEZONE: &str = "America/Sao_Paulo";
62
- const PAYPAL_CHECKOUT_REGION: &str = "BR";
63
- const PAYPAL_PROVIDER_REGION: &str = "JP";
64
- const PAYPAL_APPROVE_REGION: &str = "BR";
 
65
  const PAYPAL_BILLING_COUNTRY: &str = "US";
66
  const PAYPAL_BILLING_STATE: &str = "CA";
67
  const MAX_APPROVE_ATTEMPTS: usize = 20;
 
68
  const APPROVE_CONCURRENCY: usize = 1;
69
  const MAX_REBUILD_ATTEMPTS: usize = 5;
70
  const PAYPAL_PROVIDER_MAX_ATTEMPTS: usize = 10;
@@ -144,6 +146,7 @@ pub struct ExtractInput {
144
  pub proxy: String,
145
  pub checkout_proxy_pool: Vec<String>,
146
  pub promotion_proxy_pool: Vec<String>,
 
147
  pub base_url: String,
148
  pub link_type: String,
149
  }
@@ -158,9 +161,11 @@ pub struct ExtractApiInput {
158
  #[serde(default)]
159
  pub promotion_proxy_pool: String,
160
  #[serde(default)]
161
- pub paypal_main_proxy_pool: String,
162
  #[serde(default)]
163
- pub paypal_update_proxy_pool: String,
 
 
164
  }
165
 
166
  #[derive(Debug, Clone, Serialize, PartialEq, Eq)]
@@ -1665,14 +1670,18 @@ pub enum ExtractError {
1665
  InvalidCheckoutProxy(usize),
1666
  #[error("iDEAL Promotion Update 代理池第 {0} 行格式无效。")]
1667
  InvalidPromotionProxy(usize),
1668
- #[error("PayPal Checkout 主代理池不能为空。")]
1669
- MissingPaypalMainProxyPool,
1670
- #[error("PayPal Update 代理池不能为空。")]
1671
- MissingPaypalUpdateProxyPool,
1672
- #[error("PayPal Checkout 主代理池第 {0} 行格式无效。")]
1673
- InvalidPaypalMainProxy(usize),
1674
- #[error("PayPal Update 代理池第 {0} 行格式无效。")]
1675
- InvalidPaypalUpdateProxy(usize),
 
 
 
 
1676
  #[error("任务已中断。")]
1677
  Canceled,
1678
  #[error("non-default --base-url must be localhost or loopback: {0}")]
@@ -2071,28 +2080,39 @@ fn extract_input_for_api(input: ExtractApiInput) -> Result<ExtractInput, Extract
2071
  proxy: checkout_proxy_pool[0].clone(),
2072
  checkout_proxy_pool,
2073
  promotion_proxy_pool,
 
2074
  base_url: String::new(),
2075
  link_type: "ideal".to_string(),
2076
  })
2077
  }
2078
  "paypal" => {
2079
- let paypal_main_proxy_pool =
2080
- parse_proxy_pool(&input.paypal_main_proxy_pool, ProxyPoolKind::PaypalMain)?;
2081
- if paypal_main_proxy_pool.is_empty() {
2082
- return Err(ExtractError::MissingPaypalMainProxyPool);
 
 
 
 
 
 
 
 
 
2083
  }
2084
- let paypal_update_proxy_pool = parse_proxy_pool(
2085
- &input.paypal_update_proxy_pool,
2086
- ProxyPoolKind::PaypalUpdate,
2087
  )?;
2088
- if paypal_update_proxy_pool.is_empty() {
2089
- return Err(ExtractError::MissingPaypalUpdateProxyPool);
2090
  }
2091
  Ok(ExtractInput {
2092
  access_token: input.access_token,
2093
- proxy: paypal_main_proxy_pool[0].clone(),
2094
- checkout_proxy_pool: paypal_main_proxy_pool,
2095
- promotion_proxy_pool: paypal_update_proxy_pool,
 
2096
  base_url: String::new(),
2097
  link_type: "paypal".to_string(),
2098
  })
@@ -2107,8 +2127,9 @@ fn extract_input_for_api(input: ExtractApiInput) -> Result<ExtractInput, Extract
2107
  enum ProxyPoolKind {
2108
  Checkout,
2109
  Promotion,
2110
- PaypalMain,
2111
- PaypalUpdate,
 
2112
  }
2113
 
2114
  fn parse_proxy_pool(text: &str, kind: ProxyPoolKind) -> Result<Vec<String>, ExtractError> {
@@ -2122,11 +2143,14 @@ fn parse_proxy_pool(text: &str, kind: ProxyPoolKind) -> Result<Vec<String>, Extr
2122
  return Err(match kind {
2123
  ProxyPoolKind::Checkout => ExtractError::InvalidCheckoutProxy(line_index + 1),
2124
  ProxyPoolKind::Promotion => ExtractError::InvalidPromotionProxy(line_index + 1),
2125
- ProxyPoolKind::PaypalMain => {
2126
- ExtractError::InvalidPaypalMainProxy(line_index + 1)
 
 
 
2127
  }
2128
- ProxyPoolKind::PaypalUpdate => {
2129
- ExtractError::InvalidPaypalUpdateProxy(line_index + 1)
2130
  }
2131
  });
2132
  }
@@ -2274,10 +2298,10 @@ const fn paypal_config() -> LockedConfig {
2274
  client_fingerprint: "chrome",
2275
  user_agent: PAYPAL_USER_AGENT,
2276
  checkout_proxy_region: PAYPAL_CHECKOUT_REGION,
2277
- promotion_proxy_region: None,
2278
  provider_proxy_region: PAYPAL_PROVIDER_REGION,
2279
  approve_proxy_region: PAYPAL_APPROVE_REGION,
2280
- approve_max_attempts: MAX_APPROVE_ATTEMPTS,
2281
  approve_concurrency: APPROVE_CONCURRENCY,
2282
  }
2283
  }
@@ -2947,7 +2971,7 @@ async fn extract_paypal_link_with_progress<T: Transport>(
2947
  let base = EndpointBase::new(&input.base_url)?;
2948
  if input.proxy.trim().is_empty() {
2949
  return Err(ExtractError::BadResponse(
2950
- "proxy is required for strict BR-JP-BR PayPal extraction with US billing address"
2951
  .to_string(),
2952
  ));
2953
  }
@@ -2956,21 +2980,21 @@ async fn extract_paypal_link_with_progress<T: Transport>(
2956
  &mut steps,
2957
  "locked config",
2958
  "ok",
2959
- "paypal US billing address / USD Chrome checkout BR provider JP approve BR attempts=10 approve_attempts=20",
2960
  progress,
2961
  );
2962
 
2963
  let mut last_error = None;
2964
  let mut last_fallback = None;
2965
  for attempt in 1..=PAYPAL_PROVIDER_MAX_ATTEMPTS {
2966
- let (main_proxy, update_proxy, main_index, update_index) =
2967
  paypal_proxies_for_attempt(&input, attempt)?;
2968
  if attempt > 1 {
2969
  add_step_with_progress(
2970
  &mut steps,
2971
  "rebuild checkout",
2972
  "info",
2973
- &format!("attempt {attempt}/{PAYPAL_PROVIDER_MAX_ATTEMPTS}; main pool #{main_index}; update pool #{update_index}; proxy chain {PAYPAL_CHECKOUT_REGION}->{PAYPAL_PROVIDER_REGION}->{PAYPAL_APPROVE_REGION} retry"),
2974
  progress,
2975
  );
2976
  }
@@ -2978,8 +3002,9 @@ async fn extract_paypal_link_with_progress<T: Transport>(
2978
  transport,
2979
  &base,
2980
  &token,
2981
- &main_proxy,
2982
- &update_proxy,
 
2983
  attempt,
2984
  &mut steps,
2985
  progress,
@@ -3047,56 +3072,74 @@ async fn extract_paypal_link_with_progress<T: Transport>(
3047
  fn paypal_proxies_for_attempt(
3048
  input: &ExtractInput,
3049
  attempt: usize,
3050
- ) -> Result<(String, String, usize, usize), ExtractError> {
3051
- if !input.checkout_proxy_pool.is_empty() || !input.promotion_proxy_pool.is_empty() {
 
 
 
3052
  if input.checkout_proxy_pool.is_empty() {
3053
- return Err(ExtractError::MissingPaypalMainProxyPool);
3054
  }
3055
  if input.promotion_proxy_pool.is_empty() {
3056
- return Err(ExtractError::MissingPaypalUpdateProxyPool);
3057
  }
3058
- let main_index = (attempt.saturating_sub(1)) % input.checkout_proxy_pool.len();
3059
- let update_index = (attempt.saturating_sub(1)) % input.promotion_proxy_pool.len();
 
 
 
 
 
3060
  return Ok((
3061
- input.checkout_proxy_pool[main_index].clone(),
3062
- input.promotion_proxy_pool[update_index].clone(),
3063
- main_index + 1,
3064
- update_index + 1,
 
 
3065
  ));
3066
  }
3067
 
3068
  if input.proxy.trim().is_empty() {
3069
  return Err(ExtractError::BadResponse(
3070
- "proxy is required for strict BR-JP-BR PayPal extraction with US billing address"
3071
  .to_string(),
3072
  ));
3073
  }
3074
- Ok((input.proxy.clone(), input.proxy.clone(), 1, 1))
 
 
 
 
 
 
 
3075
  }
3076
 
3077
  async fn run_paypal_attempt<T: Transport>(
3078
  transport: &mut T,
3079
  base: &EndpointBase,
3080
  token: &str,
3081
- main_proxy: &str,
3082
- update_proxy: &str,
 
3083
  attempt: usize,
3084
  steps: &mut Vec<Step>,
3085
  progress: Option<&ProgressSink>,
3086
  ) -> Result<ExtractOutput, ExtractError> {
3087
- let attempt_main_proxy = proxy_seed_for_attempt(main_proxy, attempt);
3088
- let attempt_update_proxy = proxy_seed_for_attempt(update_proxy, attempt);
3089
- let checkout_proxy = proxy_for_region(&attempt_main_proxy, PAYPAL_CHECKOUT_REGION);
3090
- let provider_proxy = proxy_for_region(&attempt_main_proxy, PAYPAL_PROVIDER_REGION);
3091
- let update_provider_proxy =
3092
- proxy_for_region(&attempt_update_proxy, PAYPAL_PROVIDER_REGION);
3093
  let approve_proxy =
3094
- proxy_with_fresh_sid(&proxy_for_region(&attempt_main_proxy, PAYPAL_APPROVE_REGION));
3095
  add_step_with_progress(
3096
  steps,
3097
  "proxy chain",
3098
  "ok",
3099
- &format!("attempt {attempt}/{PAYPAL_PROVIDER_MAX_ATTEMPTS}; checkout={PAYPAL_CHECKOUT_REGION}; provider={PAYPAL_PROVIDER_REGION}; approve={PAYPAL_APPROVE_REGION}"),
3100
  progress,
3101
  );
3102
 
@@ -3112,6 +3155,22 @@ async fn run_paypal_attempt<T: Transport>(
3112
  .await?;
3113
  add_step_with_progress(steps, "checkout", "ok", &checkout.cs_id, progress);
3114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3115
  let stripe_pk = if checkout.publishable_key.is_empty() {
3116
  DEFAULT_STRIPE_PK.to_string()
3117
  } else {
@@ -3128,7 +3187,7 @@ async fn run_paypal_attempt<T: Transport>(
3128
  .await?;
3129
  add_step_with_progress(
3130
  steps,
3131
- "stripe init",
3132
  "ok",
3133
  &init.stripe_hosted_url,
3134
  progress,
@@ -3154,7 +3213,7 @@ async fn run_paypal_attempt<T: Transport>(
3154
  base,
3155
  &checkout.cs_id,
3156
  &stripe_pk,
3157
- &update_provider_proxy,
3158
  paypal_billing_country,
3159
  )
3160
  .await
@@ -4448,7 +4507,10 @@ async fn approve_with_retries<T: Transport>(
4448
  steps,
4449
  "approve retry policy",
4450
  "ok",
4451
- "total_attempts=20; concurrency=1",
 
 
 
4452
  progress,
4453
  );
4454
  let header_token = access_token_from_headers(headers);
@@ -4477,7 +4539,7 @@ async fn approve_with_retries<T: Transport>(
4477
  let approve_headers =
4478
  target_headers(headers, "/backend-api/payments/checkout/approve", &referer);
4479
  let mut last_error = None;
4480
- for attempt in 1..=MAX_APPROVE_ATTEMPTS {
4481
  let current_approve_proxy = if attempt == 1 {
4482
  base_approve_proxy.clone()
4483
  } else {
@@ -4489,7 +4551,8 @@ async fn approve_with_retries<T: Transport>(
4489
  "approve retry",
4490
  "info",
4491
  &format!(
4492
- "attempt {attempt}/{MAX_APPROVE_ATTEMPTS}; approve={}; retry proxy",
 
4493
  config.approve_proxy_region
4494
  ),
4495
  progress,
@@ -5759,6 +5822,7 @@ mod tests {
5759
  proxy: "http://user-region-US-sid-old-t-1:pass@proxy.example:3010".to_string(),
5760
  checkout_proxy_pool: Vec::new(),
5761
  promotion_proxy_pool: Vec::new(),
 
5762
  base_url: "http://IP_REDACTED:8792".to_string(),
5763
  link_type: "ideal".to_string(),
5764
  },
@@ -5860,6 +5924,7 @@ mod tests {
5860
  proxy: checkout_proxy.to_string(),
5861
  checkout_proxy_pool: vec![checkout_proxy.to_string()],
5862
  promotion_proxy_pool: vec![promotion_proxy.to_string()],
 
5863
  base_url: "http://IP_REDACTED:8792".to_string(),
5864
  link_type: "ideal".to_string(),
5865
  },
@@ -5897,6 +5962,7 @@ mod tests {
5897
  "http://promotion-two.example:3020".to_string(),
5898
  "http://promotion-three.example:3020".to_string(),
5899
  ],
 
5900
  base_url: String::new(),
5901
  link_type: "ideal".to_string(),
5902
  };
@@ -5912,29 +5978,36 @@ mod tests {
5912
  fn submitted_paypal_pools_rotate_independently_by_rebuild_attempt() {
5913
  let input = ExtractInput {
5914
  access_token: "at_test".to_string(),
5915
- proxy: "http://main-one.example:3010".to_string(),
5916
  checkout_proxy_pool: vec![
5917
- "http://main-one.example:3010".to_string(),
5918
- "http://main-two.example:3010".to_string(),
5919
  ],
5920
  promotion_proxy_pool: vec![
5921
- "http://update-one.example:3020".to_string(),
5922
- "http://update-two.example:3020".to_string(),
5923
- "http://update-three.example:3020".to_string(),
 
 
 
 
 
 
5924
  ],
5925
  base_url: String::new(),
5926
  link_type: "paypal".to_string(),
5927
  };
5928
 
5929
  let attempt_four = paypal_proxies_for_attempt(&input, 4)
5930
- .expect("both submitted PayPal pools should be selectable");
5931
- assert_eq!(attempt_four.0, "http://main-two.example:3010");
5932
- assert_eq!(attempt_four.1, "http://update-one.example:3020");
5933
- assert_eq!((attempt_four.2, attempt_four.3), (2, 1));
 
5934
  }
5935
 
5936
  #[tokio::test]
5937
- async fn submitted_paypal_update_pool_is_isolated_to_tax_region_update() {
5938
  #[derive(Default)]
5939
  struct PaypalTransport {
5940
  requests: Vec<HttpRequest>,
@@ -5957,6 +6030,9 @@ mod tests {
5957
  "processor_entity": "openai_ie",
5958
  "publishable_key": "pk_REDACTED"
5959
  }),
 
 
 
5960
  "/v1/payment_pages/cs_paypal_pool_test/init" => serde_json::json!({
5961
  "stripe_hosted_url": "https://checkout.stripe.com/c/pay/cs_paypal_pool_test",
5962
  "init_checksum": "checksum_paypal_pool_test",
@@ -6008,12 +6084,12 @@ mod tests {
6008
  }
6009
  }
6010
 
6011
- let main_proxy =
6012
- "http://main-user-region-US-sid-main-t-1:pass@main.example:3010";
6013
- let update_proxy =
6014
- "http://update-user-region-US-sid-update-t-1:pass@update.example:3020";
6015
- let expected_update_proxy =
6016
- "http://update-user-region-JP-sid-update-t-1:pass@update.example:3020";
6017
  let mut transport = PaypalTransport::default();
6018
  let output = extract_paypal_link_with_progress(
6019
  &mut transport,
@@ -6021,9 +6097,10 @@ mod tests {
6021
  access_token:
6022
  "eyJhbGciOiJub25lIn0.eyJlbWFpbCI6InBheXBhbC1wb29sQGV4YW1wbGUuY29tIn0.sig"
6023
  .to_string(),
6024
- proxy: main_proxy.to_string(),
6025
- checkout_proxy_pool: vec![main_proxy.to_string()],
6026
- promotion_proxy_pool: vec![update_proxy.to_string()],
 
6027
  base_url: "http://localhost:8792".to_string(),
6028
  link_type: "paypal".to_string(),
6029
  },
@@ -6057,33 +6134,32 @@ mod tests {
6057
  if form.get("billing_details[address][country]").map(String::as_str) == Some("US")
6058
  && form.get("billing_details[address][state]").map(String::as_str) == Some("CA")));
6059
 
6060
- let mut update_requests = 0;
6061
  for request in &transport.requests {
6062
- let is_tax_update = request.method == "POST"
6063
- && request
6064
- .url
6065
- .ends_with("/v1/payment_pages/cs_paypal_pool_test")
6066
- && matches!(&request.body, RequestBody::Form(form) if form.contains_key("tax_region[country]"));
6067
- if is_tax_update {
6068
- update_requests += 1;
6069
- assert_eq!(request.proxy_url, expected_update_proxy);
6070
- assert!(matches!(&request.body, RequestBody::Form(form)
6071
- if form.get("tax_region[country]").map(String::as_str) == Some("US")
6072
- && form.get("tax_region[state]").map(String::as_str).is_none_or(|state| state == "CA")));
 
 
 
6073
  } else {
6074
- assert_ne!(
6075
- request.proxy_url, expected_update_proxy,
6076
- "non-update PayPal request unexpectedly used the Update pool: {}",
6077
- request.url
6078
- );
6079
  assert!(
6080
- request.proxy_url.contains("main.example:3010"),
6081
- "non-update PayPal request must use a Main-derived route: {}",
6082
  request.url
6083
  );
 
6084
  }
6085
  }
6086
- assert_eq!(update_requests, 2);
6087
  }
6088
 
6089
  #[test]
@@ -6191,6 +6267,7 @@ mod tests {
6191
  proxy: "http://user-region-US-sid-old-t-1:pass@proxy.example:3010".to_string(),
6192
  checkout_proxy_pool: Vec::new(),
6193
  promotion_proxy_pool: Vec::new(),
 
6194
  base_url: "http://IP_REDACTED:8792".to_string(),
6195
  link_type: "ideal".to_string(),
6196
  },
@@ -6214,6 +6291,7 @@ mod tests {
6214
  proxy: String::new(),
6215
  checkout_proxy_pool: Vec::new(),
6216
  promotion_proxy_pool: Vec::new(),
 
6217
  base_url: "http://IP_REDACTED:8792".to_string(),
6218
  link_type: "ideal".to_string(),
6219
  },
@@ -6238,6 +6316,7 @@ mod tests {
6238
  proxy: String::new(),
6239
  checkout_proxy_pool: Vec::new(),
6240
  promotion_proxy_pool: Vec::new(),
 
6241
  base_url: "https://collector.example.test".to_string(),
6242
  link_type: "ideal".to_string(),
6243
  },
@@ -6269,6 +6348,7 @@ mod tests {
6269
  proxy: String::new(),
6270
  checkout_proxy_pool: Vec::new(),
6271
  promotion_proxy_pool: Vec::new(),
 
6272
  base_url: base_url.to_string(),
6273
  link_type: "ideal".to_string(),
6274
  },
@@ -6369,16 +6449,19 @@ mod tests {
6369
  assert!(html.contains("id=\"access-token\""));
6370
  assert!(html.contains("id=\"checkout-proxy-pool\""));
6371
  assert!(html.contains("id=\"promotion-proxy-pool\""));
6372
- assert!(html.contains("id=\"paypal-main-proxy-pool\""));
6373
- assert!(html.contains("id=\"paypal-update-proxy-pool\""));
 
6374
  assert!(html.contains("iDEAL Checkout 主代理池(每行一个)"));
6375
  assert!(html.contains("iDEAL Promotion Update 代理池(每行一个)"));
6376
- assert!(html.contains("PayPal Checkout 主代理池(每行一个,请使用美国代理)"));
6377
- assert!(html.contains("PayPal Update 代理池(每行一个,请使用美国代理)"));
 
6378
  assert!(html.contains("checkout_proxy_pool"));
6379
  assert!(html.contains("promotion_proxy_pool"));
6380
- assert!(html.contains("paypal_main_proxy_pool"));
6381
- assert!(html.contains("paypal_update_proxy_pool"));
 
6382
  assert!(!html.contains("paypal_proxy"));
6383
  assert!(html.contains("data-link-type=\"ideal\""));
6384
  assert!(html.contains("data-link-type=\"paypal\""));
@@ -6388,8 +6471,6 @@ mod tests {
6388
  assert!(html.contains("id=\"long-url\""));
6389
  assert!(html.contains("overflow-wrap: anywhere"));
6390
  assert!(html.contains("/cancel"));
6391
- assert!(!html.contains("id=\"provider-proxy"));
6392
- assert!(!html.contains("providerProxy"));
6393
  assert!(html.contains("link_type: currentLinkType"));
6394
  assert!(!html.contains("localStorage"));
6395
  assert!(!html.contains("UPI"));
@@ -6417,8 +6498,9 @@ mod tests {
6417
  link_type: None,
6418
  checkout_proxy_pool: "checkout.example:3010\ncheckout.example:3010".to_string(),
6419
  promotion_proxy_pool: "http://promotion.example:3010".to_string(),
6420
- paypal_main_proxy_pool: String::new(),
6421
- paypal_update_proxy_pool: String::new(),
 
6422
  })
6423
  .expect("both submitted pools should be accepted");
6424
 
@@ -6431,89 +6513,130 @@ mod tests {
6431
  }
6432
 
6433
  #[test]
6434
- fn api_input_exposes_paypal_main_and_update_proxy_pools() {
6435
  let input = extract_input_for_api(ExtractApiInput {
6436
  access_token: "at_test".to_string(),
6437
  link_type: Some("paypal".to_string()),
6438
  checkout_proxy_pool: String::new(),
6439
  promotion_proxy_pool: String::new(),
6440
- paypal_main_proxy_pool:
6441
- "main-one.example:3010\nmain-one.example:3010\nmain-two.example:3010"
6442
  .to_string(),
6443
- paypal_update_proxy_pool: "update.example:3010".to_string(),
 
6444
  })
6445
  .expect("valid PayPal pools should be accepted");
6446
 
6447
- assert_eq!(input.proxy, "http://main-one.example:3010");
6448
  assert_eq!(
6449
  input.checkout_proxy_pool,
6450
  vec![
6451
- "http://main-one.example:3010",
6452
- "http://main-two.example:3010"
6453
  ]
6454
  );
6455
  assert_eq!(
6456
  input.promotion_proxy_pool,
6457
- vec!["http://update.example:3010"]
 
 
 
 
6458
  );
6459
  assert_eq!(input.link_type, "paypal");
6460
  }
6461
 
6462
  #[test]
6463
  fn api_input_rejects_missing_invalid_paypal_pools_and_unknown_link_type() {
6464
- let missing_main = extract_input_for_api(ExtractApiInput {
6465
  access_token: "at_test".to_string(),
6466
  link_type: Some("paypal".to_string()),
6467
  checkout_proxy_pool: String::new(),
6468
  promotion_proxy_pool: String::new(),
6469
- paypal_main_proxy_pool: String::new(),
6470
- paypal_update_proxy_pool: "update.example:3010".to_string(),
 
6471
  });
6472
  assert!(matches!(
6473
- missing_main,
6474
- Err(ExtractError::MissingPaypalMainProxyPool)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6475
  ));
6476
 
6477
- let missing_update = extract_input_for_api(ExtractApiInput {
6478
  access_token: "at_test".to_string(),
6479
  link_type: Some("paypal".to_string()),
6480
  checkout_proxy_pool: String::new(),
6481
  promotion_proxy_pool: String::new(),
6482
- paypal_main_proxy_pool: "main.example:3010".to_string(),
6483
- paypal_update_proxy_pool: String::new(),
 
6484
  });
6485
  assert!(matches!(
6486
- missing_update,
6487
- Err(ExtractError::MissingPaypalUpdateProxyPool)
6488
  ));
6489
 
6490
- let invalid_main = extract_input_for_api(ExtractApiInput {
6491
  access_token: "at_test".to_string(),
6492
  link_type: Some("paypal".to_string()),
6493
  checkout_proxy_pool: String::new(),
6494
  promotion_proxy_pool: String::new(),
6495
- paypal_main_proxy_pool: "secret-user:secret-pass@bad host:3010".to_string(),
6496
- paypal_update_proxy_pool: "update.example:3010".to_string(),
 
6497
  });
6498
  assert!(matches!(
6499
- &invalid_main,
6500
- Err(ExtractError::InvalidPaypalMainProxy(1))
6501
  ));
6502
- assert!(!invalid_main.unwrap_err().to_string().contains("secret-user"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6503
 
6504
- let invalid_update = extract_input_for_api(ExtractApiInput {
6505
  access_token: "at_test".to_string(),
6506
  link_type: Some("paypal".to_string()),
6507
  checkout_proxy_pool: String::new(),
6508
  promotion_proxy_pool: String::new(),
6509
- paypal_main_proxy_pool: "main.example:3010".to_string(),
6510
- paypal_update_proxy_pool: "secret-user:secret-pass@bad host:3010".to_string(),
 
6511
  });
6512
  assert!(matches!(
6513
- &invalid_update,
6514
- Err(ExtractError::InvalidPaypalUpdateProxy(1))
6515
  ));
6516
- assert!(!invalid_update
6517
  .unwrap_err()
6518
  .to_string()
6519
  .contains("secret-user"));
@@ -6523,8 +6646,9 @@ mod tests {
6523
  link_type: Some("upi".to_string()),
6524
  checkout_proxy_pool: String::new(),
6525
  promotion_proxy_pool: String::new(),
6526
- paypal_main_proxy_pool: String::new(),
6527
- paypal_update_proxy_pool: String::new(),
 
6528
  });
6529
  assert!(matches!(
6530
  unsupported,
@@ -6561,8 +6685,9 @@ mod tests {
6561
  link_type: None,
6562
  checkout_proxy_pool: String::new(),
6563
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6564
- paypal_main_proxy_pool: String::new(),
6565
- paypal_update_proxy_pool: String::new(),
 
6566
  });
6567
  assert!(matches!(
6568
  missing_checkout,
@@ -6574,8 +6699,9 @@ mod tests {
6574
  link_type: None,
6575
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6576
  promotion_proxy_pool: String::new(),
6577
- paypal_main_proxy_pool: String::new(),
6578
- paypal_update_proxy_pool: String::new(),
 
6579
  });
6580
  assert!(matches!(
6581
  missing_promotion,
@@ -6599,9 +6725,11 @@ mod tests {
6599
  let paypal = config_for_link_type(LinkType::Paypal);
6600
  assert_eq!(paypal.billing_country, "US");
6601
  assert_eq!(paypal.currency, "USD");
6602
- assert_eq!(paypal.checkout_proxy_region, "BR");
6603
- assert_eq!(paypal.provider_proxy_region, "JP");
6604
- assert_eq!(paypal.approve_proxy_region, "BR");
 
 
6605
  }
6606
 
6607
  #[cfg(feature = "postgres-integration-tests")]
@@ -6617,8 +6745,9 @@ mod tests {
6617
  link_type: None,
6618
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6619
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6620
- paypal_main_proxy_pool: String::new(),
6621
- paypal_update_proxy_pool: String::new(),
 
6622
  }),
6623
  )
6624
  .await;
@@ -6644,8 +6773,9 @@ mod tests {
6644
  link_type: None,
6645
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6646
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6647
- paypal_main_proxy_pool: String::new(),
6648
- paypal_update_proxy_pool: String::new(),
 
6649
  }),
6650
  )
6651
  .await;
@@ -6682,8 +6812,9 @@ mod tests {
6682
  link_type: None,
6683
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6684
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6685
- paypal_main_proxy_pool: String::new(),
6686
- paypal_update_proxy_pool: String::new(),
 
6687
  }),
6688
  )
6689
  .await;
@@ -6698,8 +6829,9 @@ mod tests {
6698
  link_type: None,
6699
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6700
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6701
- paypal_main_proxy_pool: String::new(),
6702
- paypal_update_proxy_pool: String::new(),
 
6703
  }),
6704
  )
6705
  .await;
@@ -6723,8 +6855,9 @@ mod tests {
6723
  link_type: None,
6724
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6725
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6726
- paypal_main_proxy_pool: String::new(),
6727
- paypal_update_proxy_pool: String::new(),
 
6728
  }),
6729
  )
6730
  .await;
@@ -6748,8 +6881,9 @@ mod tests {
6748
  link_type: None,
6749
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6750
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6751
- paypal_main_proxy_pool: String::new(),
6752
- paypal_update_proxy_pool: String::new(),
 
6753
  }),
6754
  )
6755
  .await;
@@ -6774,8 +6908,9 @@ mod tests {
6774
  link_type: None,
6775
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6776
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6777
- paypal_main_proxy_pool: String::new(),
6778
- paypal_update_proxy_pool: String::new(),
 
6779
  }),
6780
  )
6781
  .await;
@@ -6972,8 +7107,9 @@ mod tests {
6972
  link_type: None,
6973
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6974
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6975
- paypal_main_proxy_pool: String::new(),
6976
- paypal_update_proxy_pool: String::new(),
 
6977
  },
6978
  )
6979
  .expect("valid pools should be accepted");
 
59
  const PAYPAL_BROWSER_LOCALE: &str = "pt-BR";
60
  const PAYPAL_ELEMENTS_LOCALE: &str = "pt-BR";
61
  const PAYPAL_BROWSER_TIMEZONE: &str = "America/Sao_Paulo";
62
+ const PAYPAL_CHECKOUT_REGION: &str = "US";
63
+ const PAYPAL_PROMOTION_REGION: &str = "VN";
64
+ const PAYPAL_PROVIDER_REGION: &str = "TR";
65
+ const PAYPAL_APPROVE_REGION: &str = "US";
66
  const PAYPAL_BILLING_COUNTRY: &str = "US";
67
  const PAYPAL_BILLING_STATE: &str = "CA";
68
  const MAX_APPROVE_ATTEMPTS: usize = 20;
69
+ const PAYPAL_APPROVE_MAX_ATTEMPTS: usize = 1;
70
  const APPROVE_CONCURRENCY: usize = 1;
71
  const MAX_REBUILD_ATTEMPTS: usize = 5;
72
  const PAYPAL_PROVIDER_MAX_ATTEMPTS: usize = 10;
 
146
  pub proxy: String,
147
  pub checkout_proxy_pool: Vec<String>,
148
  pub promotion_proxy_pool: Vec<String>,
149
+ pub paypal_provider_proxy_pool: Vec<String>,
150
  pub base_url: String,
151
  pub link_type: String,
152
  }
 
161
  #[serde(default)]
162
  pub promotion_proxy_pool: String,
163
  #[serde(default)]
164
+ pub paypal_checkout_proxy_pool: String,
165
  #[serde(default)]
166
+ pub paypal_promotion_proxy_pool: String,
167
+ #[serde(default)]
168
+ pub paypal_provider_proxy_pool: String,
169
  }
170
 
171
  #[derive(Debug, Clone, Serialize, PartialEq, Eq)]
 
1670
  InvalidCheckoutProxy(usize),
1671
  #[error("iDEAL Promotion Update 代理池第 {0} 行格式无效。")]
1672
  InvalidPromotionProxy(usize),
1673
+ #[error("PayPal US Checkout / Approve 代理池不能为空。")]
1674
+ MissingPaypalCheckoutProxyPool,
1675
+ #[error("PayPal VN Promotion Update 代理池不能为空。")]
1676
+ MissingPaypalPromotionProxyPool,
1677
+ #[error("PayPal TR Provider 代理池不能为空。")]
1678
+ MissingPaypalProviderProxyPool,
1679
+ #[error("PayPal US Checkout / Approve 代理池第 {0} 行格式无效。")]
1680
+ InvalidPaypalCheckoutProxy(usize),
1681
+ #[error("PayPal VN Promotion Update 代理池第 {0} 行格式无效。")]
1682
+ InvalidPaypalPromotionProxy(usize),
1683
+ #[error("PayPal TR Provider 代理池第 {0} 行格式无效。")]
1684
+ InvalidPaypalProviderProxy(usize),
1685
  #[error("任务已中断。")]
1686
  Canceled,
1687
  #[error("non-default --base-url must be localhost or loopback: {0}")]
 
2080
  proxy: checkout_proxy_pool[0].clone(),
2081
  checkout_proxy_pool,
2082
  promotion_proxy_pool,
2083
+ paypal_provider_proxy_pool: Vec::new(),
2084
  base_url: String::new(),
2085
  link_type: "ideal".to_string(),
2086
  })
2087
  }
2088
  "paypal" => {
2089
+ let paypal_checkout_proxy_pool = parse_proxy_pool(
2090
+ &input.paypal_checkout_proxy_pool,
2091
+ ProxyPoolKind::PaypalCheckout,
2092
+ )?;
2093
+ if paypal_checkout_proxy_pool.is_empty() {
2094
+ return Err(ExtractError::MissingPaypalCheckoutProxyPool);
2095
+ }
2096
+ let paypal_promotion_proxy_pool = parse_proxy_pool(
2097
+ &input.paypal_promotion_proxy_pool,
2098
+ ProxyPoolKind::PaypalPromotion,
2099
+ )?;
2100
+ if paypal_promotion_proxy_pool.is_empty() {
2101
+ return Err(ExtractError::MissingPaypalPromotionProxyPool);
2102
  }
2103
+ let paypal_provider_proxy_pool = parse_proxy_pool(
2104
+ &input.paypal_provider_proxy_pool,
2105
+ ProxyPoolKind::PaypalProvider,
2106
  )?;
2107
+ if paypal_provider_proxy_pool.is_empty() {
2108
+ return Err(ExtractError::MissingPaypalProviderProxyPool);
2109
  }
2110
  Ok(ExtractInput {
2111
  access_token: input.access_token,
2112
+ proxy: paypal_checkout_proxy_pool[0].clone(),
2113
+ checkout_proxy_pool: paypal_checkout_proxy_pool,
2114
+ promotion_proxy_pool: paypal_promotion_proxy_pool,
2115
+ paypal_provider_proxy_pool,
2116
  base_url: String::new(),
2117
  link_type: "paypal".to_string(),
2118
  })
 
2127
  enum ProxyPoolKind {
2128
  Checkout,
2129
  Promotion,
2130
+ PaypalCheckout,
2131
+ PaypalPromotion,
2132
+ PaypalProvider,
2133
  }
2134
 
2135
  fn parse_proxy_pool(text: &str, kind: ProxyPoolKind) -> Result<Vec<String>, ExtractError> {
 
2143
  return Err(match kind {
2144
  ProxyPoolKind::Checkout => ExtractError::InvalidCheckoutProxy(line_index + 1),
2145
  ProxyPoolKind::Promotion => ExtractError::InvalidPromotionProxy(line_index + 1),
2146
+ ProxyPoolKind::PaypalCheckout => {
2147
+ ExtractError::InvalidPaypalCheckoutProxy(line_index + 1)
2148
+ }
2149
+ ProxyPoolKind::PaypalPromotion => {
2150
+ ExtractError::InvalidPaypalPromotionProxy(line_index + 1)
2151
  }
2152
+ ProxyPoolKind::PaypalProvider => {
2153
+ ExtractError::InvalidPaypalProviderProxy(line_index + 1)
2154
  }
2155
  });
2156
  }
 
2298
  client_fingerprint: "chrome",
2299
  user_agent: PAYPAL_USER_AGENT,
2300
  checkout_proxy_region: PAYPAL_CHECKOUT_REGION,
2301
+ promotion_proxy_region: Some(PAYPAL_PROMOTION_REGION),
2302
  provider_proxy_region: PAYPAL_PROVIDER_REGION,
2303
  approve_proxy_region: PAYPAL_APPROVE_REGION,
2304
+ approve_max_attempts: PAYPAL_APPROVE_MAX_ATTEMPTS,
2305
  approve_concurrency: APPROVE_CONCURRENCY,
2306
  }
2307
  }
 
2971
  let base = EndpointBase::new(&input.base_url)?;
2972
  if input.proxy.trim().is_empty() {
2973
  return Err(ExtractError::BadResponse(
2974
+ "proxy is required for strict US-VN-TR-US PayPal extraction with US billing address"
2975
  .to_string(),
2976
  ));
2977
  }
 
2980
  &mut steps,
2981
  "locked config",
2982
  "ok",
2983
+ "paypal US billing address / USD Chrome checkout US -> VN promotion -> TR provider -> US approve attempts=10 approve_attempts=1",
2984
  progress,
2985
  );
2986
 
2987
  let mut last_error = None;
2988
  let mut last_fallback = None;
2989
  for attempt in 1..=PAYPAL_PROVIDER_MAX_ATTEMPTS {
2990
+ let (checkout_proxy, promotion_proxy, provider_proxy, checkout_index, promotion_index, provider_index) =
2991
  paypal_proxies_for_attempt(&input, attempt)?;
2992
  if attempt > 1 {
2993
  add_step_with_progress(
2994
  &mut steps,
2995
  "rebuild checkout",
2996
  "info",
2997
+ &format!("attempt {attempt}/{PAYPAL_PROVIDER_MAX_ATTEMPTS}; checkout pool #{checkout_index}; promotion pool #{promotion_index}; provider pool #{provider_index}; proxy chain {PAYPAL_CHECKOUT_REGION}->{PAYPAL_PROMOTION_REGION}->{PAYPAL_PROVIDER_REGION}->{PAYPAL_APPROVE_REGION} retry"),
2998
  progress,
2999
  );
3000
  }
 
3002
  transport,
3003
  &base,
3004
  &token,
3005
+ &checkout_proxy,
3006
+ &promotion_proxy,
3007
+ &provider_proxy,
3008
  attempt,
3009
  &mut steps,
3010
  progress,
 
3072
  fn paypal_proxies_for_attempt(
3073
  input: &ExtractInput,
3074
  attempt: usize,
3075
+ ) -> Result<(String, String, String, usize, usize, usize), ExtractError> {
3076
+ if !input.checkout_proxy_pool.is_empty()
3077
+ || !input.promotion_proxy_pool.is_empty()
3078
+ || !input.paypal_provider_proxy_pool.is_empty()
3079
+ {
3080
  if input.checkout_proxy_pool.is_empty() {
3081
+ return Err(ExtractError::MissingPaypalCheckoutProxyPool);
3082
  }
3083
  if input.promotion_proxy_pool.is_empty() {
3084
+ return Err(ExtractError::MissingPaypalPromotionProxyPool);
3085
  }
3086
+ if input.paypal_provider_proxy_pool.is_empty() {
3087
+ return Err(ExtractError::MissingPaypalProviderProxyPool);
3088
+ }
3089
+ let checkout_index = (attempt.saturating_sub(1)) % input.checkout_proxy_pool.len();
3090
+ let promotion_index = (attempt.saturating_sub(1)) % input.promotion_proxy_pool.len();
3091
+ let provider_index =
3092
+ (attempt.saturating_sub(1)) % input.paypal_provider_proxy_pool.len();
3093
  return Ok((
3094
+ input.checkout_proxy_pool[checkout_index].clone(),
3095
+ input.promotion_proxy_pool[promotion_index].clone(),
3096
+ input.paypal_provider_proxy_pool[provider_index].clone(),
3097
+ checkout_index + 1,
3098
+ promotion_index + 1,
3099
+ provider_index + 1,
3100
  ));
3101
  }
3102
 
3103
  if input.proxy.trim().is_empty() {
3104
  return Err(ExtractError::BadResponse(
3105
+ "proxy is required for strict US-VN-TR-US PayPal extraction with US billing address"
3106
  .to_string(),
3107
  ));
3108
  }
3109
+ Ok((
3110
+ input.proxy.clone(),
3111
+ input.proxy.clone(),
3112
+ input.proxy.clone(),
3113
+ 1,
3114
+ 1,
3115
+ 1,
3116
+ ))
3117
  }
3118
 
3119
  async fn run_paypal_attempt<T: Transport>(
3120
  transport: &mut T,
3121
  base: &EndpointBase,
3122
  token: &str,
3123
+ checkout_proxy_seed: &str,
3124
+ promotion_proxy_seed: &str,
3125
+ provider_proxy_seed: &str,
3126
  attempt: usize,
3127
  steps: &mut Vec<Step>,
3128
  progress: Option<&ProgressSink>,
3129
  ) -> Result<ExtractOutput, ExtractError> {
3130
+ let attempt_checkout_proxy = proxy_seed_for_attempt(checkout_proxy_seed, attempt);
3131
+ let attempt_promotion_proxy = proxy_seed_for_attempt(promotion_proxy_seed, attempt);
3132
+ let attempt_provider_proxy = proxy_seed_for_attempt(provider_proxy_seed, attempt);
3133
+ let checkout_proxy = proxy_for_region(&attempt_checkout_proxy, PAYPAL_CHECKOUT_REGION);
3134
+ let promotion_proxy = proxy_for_region(&attempt_promotion_proxy, PAYPAL_PROMOTION_REGION);
3135
+ let provider_proxy = proxy_for_region(&attempt_provider_proxy, PAYPAL_PROVIDER_REGION);
3136
  let approve_proxy =
3137
+ proxy_with_fresh_sid(&proxy_for_region(&attempt_checkout_proxy, PAYPAL_APPROVE_REGION));
3138
  add_step_with_progress(
3139
  steps,
3140
  "proxy chain",
3141
  "ok",
3142
+ &format!("attempt {attempt}/{PAYPAL_PROVIDER_MAX_ATTEMPTS}; checkout={PAYPAL_CHECKOUT_REGION}; promotion={PAYPAL_PROMOTION_REGION}; provider={PAYPAL_PROVIDER_REGION}; approve={PAYPAL_APPROVE_REGION}"),
3143
  progress,
3144
  );
3145
 
 
3155
  .await?;
3156
  add_step_with_progress(steps, "checkout", "ok", &checkout.cs_id, progress);
3157
 
3158
+ update_checkout_promotion(
3159
+ transport,
3160
+ base,
3161
+ &chatgpt_headers,
3162
+ &checkout,
3163
+ &promotion_proxy,
3164
+ )
3165
+ .await?;
3166
+ add_step_with_progress(
3167
+ steps,
3168
+ "VN promotion update",
3169
+ "ok",
3170
+ "promotion applied before PayPal; reinitializing Stripe through TR",
3171
+ progress,
3172
+ );
3173
+
3174
  let stripe_pk = if checkout.publishable_key.is_empty() {
3175
  DEFAULT_STRIPE_PK.to_string()
3176
  } else {
 
3187
  .await?;
3188
  add_step_with_progress(
3189
  steps,
3190
+ "VN promotion Stripe init",
3191
  "ok",
3192
  &init.stripe_hosted_url,
3193
  progress,
 
3213
  base,
3214
  &checkout.cs_id,
3215
  &stripe_pk,
3216
+ &provider_proxy,
3217
  paypal_billing_country,
3218
  )
3219
  .await
 
4507
  steps,
4508
  "approve retry policy",
4509
  "ok",
4510
+ &format!(
4511
+ "total_attempts={}; concurrency={}",
4512
+ config.approve_max_attempts, config.approve_concurrency
4513
+ ),
4514
  progress,
4515
  );
4516
  let header_token = access_token_from_headers(headers);
 
4539
  let approve_headers =
4540
  target_headers(headers, "/backend-api/payments/checkout/approve", &referer);
4541
  let mut last_error = None;
4542
+ for attempt in 1..=config.approve_max_attempts {
4543
  let current_approve_proxy = if attempt == 1 {
4544
  base_approve_proxy.clone()
4545
  } else {
 
4551
  "approve retry",
4552
  "info",
4553
  &format!(
4554
+ "attempt {attempt}/{}; approve={}; retry proxy",
4555
+ config.approve_max_attempts,
4556
  config.approve_proxy_region
4557
  ),
4558
  progress,
 
5822
  proxy: "http://user-region-US-sid-old-t-1:pass@proxy.example:3010".to_string(),
5823
  checkout_proxy_pool: Vec::new(),
5824
  promotion_proxy_pool: Vec::new(),
5825
+ paypal_provider_proxy_pool: Vec::new(),
5826
  base_url: "http://IP_REDACTED:8792".to_string(),
5827
  link_type: "ideal".to_string(),
5828
  },
 
5924
  proxy: checkout_proxy.to_string(),
5925
  checkout_proxy_pool: vec![checkout_proxy.to_string()],
5926
  promotion_proxy_pool: vec![promotion_proxy.to_string()],
5927
+ paypal_provider_proxy_pool: Vec::new(),
5928
  base_url: "http://IP_REDACTED:8792".to_string(),
5929
  link_type: "ideal".to_string(),
5930
  },
 
5962
  "http://promotion-two.example:3020".to_string(),
5963
  "http://promotion-three.example:3020".to_string(),
5964
  ],
5965
+ paypal_provider_proxy_pool: Vec::new(),
5966
  base_url: String::new(),
5967
  link_type: "ideal".to_string(),
5968
  };
 
5978
  fn submitted_paypal_pools_rotate_independently_by_rebuild_attempt() {
5979
  let input = ExtractInput {
5980
  access_token: "at_test".to_string(),
5981
+ proxy: "http://checkout-one.example:3010".to_string(),
5982
  checkout_proxy_pool: vec![
5983
+ "http://checkout-one.example:3010".to_string(),
5984
+ "http://checkout-two.example:3010".to_string(),
5985
  ],
5986
  promotion_proxy_pool: vec![
5987
+ "http://promotion-one.example:3020".to_string(),
5988
+ "http://promotion-two.example:3020".to_string(),
5989
+ "http://promotion-three.example:3020".to_string(),
5990
+ ],
5991
+ paypal_provider_proxy_pool: vec![
5992
+ "http://provider-one.example:3030".to_string(),
5993
+ "http://provider-two.example:3030".to_string(),
5994
+ "http://provider-three.example:3030".to_string(),
5995
+ "http://provider-four.example:3030".to_string(),
5996
  ],
5997
  base_url: String::new(),
5998
  link_type: "paypal".to_string(),
5999
  };
6000
 
6001
  let attempt_four = paypal_proxies_for_attempt(&input, 4)
6002
+ .expect("all submitted PayPal pools should be selectable");
6003
+ assert_eq!(attempt_four.0, "http://checkout-two.example:3010");
6004
+ assert_eq!(attempt_four.1, "http://promotion-one.example:3020");
6005
+ assert_eq!(attempt_four.2, "http://provider-four.example:3030");
6006
+ assert_eq!((attempt_four.3, attempt_four.4, attempt_four.5), (2, 1, 4));
6007
  }
6008
 
6009
  #[tokio::test]
6010
+ async fn submitted_paypal_pools_route_us_vn_tr_us() {
6011
  #[derive(Default)]
6012
  struct PaypalTransport {
6013
  requests: Vec<HttpRequest>,
 
6030
  "processor_entity": "openai_ie",
6031
  "publishable_key": "pk_REDACTED"
6032
  }),
6033
+ "/backend-api/payments/checkout/update" => {
6034
+ serde_json::json!({ "success": true })
6035
+ }
6036
  "/v1/payment_pages/cs_paypal_pool_test/init" => serde_json::json!({
6037
  "stripe_hosted_url": "https://checkout.stripe.com/c/pay/cs_paypal_pool_test",
6038
  "init_checksum": "checksum_paypal_pool_test",
 
6084
  }
6085
  }
6086
 
6087
+ let checkout_proxy =
6088
+ "http://checkout-user-region-US-sid-checkout-t-1:pass@checkout.example:3010";
6089
+ let promotion_proxy =
6090
+ "http://promotion-user-region-VN-sid-promotion-t-1:pass@promotion.example:3020";
6091
+ let provider_proxy =
6092
+ "http://provider-user-region-TR-sid-provider-t-1:pass@provider.example:3030";
6093
  let mut transport = PaypalTransport::default();
6094
  let output = extract_paypal_link_with_progress(
6095
  &mut transport,
 
6097
  access_token:
6098
  "eyJhbGciOiJub25lIn0.eyJlbWFpbCI6InBheXBhbC1wb29sQGV4YW1wbGUuY29tIn0.sig"
6099
  .to_string(),
6100
+ proxy: checkout_proxy.to_string(),
6101
+ checkout_proxy_pool: vec![checkout_proxy.to_string()],
6102
+ promotion_proxy_pool: vec![promotion_proxy.to_string()],
6103
+ paypal_provider_proxy_pool: vec![provider_proxy.to_string()],
6104
  base_url: "http://localhost:8792".to_string(),
6105
  link_type: "paypal".to_string(),
6106
  },
 
6134
  if form.get("billing_details[address][country]").map(String::as_str) == Some("US")
6135
  && form.get("billing_details[address][state]").map(String::as_str) == Some("CA")));
6136
 
6137
+ let mut approve_requests = 0;
6138
  for request in &transport.requests {
6139
+ if request.url.ends_with("/backend-api/payments/checkout/update") {
6140
+ assert!(request.proxy_url.contains("promotion.example:3020"));
6141
+ assert!(request.proxy_url.contains("region-VN"));
6142
+ } else if request.url.ends_with("/backend-api/payments/checkout")
6143
+ || request.url.ends_with("/backend-api/sentinel/ping")
6144
+ || request.url.ends_with("/backend-api/payments/checkout/approve")
6145
+ || (request.url.ends_with("/v1/payment_pages/cs_paypal_pool_test")
6146
+ && request.method == "GET")
6147
+ {
6148
+ assert!(request.proxy_url.contains("checkout.example:3010"));
6149
+ assert!(request.proxy_url.contains("region-US"));
6150
+ if request.url.ends_with("/backend-api/payments/checkout/approve") {
6151
+ approve_requests += 1;
6152
+ }
6153
  } else {
 
 
 
 
 
6154
  assert!(
6155
+ request.proxy_url.contains("provider.example:3030"),
6156
+ "provider PayPal request must use the TR pool: {}",
6157
  request.url
6158
  );
6159
+ assert!(request.proxy_url.contains("region-TR"));
6160
  }
6161
  }
6162
+ assert_eq!(approve_requests, 1);
6163
  }
6164
 
6165
  #[test]
 
6267
  proxy: "http://user-region-US-sid-old-t-1:pass@proxy.example:3010".to_string(),
6268
  checkout_proxy_pool: Vec::new(),
6269
  promotion_proxy_pool: Vec::new(),
6270
+ paypal_provider_proxy_pool: Vec::new(),
6271
  base_url: "http://IP_REDACTED:8792".to_string(),
6272
  link_type: "ideal".to_string(),
6273
  },
 
6291
  proxy: String::new(),
6292
  checkout_proxy_pool: Vec::new(),
6293
  promotion_proxy_pool: Vec::new(),
6294
+ paypal_provider_proxy_pool: Vec::new(),
6295
  base_url: "http://IP_REDACTED:8792".to_string(),
6296
  link_type: "ideal".to_string(),
6297
  },
 
6316
  proxy: String::new(),
6317
  checkout_proxy_pool: Vec::new(),
6318
  promotion_proxy_pool: Vec::new(),
6319
+ paypal_provider_proxy_pool: Vec::new(),
6320
  base_url: "https://collector.example.test".to_string(),
6321
  link_type: "ideal".to_string(),
6322
  },
 
6348
  proxy: String::new(),
6349
  checkout_proxy_pool: Vec::new(),
6350
  promotion_proxy_pool: Vec::new(),
6351
+ paypal_provider_proxy_pool: Vec::new(),
6352
  base_url: base_url.to_string(),
6353
  link_type: "ideal".to_string(),
6354
  },
 
6449
  assert!(html.contains("id=\"access-token\""));
6450
  assert!(html.contains("id=\"checkout-proxy-pool\""));
6451
  assert!(html.contains("id=\"promotion-proxy-pool\""));
6452
+ assert!(html.contains("id=\"paypal-checkout-proxy-pool\""));
6453
+ assert!(html.contains("id=\"paypal-promotion-proxy-pool\""));
6454
+ assert!(html.contains("id=\"paypal-provider-proxy-pool\""));
6455
  assert!(html.contains("iDEAL Checkout 主代理池(每行一个)"));
6456
  assert!(html.contains("iDEAL Promotion Update 代理池(每行一个)"));
6457
+ assert!(html.contains("PayPal US Checkout / Approve 代理池(每行一个)"));
6458
+ assert!(html.contains("PayPal VN Promotion Update 代理池(每行一个)"));
6459
+ assert!(html.contains("PayPal TR Provider 代理池(每行一个)"));
6460
  assert!(html.contains("checkout_proxy_pool"));
6461
  assert!(html.contains("promotion_proxy_pool"));
6462
+ assert!(html.contains("paypal_checkout_proxy_pool"));
6463
+ assert!(html.contains("paypal_promotion_proxy_pool"));
6464
+ assert!(html.contains("paypal_provider_proxy_pool"));
6465
  assert!(!html.contains("paypal_proxy"));
6466
  assert!(html.contains("data-link-type=\"ideal\""));
6467
  assert!(html.contains("data-link-type=\"paypal\""));
 
6471
  assert!(html.contains("id=\"long-url\""));
6472
  assert!(html.contains("overflow-wrap: anywhere"));
6473
  assert!(html.contains("/cancel"));
 
 
6474
  assert!(html.contains("link_type: currentLinkType"));
6475
  assert!(!html.contains("localStorage"));
6476
  assert!(!html.contains("UPI"));
 
6498
  link_type: None,
6499
  checkout_proxy_pool: "checkout.example:3010\ncheckout.example:3010".to_string(),
6500
  promotion_proxy_pool: "http://promotion.example:3010".to_string(),
6501
+ paypal_checkout_proxy_pool: String::new(),
6502
+ paypal_promotion_proxy_pool: String::new(),
6503
+ paypal_provider_proxy_pool: String::new(),
6504
  })
6505
  .expect("both submitted pools should be accepted");
6506
 
 
6513
  }
6514
 
6515
  #[test]
6516
+ fn api_input_exposes_three_paypal_proxy_pools() {
6517
  let input = extract_input_for_api(ExtractApiInput {
6518
  access_token: "at_test".to_string(),
6519
  link_type: Some("paypal".to_string()),
6520
  checkout_proxy_pool: String::new(),
6521
  promotion_proxy_pool: String::new(),
6522
+ paypal_checkout_proxy_pool:
6523
+ "checkout-one.example:3010\ncheckout-one.example:3010\ncheckout-two.example:3010"
6524
  .to_string(),
6525
+ paypal_promotion_proxy_pool: "promotion.example:3020".to_string(),
6526
+ paypal_provider_proxy_pool: "provider.example:3030".to_string(),
6527
  })
6528
  .expect("valid PayPal pools should be accepted");
6529
 
6530
+ assert_eq!(input.proxy, "http://checkout-one.example:3010");
6531
  assert_eq!(
6532
  input.checkout_proxy_pool,
6533
  vec![
6534
+ "http://checkout-one.example:3010",
6535
+ "http://checkout-two.example:3010"
6536
  ]
6537
  );
6538
  assert_eq!(
6539
  input.promotion_proxy_pool,
6540
+ vec!["http://promotion.example:3020"]
6541
+ );
6542
+ assert_eq!(
6543
+ input.paypal_provider_proxy_pool,
6544
+ vec!["http://provider.example:3030"]
6545
  );
6546
  assert_eq!(input.link_type, "paypal");
6547
  }
6548
 
6549
  #[test]
6550
  fn api_input_rejects_missing_invalid_paypal_pools_and_unknown_link_type() {
6551
+ let missing_checkout = extract_input_for_api(ExtractApiInput {
6552
  access_token: "at_test".to_string(),
6553
  link_type: Some("paypal".to_string()),
6554
  checkout_proxy_pool: String::new(),
6555
  promotion_proxy_pool: String::new(),
6556
+ paypal_checkout_proxy_pool: String::new(),
6557
+ paypal_promotion_proxy_pool: "promotion.example:3020".to_string(),
6558
+ paypal_provider_proxy_pool: "provider.example:3030".to_string(),
6559
  });
6560
  assert!(matches!(
6561
+ missing_checkout,
6562
+ Err(ExtractError::MissingPaypalCheckoutProxyPool)
6563
+ ));
6564
+
6565
+ let missing_promotion = extract_input_for_api(ExtractApiInput {
6566
+ access_token: "at_test".to_string(),
6567
+ link_type: Some("paypal".to_string()),
6568
+ checkout_proxy_pool: String::new(),
6569
+ promotion_proxy_pool: String::new(),
6570
+ paypal_checkout_proxy_pool: "checkout.example:3010".to_string(),
6571
+ paypal_promotion_proxy_pool: String::new(),
6572
+ paypal_provider_proxy_pool: "provider.example:3030".to_string(),
6573
+ });
6574
+ assert!(matches!(
6575
+ missing_promotion,
6576
+ Err(ExtractError::MissingPaypalPromotionProxyPool)
6577
  ));
6578
 
6579
+ let missing_provider = extract_input_for_api(ExtractApiInput {
6580
  access_token: "at_test".to_string(),
6581
  link_type: Some("paypal".to_string()),
6582
  checkout_proxy_pool: String::new(),
6583
  promotion_proxy_pool: String::new(),
6584
+ paypal_checkout_proxy_pool: "checkout.example:3010".to_string(),
6585
+ paypal_promotion_proxy_pool: "promotion.example:3020".to_string(),
6586
+ paypal_provider_proxy_pool: String::new(),
6587
  });
6588
  assert!(matches!(
6589
+ missing_provider,
6590
+ Err(ExtractError::MissingPaypalProviderProxyPool)
6591
  ));
6592
 
6593
+ let invalid_checkout = extract_input_for_api(ExtractApiInput {
6594
  access_token: "at_test".to_string(),
6595
  link_type: Some("paypal".to_string()),
6596
  checkout_proxy_pool: String::new(),
6597
  promotion_proxy_pool: String::new(),
6598
+ paypal_checkout_proxy_pool: "secret-user:secret-pass@bad host:3010".to_string(),
6599
+ paypal_promotion_proxy_pool: "promotion.example:3020".to_string(),
6600
+ paypal_provider_proxy_pool: "provider.example:3030".to_string(),
6601
  });
6602
  assert!(matches!(
6603
+ &invalid_checkout,
6604
+ Err(ExtractError::InvalidPaypalCheckoutProxy(1))
6605
  ));
6606
+ assert!(!invalid_checkout.unwrap_err().to_string().contains("secret-user"));
6607
+
6608
+ let invalid_promotion = extract_input_for_api(ExtractApiInput {
6609
+ access_token: "at_test".to_string(),
6610
+ link_type: Some("paypal".to_string()),
6611
+ checkout_proxy_pool: String::new(),
6612
+ promotion_proxy_pool: String::new(),
6613
+ paypal_checkout_proxy_pool: "checkout.example:3010".to_string(),
6614
+ paypal_promotion_proxy_pool: "secret-user:secret-pass@bad host:3010".to_string(),
6615
+ paypal_provider_proxy_pool: "provider.example:3030".to_string(),
6616
+ });
6617
+ assert!(matches!(
6618
+ &invalid_promotion,
6619
+ Err(ExtractError::InvalidPaypalPromotionProxy(1))
6620
+ ));
6621
+ assert!(!invalid_promotion
6622
+ .unwrap_err()
6623
+ .to_string()
6624
+ .contains("secret-user"));
6625
 
6626
+ let invalid_provider = extract_input_for_api(ExtractApiInput {
6627
  access_token: "at_test".to_string(),
6628
  link_type: Some("paypal".to_string()),
6629
  checkout_proxy_pool: String::new(),
6630
  promotion_proxy_pool: String::new(),
6631
+ paypal_checkout_proxy_pool: "checkout.example:3010".to_string(),
6632
+ paypal_promotion_proxy_pool: "promotion.example:3020".to_string(),
6633
+ paypal_provider_proxy_pool: "secret-user:secret-pass@bad host:3010".to_string(),
6634
  });
6635
  assert!(matches!(
6636
+ &invalid_provider,
6637
+ Err(ExtractError::InvalidPaypalProviderProxy(1))
6638
  ));
6639
+ assert!(!invalid_provider
6640
  .unwrap_err()
6641
  .to_string()
6642
  .contains("secret-user"));
 
6646
  link_type: Some("upi".to_string()),
6647
  checkout_proxy_pool: String::new(),
6648
  promotion_proxy_pool: String::new(),
6649
+ paypal_checkout_proxy_pool: String::new(),
6650
+ paypal_promotion_proxy_pool: String::new(),
6651
+ paypal_provider_proxy_pool: String::new(),
6652
  });
6653
  assert!(matches!(
6654
  unsupported,
 
6685
  link_type: None,
6686
  checkout_proxy_pool: String::new(),
6687
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6688
+ paypal_checkout_proxy_pool: String::new(),
6689
+ paypal_promotion_proxy_pool: String::new(),
6690
+ paypal_provider_proxy_pool: String::new(),
6691
  });
6692
  assert!(matches!(
6693
  missing_checkout,
 
6699
  link_type: None,
6700
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6701
  promotion_proxy_pool: String::new(),
6702
+ paypal_checkout_proxy_pool: String::new(),
6703
+ paypal_promotion_proxy_pool: String::new(),
6704
+ paypal_provider_proxy_pool: String::new(),
6705
  });
6706
  assert!(matches!(
6707
  missing_promotion,
 
6725
  let paypal = config_for_link_type(LinkType::Paypal);
6726
  assert_eq!(paypal.billing_country, "US");
6727
  assert_eq!(paypal.currency, "USD");
6728
+ assert_eq!(paypal.checkout_proxy_region, "US");
6729
+ assert_eq!(paypal.promotion_proxy_region, Some("VN"));
6730
+ assert_eq!(paypal.provider_proxy_region, "TR");
6731
+ assert_eq!(paypal.approve_proxy_region, "US");
6732
+ assert_eq!(paypal.approve_max_attempts, 1);
6733
  }
6734
 
6735
  #[cfg(feature = "postgres-integration-tests")]
 
6745
  link_type: None,
6746
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6747
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6748
+ paypal_checkout_proxy_pool: String::new(),
6749
+ paypal_promotion_proxy_pool: String::new(),
6750
+ paypal_provider_proxy_pool: String::new(),
6751
  }),
6752
  )
6753
  .await;
 
6773
  link_type: None,
6774
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6775
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6776
+ paypal_checkout_proxy_pool: String::new(),
6777
+ paypal_promotion_proxy_pool: String::new(),
6778
+ paypal_provider_proxy_pool: String::new(),
6779
  }),
6780
  )
6781
  .await;
 
6812
  link_type: None,
6813
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6814
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6815
+ paypal_checkout_proxy_pool: String::new(),
6816
+ paypal_promotion_proxy_pool: String::new(),
6817
+ paypal_provider_proxy_pool: String::new(),
6818
  }),
6819
  )
6820
  .await;
 
6829
  link_type: None,
6830
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6831
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6832
+ paypal_checkout_proxy_pool: String::new(),
6833
+ paypal_promotion_proxy_pool: String::new(),
6834
+ paypal_provider_proxy_pool: String::new(),
6835
  }),
6836
  )
6837
  .await;
 
6855
  link_type: None,
6856
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6857
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6858
+ paypal_checkout_proxy_pool: String::new(),
6859
+ paypal_promotion_proxy_pool: String::new(),
6860
+ paypal_provider_proxy_pool: String::new(),
6861
  }),
6862
  )
6863
  .await;
 
6881
  link_type: None,
6882
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6883
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6884
+ paypal_checkout_proxy_pool: String::new(),
6885
+ paypal_promotion_proxy_pool: String::new(),
6886
+ paypal_provider_proxy_pool: String::new(),
6887
  }),
6888
  )
6889
  .await;
 
6908
  link_type: None,
6909
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6910
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6911
+ paypal_checkout_proxy_pool: String::new(),
6912
+ paypal_promotion_proxy_pool: String::new(),
6913
+ paypal_provider_proxy_pool: String::new(),
6914
  }),
6915
  )
6916
  .await;
 
7107
  link_type: None,
7108
  checkout_proxy_pool: "checkout.example:3010".to_string(),
7109
  promotion_proxy_pool: "promotion.example:3010".to_string(),
7110
+ paypal_checkout_proxy_pool: String::new(),
7111
+ paypal_promotion_proxy_pool: String::new(),
7112
+ paypal_provider_proxy_pool: String::new(),
7113
  },
7114
  )
7115
  .expect("valid pools should be accepted");