axm0121 commited on
Commit
79d2c8a
·
verified ·
1 Parent(s): c2835bd

Expose existing Rust PayPal flow

Browse files

Restore PayPal API dispatch and UI mode with a single US-proxy-hinted input while leaving the existing Rust PayPal implementation unchanged.

Files changed (3) hide show
  1. README.md +4 -2
  2. src/index.html +95 -17
  3. src/lib.rs +134 -19
README.md CHANGED
@@ -35,7 +35,7 @@ the Hugging Face Space settings and must not be committed to this repository.
35
 
36
  ## Fixed behavior
37
 
38
- - `link_type`: `ideal`
39
  - billing country: `NL`
40
  - currency: `EUR`
41
  - checkout UI mode: `custom`
@@ -64,7 +64,9 @@ Direct CLI extraction is not available; extraction is intentionally exposed only
64
  - `GET /api/auth/me` to read the current LinuxDo user, CDK, and remaining uses.
65
  - `POST /api/auth/logout` to clear the local session.
66
  - `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.
67
- - `POST /api/extract` with `{ "access_token", "checkout_proxy_pool", "promotion_proxy_pool" }` to enqueue a job. Both proxy pools are required newline-delimited strings.
 
 
68
  - `GET /api/extract/{job_id}` to poll queued/running/completed status.
69
 
70
  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. Browser extraction reads two required proxy pools from the request: one Checkout route reused for Checkout, Stripe, tax, provider resolution, and approve within an attempt, plus one Promotion Update route used only for that update call. 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`.
 
35
 
36
  ## Fixed behavior
37
 
38
+ - browser `link_type`: `ideal` or `paypal`
39
  - billing country: `NL`
40
  - currency: `EUR`
41
  - checkout UI mode: `custom`
 
64
  - `GET /api/auth/me` to read the current LinuxDo user, CDK, and remaining uses.
65
  - `POST /api/auth/logout` to clear the local session.
66
  - `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.
67
+ - `POST /api/extract` to enqueue a job:
68
+ - iDEAL: `{ "access_token", "link_type": "ideal", "checkout_proxy_pool", "promotion_proxy_pool" }`; both pools are required newline-delimited strings.
69
+ - PayPal: `{ "access_token", "link_type": "paypal", "paypal_proxy" }`; the single proxy is required and the page prompts for a United States proxy seed.
70
  - `GET /api/extract/{job_id}` to poll queued/running/completed status.
71
 
72
  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. Browser extraction reads two required proxy pools from the request: one Checkout route reused for Checkout, Stripe, tax, provider resolution, and approve within an attempt, plus one Promotion Update route used only for that update call. 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`.
src/index.html CHANGED
@@ -70,6 +70,26 @@
70
  .field { display: grid; gap: 8px; }
71
  label { font-size: 13px; font-weight: 700; }
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  textarea, input {
74
  width: 100%;
75
  border: 1px solid var(--line);
@@ -153,24 +173,29 @@
153
  <main>
154
  <header>
155
  <div>
156
- <h1>iDEAL 链接提取器</h1>
157
- <p>固定 NL/EUR/custom/Safari。Checkout 全链路与 Promotion Update 分别使用下方两个代理池。</p>
158
  </div>
159
  <div class="stats" aria-label="locked configuration">
160
- <div class="stat"><strong>iDEAL</strong><span>NL / EUR</span></div>
161
- <div class="stat"><strong>5 轮</strong><span>代理池依次轮换</span></div>
162
- <div class="stat"><strong>双代理池</strong><span>输入即用于本轮链路</span></div>
163
  </div>
164
  </header>
165
 
166
  <section class="panel tool">
 
 
 
 
 
167
  <div class="field">
168
  <label for="access-token">Access Token 或 session JSON</label>
169
  <textarea id="access-token" autocomplete="off" spellcheck="false" placeholder="在这里粘贴 Access Token"></textarea>
170
  <small>Token 不会写入磁盘,也不会显示在结果中。</small>
171
  </div>
172
 
173
- <div class="grid">
174
  <div class="field">
175
  <label for="checkout-proxy-pool">iDEAL Checkout 主代理池(每行一个)</label>
176
  <textarea id="checkout-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@host:port&#10;user:pass@host:port"></textarea>
@@ -183,6 +208,12 @@
183
  </div>
184
  </div>
185
 
 
 
 
 
 
 
186
  <div class="actions">
187
  <button id="generate" type="button">提取 iDEAL 链</button>
188
  <button id="clear" class="secondary" type="button">清空</button>
@@ -216,11 +247,14 @@
216
  const tokenInput = $("access-token");
217
  const checkoutPoolInput = $("checkout-proxy-pool");
218
  const promotionPoolInput = $("promotion-proxy-pool");
 
219
  const generateButton = $("generate");
220
  const cancelButton = $("cancel");
 
221
  let activeJobId = "";
222
  let pollTimer = 0;
223
  let currentLongUrl = "";
 
224
 
225
  function setStatus(message, kind = "") {
226
  $("status").textContent = message;
@@ -235,10 +269,43 @@
235
  tokenInput.disabled = busy;
236
  checkoutPoolInput.disabled = busy;
237
  promotionPoolInput.disabled = busy;
 
238
  generateButton.disabled = busy;
239
  $("clear").disabled = busy;
240
  $("task-control").classList.toggle("hidden", !busy);
241
  cancelButton.disabled = !busy;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
  function stopPolling() {
@@ -258,21 +325,21 @@
258
  const stepLabels = {
259
  queued: "排队",
260
  running: "开始执行",
261
- "locked config": "固定 iDEAL 配置",
262
  "proxy chain": "选择本轮代理",
263
- checkout: "创建 NL Checkout",
264
  "stripe init": "初始化 Stripe",
265
  "VN promotion update": "Promotion Update",
266
  "VN promotion Stripe init": "优惠后刷新 Stripe",
267
  "iDEAL ChatGPT taxes": "同步 ChatGPT 税费",
268
  "iDEAL Stripe tax region": "同步 Stripe 税区",
269
  "iDEAL tax Stripe init": "税费后刷新 Stripe",
270
- "payment method": "创建 iDEAL PaymentMethod",
271
  "stripe confirm": "确认 Stripe",
272
  approve: "ChatGPT approve",
273
  "approve retry": "approve 重试",
274
  "stripe redirect retry": "轮询 Stripe 跳转",
275
- "provider redirect": "解析最终 iDEAL 链",
276
  "rebuild checkout": "重建 Checkout",
277
  "rebuild retry": "进入下一轮",
278
  canceled: "任务已终止",
@@ -314,7 +381,7 @@
314
  }
315
 
316
  function jobStatusText(job) {
317
- if (job?.status === "running") return "正在执行完整 iDEAL 链路。";
318
  if (job?.status === "queued") return job.position > 1 ? `排队中,前面还有 ${job.position - 1} 个任务。` : "排队中,即将开始。";
319
  return "正在处理。";
320
  }
@@ -328,7 +395,7 @@
328
  $("progress-state").textContent = job?.status || "running";
329
  if (job?.status === "completed") {
330
  showResult(payload.output || job.output);
331
- setStatus("iDEAL 链提取完成。", "ok");
332
  stopPolling();
333
  return;
334
  }
@@ -352,9 +419,11 @@
352
  const accessToken = tokenInput.value.trim();
353
  const checkoutPool = proxyLines(checkoutPoolInput.value);
354
  const promotionPool = proxyLines(promotionPoolInput.value);
 
355
  if (!accessToken) return setStatus("Access Token 不能为空。", "error");
356
- if (!checkoutPool.length) return setStatus("iDEAL Checkout 主代理池不能为空。", "error");
357
- if (!promotionPool.length) return setStatus("iDEAL Promotion Update 代理池不能为空。", "error");
 
358
 
359
  $("result").classList.remove("show");
360
  renderSteps([{ name: "queued", status: "queued", detail: "正在提交任务。" }]);
@@ -366,8 +435,10 @@
366
  headers: { "content-type": "application/json" },
367
  body: JSON.stringify({
368
  access_token: accessToken,
369
- checkout_proxy_pool: checkoutPool.join("\n"),
370
- promotion_proxy_pool: promotionPool.join("\n"),
 
 
371
  }),
372
  });
373
  const payload = await readJson(response);
@@ -388,9 +459,10 @@
388
  tokenInput.value = "";
389
  checkoutPoolInput.value = "";
390
  promotionPoolInput.value = "";
 
391
  $("result").classList.remove("show");
392
  renderSteps([]);
393
- setStatus("两个代理池都必须填写。");
394
  });
395
  cancelButton.addEventListener("click", async () => {
396
  if (!activeJobId) return;
@@ -412,7 +484,13 @@
412
  await navigator.clipboard.writeText(currentLongUrl);
413
  setStatus("链接已复制。", "ok");
414
  });
 
 
 
 
 
415
  setBusy(false);
 
416
  </script>
417
  </body>
418
  </html>
 
70
  .field { display: grid; gap: 8px; }
71
  label { font-size: 13px; font-weight: 700; }
72
 
73
+ .mode-group {
74
+ display: grid;
75
+ grid-template-columns: repeat(2, minmax(0, 1fr));
76
+ gap: 6px;
77
+ width: min(360px, 100%);
78
+ padding: 4px;
79
+ border: 1px solid var(--line);
80
+ border-radius: 8px;
81
+ background: var(--soft);
82
+ }
83
+
84
+ .mode-button {
85
+ min-height: 38px;
86
+ background: transparent;
87
+ color: var(--muted);
88
+ }
89
+
90
+ .mode-button:hover { background: #e1e8ee; }
91
+ .mode-button.active { background: var(--accent); color: #fff; }
92
+
93
  textarea, input {
94
  width: 100%;
95
  border: 1px solid var(--line);
 
173
  <main>
174
  <header>
175
  <div>
176
+ <h1 id="page-title">iDEAL 链接提取器</h1>
177
+ <p id="page-description">固定 NL/EUR/custom/Safari。Checkout 全链路与 Promotion Update 分别使用下方两个代理池。</p>
178
  </div>
179
  <div class="stats" aria-label="locked configuration">
180
+ <div class="stat"><strong id="stat-link">iDEAL</strong><span id="stat-billing">NL / EUR</span></div>
181
+ <div class="stat"><strong id="stat-attempts">5 轮</strong><span id="stat-route">代理池依次轮换</span></div>
182
+ <div class="stat"><strong id="stat-proxy">双代理池</strong><span id="stat-proxy-note">输入即用于本轮链路</span></div>
183
  </div>
184
  </header>
185
 
186
  <section class="panel tool">
187
+ <div class="mode-group" role="tablist" aria-label="link type">
188
+ <button class="mode-button active" type="button" data-link-type="ideal" role="tab" aria-selected="true">iDEAL</button>
189
+ <button class="mode-button" type="button" data-link-type="paypal" role="tab" aria-selected="false">PayPal</button>
190
+ </div>
191
+
192
  <div class="field">
193
  <label for="access-token">Access Token 或 session JSON</label>
194
  <textarea id="access-token" autocomplete="off" spellcheck="false" placeholder="在这里粘贴 Access Token"></textarea>
195
  <small>Token 不会写入磁盘,也不会显示在结果中。</small>
196
  </div>
197
 
198
+ <div id="ideal-proxy-fields" class="grid">
199
  <div class="field">
200
  <label for="checkout-proxy-pool">iDEAL Checkout 主代理池(每行一个)</label>
201
  <textarea id="checkout-proxy-pool" class="proxy-list" spellcheck="false" placeholder="user:pass@host:port&#10;user:pass@host:port"></textarea>
 
208
  </div>
209
  </div>
210
 
211
+ <div id="paypal-proxy-field" class="field hidden">
212
+ <label for="paypal-proxy">PayPal Checkout 代理(请使用美国代理)</label>
213
+ <input id="paypal-proxy" autocomplete="off" spellcheck="false" placeholder="user:pass@us-host:port" />
214
+ <small>该值作为现有 Rust PayPal 链路的代理种子;指纹、账单、BR → JP → BR 路由和重试流程保持不变。</small>
215
+ </div>
216
+
217
  <div class="actions">
218
  <button id="generate" type="button">提取 iDEAL 链</button>
219
  <button id="clear" class="secondary" type="button">清空</button>
 
247
  const tokenInput = $("access-token");
248
  const checkoutPoolInput = $("checkout-proxy-pool");
249
  const promotionPoolInput = $("promotion-proxy-pool");
250
+ const paypalProxyInput = $("paypal-proxy");
251
  const generateButton = $("generate");
252
  const cancelButton = $("cancel");
253
+ const modeButtons = Array.from(document.querySelectorAll(".mode-button"));
254
  let activeJobId = "";
255
  let pollTimer = 0;
256
  let currentLongUrl = "";
257
+ let currentLinkType = "ideal";
258
 
259
  function setStatus(message, kind = "") {
260
  $("status").textContent = message;
 
269
  tokenInput.disabled = busy;
270
  checkoutPoolInput.disabled = busy;
271
  promotionPoolInput.disabled = busy;
272
+ paypalProxyInput.disabled = busy;
273
  generateButton.disabled = busy;
274
  $("clear").disabled = busy;
275
  $("task-control").classList.toggle("hidden", !busy);
276
  cancelButton.disabled = !busy;
277
+ for (const button of modeButtons) button.disabled = busy;
278
+ }
279
+
280
+ function linkLabel() {
281
+ return currentLinkType === "paypal" ? "PayPal" : "iDEAL";
282
+ }
283
+
284
+ function setMode(linkType) {
285
+ currentLinkType = linkType === "paypal" ? "paypal" : "ideal";
286
+ const isPaypal = currentLinkType === "paypal";
287
+ $("ideal-proxy-fields").classList.toggle("hidden", isPaypal);
288
+ $("paypal-proxy-field").classList.toggle("hidden", !isPaypal);
289
+ for (const button of modeButtons) {
290
+ const active = button.dataset.linkType === currentLinkType;
291
+ button.classList.toggle("active", active);
292
+ button.setAttribute("aria-selected", active ? "true" : "false");
293
+ }
294
+ $("page-title").textContent = `${linkLabel()} 链接提取器`;
295
+ $("page-description").textContent = isPaypal
296
+ ? "调用当前 Rust PayPal 链路;请提供美国代理种子,既有指纹和流程保持不变。"
297
+ : "固定 NL/EUR/custom/Safari。Checkout 全链路与 Promotion Update 分别使用下方两个代理池。";
298
+ $("stat-link").textContent = isPaypal ? "PayPal" : "iDEAL";
299
+ $("stat-billing").textContent = isPaypal ? "BR / USD" : "NL / EUR";
300
+ $("stat-attempts").textContent = isPaypal ? "10 轮" : "5 轮";
301
+ $("stat-route").textContent = isPaypal ? "BR → JP → BR" : "代理池依次轮换";
302
+ $("stat-proxy").textContent = isPaypal ? "单代理种子" : "双代理池";
303
+ $("stat-proxy-note").textContent = isPaypal ? "提示使用美国代理" : "输入即用于本轮链路";
304
+ generateButton.textContent = `提取 ${linkLabel()} 链`;
305
+ $("open-link").textContent = `打开 ${linkLabel()} 链`;
306
+ setStatus(isPaypal ? "请填写 PayPal Checkout 美国代理。" : "两个代理池都必须填写。");
307
+ $("result").classList.remove("show");
308
+ renderSteps([]);
309
  }
310
 
311
  function stopPolling() {
 
325
  const stepLabels = {
326
  queued: "排队",
327
  running: "开始执行",
328
+ "locked config": "固定链路配置",
329
  "proxy chain": "选择本轮代理",
330
+ checkout: "创建 Checkout",
331
  "stripe init": "初始化 Stripe",
332
  "VN promotion update": "Promotion Update",
333
  "VN promotion Stripe init": "优惠后刷新 Stripe",
334
  "iDEAL ChatGPT taxes": "同步 ChatGPT 税费",
335
  "iDEAL Stripe tax region": "同步 Stripe 税区",
336
  "iDEAL tax Stripe init": "税费后刷新 Stripe",
337
+ "payment method": "创建 PaymentMethod",
338
  "stripe confirm": "确认 Stripe",
339
  approve: "ChatGPT approve",
340
  "approve retry": "approve 重试",
341
  "stripe redirect retry": "轮询 Stripe 跳转",
342
+ "provider redirect": "解析最终支付链",
343
  "rebuild checkout": "重建 Checkout",
344
  "rebuild retry": "进入下一轮",
345
  canceled: "任务已终止",
 
381
  }
382
 
383
  function jobStatusText(job) {
384
+ if (job?.status === "running") return `正在执行完整 ${linkLabel()} 链路。`;
385
  if (job?.status === "queued") return job.position > 1 ? `排队中,前面还有 ${job.position - 1} 个任务。` : "排队中,即将开始。";
386
  return "正在处理。";
387
  }
 
395
  $("progress-state").textContent = job?.status || "running";
396
  if (job?.status === "completed") {
397
  showResult(payload.output || job.output);
398
+ setStatus(`${linkLabel()} 链提取完成。`, "ok");
399
  stopPolling();
400
  return;
401
  }
 
419
  const accessToken = tokenInput.value.trim();
420
  const checkoutPool = proxyLines(checkoutPoolInput.value);
421
  const promotionPool = proxyLines(promotionPoolInput.value);
422
+ const paypalProxy = paypalProxyInput.value.trim();
423
  if (!accessToken) return setStatus("Access Token 不能为空。", "error");
424
+ if (currentLinkType === "ideal" && !checkoutPool.length) return setStatus("iDEAL Checkout 主代理池不能为空。", "error");
425
+ if (currentLinkType === "ideal" && !promotionPool.length) return setStatus("iDEAL Promotion Update 代理池不能为空。", "error");
426
+ if (currentLinkType === "paypal" && !paypalProxy) return setStatus("PayPal Checkout 代理不能为空。", "error");
427
 
428
  $("result").classList.remove("show");
429
  renderSteps([{ name: "queued", status: "queued", detail: "正在提交任务。" }]);
 
435
  headers: { "content-type": "application/json" },
436
  body: JSON.stringify({
437
  access_token: accessToken,
438
+ link_type: currentLinkType,
439
+ checkout_proxy_pool: currentLinkType === "ideal" ? checkoutPool.join("\n") : "",
440
+ promotion_proxy_pool: currentLinkType === "ideal" ? promotionPool.join("\n") : "",
441
+ paypal_proxy: currentLinkType === "paypal" ? paypalProxy : "",
442
  }),
443
  });
444
  const payload = await readJson(response);
 
459
  tokenInput.value = "";
460
  checkoutPoolInput.value = "";
461
  promotionPoolInput.value = "";
462
+ paypalProxyInput.value = "";
463
  $("result").classList.remove("show");
464
  renderSteps([]);
465
+ setStatus(currentLinkType === "paypal" ? "请填写 PayPal Checkout 美国代理。" : "两个代理池都必须填写。");
466
  });
467
  cancelButton.addEventListener("click", async () => {
468
  if (!activeJobId) return;
 
484
  await navigator.clipboard.writeText(currentLongUrl);
485
  setStatus("链接已复制。", "ok");
486
  });
487
+ for (const button of modeButtons) {
488
+ button.addEventListener("click", () => {
489
+ if (!button.disabled) setMode(button.dataset.linkType);
490
+ });
491
+ }
492
  setBusy(false);
493
+ setMode("ideal");
494
  </script>
495
  </body>
496
  </html>
src/lib.rs CHANGED
@@ -155,6 +155,8 @@ pub struct ExtractApiInput {
155
  pub checkout_proxy_pool: String,
156
  #[serde(default)]
157
  pub promotion_proxy_pool: String,
 
 
158
  }
159
 
160
  #[derive(Debug, Clone, Serialize, PartialEq, Eq)]
@@ -1659,6 +1661,10 @@ pub enum ExtractError {
1659
  InvalidCheckoutProxy(usize),
1660
  #[error("iDEAL Promotion Update 代理池第 {0} 行格式无效。")]
1661
  InvalidPromotionProxy(usize),
 
 
 
 
1662
  #[error("任务已中断。")]
1663
  Canceled,
1664
  #[error("non-default --base-url must be localhost or loopback: {0}")]
@@ -2034,23 +2040,66 @@ fn api_queue_error(
2034
  }
2035
 
2036
  fn extract_input_for_api(input: ExtractApiInput) -> Result<ExtractInput, ExtractError> {
2037
- let checkout_proxy_pool = parse_proxy_pool(&input.checkout_proxy_pool, ProxyPoolKind::Checkout)?;
2038
- if checkout_proxy_pool.is_empty() {
2039
- return Err(ExtractError::MissingCheckoutProxyPool);
2040
- }
2041
- let promotion_proxy_pool =
2042
- parse_proxy_pool(&input.promotion_proxy_pool, ProxyPoolKind::Promotion)?;
2043
- if promotion_proxy_pool.is_empty() {
2044
- return Err(ExtractError::MissingPromotionProxyPool);
2045
- }
2046
- Ok(ExtractInput {
2047
- access_token: input.access_token,
2048
- proxy: checkout_proxy_pool[0].clone(),
2049
- checkout_proxy_pool,
2050
- promotion_proxy_pool,
2051
- base_url: String::new(),
2052
- link_type: "ideal".to_string(),
2053
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2054
  }
2055
 
2056
  #[derive(Clone, Copy)]
@@ -6113,10 +6162,15 @@ mod tests {
6113
  assert!(html.contains("id=\"access-token\""));
6114
  assert!(html.contains("id=\"checkout-proxy-pool\""));
6115
  assert!(html.contains("id=\"promotion-proxy-pool\""));
 
6116
  assert!(html.contains("iDEAL Checkout 主代理池(每行一个)"));
6117
  assert!(html.contains("iDEAL Promotion Update 代理池(每行一个)"));
 
6118
  assert!(html.contains("checkout_proxy_pool"));
6119
  assert!(html.contains("promotion_proxy_pool"));
 
 
 
6120
  assert!(html.contains("/api/extract"));
6121
  assert!(html.contains("排队中"));
6122
  assert!(html.contains("正在执行完整 iDEAL 链路"));
@@ -6125,9 +6179,8 @@ mod tests {
6125
  assert!(html.contains("/cancel"));
6126
  assert!(!html.contains("id=\"provider-proxy"));
6127
  assert!(!html.contains("providerProxy"));
6128
- assert!(!html.contains("link_type:"));
6129
  assert!(!html.contains("localStorage"));
6130
- assert!(!html.contains("PayPal"));
6131
  assert!(!html.contains("UPI"));
6132
  }
6133
 
@@ -6153,6 +6206,7 @@ mod tests {
6153
  link_type: None,
6154
  checkout_proxy_pool: "checkout.example:3010\ncheckout.example:3010".to_string(),
6155
  promotion_proxy_pool: "http://promotion.example:3010".to_string(),
 
6156
  })
6157
  .expect("both submitted pools should be accepted");
6158
 
@@ -6164,6 +6218,57 @@ mod tests {
6164
  assert_eq!(input.link_type, "ideal");
6165
  }
6166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6167
  #[test]
6168
  fn proxy_pool_parser_is_line_based_normalized_and_order_preserving() {
6169
  assert_eq!(
@@ -6193,6 +6298,7 @@ mod tests {
6193
  link_type: None,
6194
  checkout_proxy_pool: String::new(),
6195
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6196
  });
6197
  assert!(matches!(
6198
  missing_checkout,
@@ -6204,6 +6310,7 @@ mod tests {
6204
  link_type: None,
6205
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6206
  promotion_proxy_pool: String::new(),
 
6207
  });
6208
  assert!(matches!(
6209
  missing_promotion,
@@ -6238,6 +6345,7 @@ mod tests {
6238
  link_type: None,
6239
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6240
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6241
  }),
6242
  )
6243
  .await;
@@ -6263,6 +6371,7 @@ mod tests {
6263
  link_type: None,
6264
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6265
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6266
  }),
6267
  )
6268
  .await;
@@ -6299,6 +6408,7 @@ mod tests {
6299
  link_type: None,
6300
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6301
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6302
  }),
6303
  )
6304
  .await;
@@ -6313,6 +6423,7 @@ mod tests {
6313
  link_type: None,
6314
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6315
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6316
  }),
6317
  )
6318
  .await;
@@ -6336,6 +6447,7 @@ mod tests {
6336
  link_type: None,
6337
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6338
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6339
  }),
6340
  )
6341
  .await;
@@ -6359,6 +6471,7 @@ mod tests {
6359
  link_type: None,
6360
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6361
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6362
  }),
6363
  )
6364
  .await;
@@ -6383,6 +6496,7 @@ mod tests {
6383
  link_type: None,
6384
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6385
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6386
  }),
6387
  )
6388
  .await;
@@ -6579,6 +6693,7 @@ mod tests {
6579
  link_type: None,
6580
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6581
  promotion_proxy_pool: "promotion.example:3010".to_string(),
 
6582
  },
6583
  )
6584
  .expect("valid pools should be accepted");
 
155
  pub checkout_proxy_pool: String,
156
  #[serde(default)]
157
  pub promotion_proxy_pool: String,
158
+ #[serde(default)]
159
+ pub paypal_proxy: String,
160
  }
161
 
162
  #[derive(Debug, Clone, Serialize, PartialEq, Eq)]
 
1661
  InvalidCheckoutProxy(usize),
1662
  #[error("iDEAL Promotion Update 代理池第 {0} 行格式无效。")]
1663
  InvalidPromotionProxy(usize),
1664
+ #[error("PayPal Checkout 代理不能为空。")]
1665
+ MissingPaypalProxy,
1666
+ #[error("PayPal Checkout 代理格式无效。")]
1667
+ InvalidPaypalProxy,
1668
  #[error("任务已中断。")]
1669
  Canceled,
1670
  #[error("non-default --base-url must be localhost or loopback: {0}")]
 
2040
  }
2041
 
2042
  fn extract_input_for_api(input: ExtractApiInput) -> Result<ExtractInput, ExtractError> {
2043
+ let link_type = input
2044
+ .link_type
2045
+ .as_deref()
2046
+ .unwrap_or("ideal")
2047
+ .trim()
2048
+ .to_ascii_lowercase();
2049
+ match link_type.as_str() {
2050
+ "" | "ideal" => {
2051
+ let checkout_proxy_pool =
2052
+ parse_proxy_pool(&input.checkout_proxy_pool, ProxyPoolKind::Checkout)?;
2053
+ if checkout_proxy_pool.is_empty() {
2054
+ return Err(ExtractError::MissingCheckoutProxyPool);
2055
+ }
2056
+ let promotion_proxy_pool =
2057
+ parse_proxy_pool(&input.promotion_proxy_pool, ProxyPoolKind::Promotion)?;
2058
+ if promotion_proxy_pool.is_empty() {
2059
+ return Err(ExtractError::MissingPromotionProxyPool);
2060
+ }
2061
+ Ok(ExtractInput {
2062
+ access_token: input.access_token,
2063
+ proxy: checkout_proxy_pool[0].clone(),
2064
+ checkout_proxy_pool,
2065
+ promotion_proxy_pool,
2066
+ base_url: String::new(),
2067
+ link_type: "ideal".to_string(),
2068
+ })
2069
+ }
2070
+ "paypal" => {
2071
+ let paypal_proxy = parse_paypal_proxy(&input.paypal_proxy)?;
2072
+ Ok(ExtractInput {
2073
+ access_token: input.access_token,
2074
+ proxy: paypal_proxy,
2075
+ checkout_proxy_pool: Vec::new(),
2076
+ promotion_proxy_pool: Vec::new(),
2077
+ base_url: String::new(),
2078
+ link_type: "paypal".to_string(),
2079
+ })
2080
+ }
2081
+ other => Err(ExtractError::BadResponse(format!(
2082
+ "unsupported link_type: {other}"
2083
+ ))),
2084
+ }
2085
+ }
2086
+
2087
+ fn parse_paypal_proxy(text: &str) -> Result<String, ExtractError> {
2088
+ let mut lines = text.lines().map(str::trim).filter(|line| !line.is_empty());
2089
+ let Some(line) = lines.next() else {
2090
+ return Err(ExtractError::MissingPaypalProxy);
2091
+ };
2092
+ if lines.next().is_some() {
2093
+ return Err(ExtractError::InvalidPaypalProxy);
2094
+ }
2095
+ let proxy = normalize_proxy_url_for_reqwest(line);
2096
+ if proxy.is_empty() {
2097
+ return Err(ExtractError::MissingPaypalProxy);
2098
+ }
2099
+ if reqwest::Proxy::all(&proxy).is_err() {
2100
+ return Err(ExtractError::InvalidPaypalProxy);
2101
+ }
2102
+ Ok(proxy)
2103
  }
2104
 
2105
  #[derive(Clone, Copy)]
 
6162
  assert!(html.contains("id=\"access-token\""));
6163
  assert!(html.contains("id=\"checkout-proxy-pool\""));
6164
  assert!(html.contains("id=\"promotion-proxy-pool\""));
6165
+ assert!(html.contains("id=\"paypal-proxy\""));
6166
  assert!(html.contains("iDEAL Checkout 主代理池(每行一个)"));
6167
  assert!(html.contains("iDEAL Promotion Update 代理池(每行一个)"));
6168
+ assert!(html.contains("PayPal Checkout 代理(请使用美国代理)"));
6169
  assert!(html.contains("checkout_proxy_pool"));
6170
  assert!(html.contains("promotion_proxy_pool"));
6171
+ assert!(html.contains("paypal_proxy"));
6172
+ assert!(html.contains("data-link-type=\"ideal\""));
6173
+ assert!(html.contains("data-link-type=\"paypal\""));
6174
  assert!(html.contains("/api/extract"));
6175
  assert!(html.contains("排队中"));
6176
  assert!(html.contains("正在执行完整 iDEAL 链路"));
 
6179
  assert!(html.contains("/cancel"));
6180
  assert!(!html.contains("id=\"provider-proxy"));
6181
  assert!(!html.contains("providerProxy"));
6182
+ assert!(html.contains("link_type: currentLinkType"));
6183
  assert!(!html.contains("localStorage"));
 
6184
  assert!(!html.contains("UPI"));
6185
  }
6186
 
 
6206
  link_type: None,
6207
  checkout_proxy_pool: "checkout.example:3010\ncheckout.example:3010".to_string(),
6208
  promotion_proxy_pool: "http://promotion.example:3010".to_string(),
6209
+ paypal_proxy: String::new(),
6210
  })
6211
  .expect("both submitted pools should be accepted");
6212
 
 
6218
  assert_eq!(input.link_type, "ideal");
6219
  }
6220
 
6221
+ #[test]
6222
+ fn api_input_exposes_existing_paypal_single_proxy_path() {
6223
+ let input = extract_input_for_api(ExtractApiInput {
6224
+ access_token: "at_test".to_string(),
6225
+ link_type: Some("paypal".to_string()),
6226
+ checkout_proxy_pool: String::new(),
6227
+ promotion_proxy_pool: String::new(),
6228
+ paypal_proxy: "us-proxy.example:3010".to_string(),
6229
+ })
6230
+ .expect("valid PayPal proxy should be accepted");
6231
+
6232
+ assert_eq!(input.proxy, "http://us-proxy.example:3010");
6233
+ assert!(input.checkout_proxy_pool.is_empty());
6234
+ assert!(input.promotion_proxy_pool.is_empty());
6235
+ assert_eq!(input.link_type, "paypal");
6236
+ }
6237
+
6238
+ #[test]
6239
+ fn api_input_rejects_missing_invalid_paypal_proxy_and_unknown_link_type() {
6240
+ let missing = extract_input_for_api(ExtractApiInput {
6241
+ access_token: "at_test".to_string(),
6242
+ link_type: Some("paypal".to_string()),
6243
+ checkout_proxy_pool: String::new(),
6244
+ promotion_proxy_pool: String::new(),
6245
+ paypal_proxy: String::new(),
6246
+ });
6247
+ assert!(matches!(missing, Err(ExtractError::MissingPaypalProxy)));
6248
+
6249
+ let invalid = extract_input_for_api(ExtractApiInput {
6250
+ access_token: "at_test".to_string(),
6251
+ link_type: Some("paypal".to_string()),
6252
+ checkout_proxy_pool: String::new(),
6253
+ promotion_proxy_pool: String::new(),
6254
+ paypal_proxy: "secret-user:secret-pass@bad host:3010".to_string(),
6255
+ });
6256
+ assert!(matches!(&invalid, Err(ExtractError::InvalidPaypalProxy)));
6257
+ assert!(!invalid.unwrap_err().to_string().contains("secret-user"));
6258
+
6259
+ let unsupported = extract_input_for_api(ExtractApiInput {
6260
+ access_token: "at_test".to_string(),
6261
+ link_type: Some("upi".to_string()),
6262
+ checkout_proxy_pool: String::new(),
6263
+ promotion_proxy_pool: String::new(),
6264
+ paypal_proxy: String::new(),
6265
+ });
6266
+ assert!(matches!(
6267
+ unsupported,
6268
+ Err(ExtractError::BadResponse(ref detail)) if detail == "unsupported link_type: upi"
6269
+ ));
6270
+ }
6271
+
6272
  #[test]
6273
  fn proxy_pool_parser_is_line_based_normalized_and_order_preserving() {
6274
  assert_eq!(
 
6298
  link_type: None,
6299
  checkout_proxy_pool: String::new(),
6300
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6301
+ paypal_proxy: String::new(),
6302
  });
6303
  assert!(matches!(
6304
  missing_checkout,
 
6310
  link_type: None,
6311
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6312
  promotion_proxy_pool: String::new(),
6313
+ paypal_proxy: String::new(),
6314
  });
6315
  assert!(matches!(
6316
  missing_promotion,
 
6345
  link_type: None,
6346
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6347
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6348
+ paypal_proxy: String::new(),
6349
  }),
6350
  )
6351
  .await;
 
6371
  link_type: None,
6372
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6373
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6374
+ paypal_proxy: String::new(),
6375
  }),
6376
  )
6377
  .await;
 
6408
  link_type: None,
6409
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6410
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6411
+ paypal_proxy: String::new(),
6412
  }),
6413
  )
6414
  .await;
 
6423
  link_type: None,
6424
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6425
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6426
+ paypal_proxy: String::new(),
6427
  }),
6428
  )
6429
  .await;
 
6447
  link_type: None,
6448
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6449
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6450
+ paypal_proxy: String::new(),
6451
  }),
6452
  )
6453
  .await;
 
6471
  link_type: None,
6472
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6473
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6474
+ paypal_proxy: String::new(),
6475
  }),
6476
  )
6477
  .await;
 
6496
  link_type: None,
6497
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6498
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6499
+ paypal_proxy: String::new(),
6500
  }),
6501
  )
6502
  .await;
 
6693
  link_type: None,
6694
  checkout_proxy_pool: "checkout.example:3010".to_string(),
6695
  promotion_proxy_pool: "promotion.example:3010".to_string(),
6696
+ paypal_proxy: String::new(),
6697
  },
6698
  )
6699
  .expect("valid pools should be accepted");