axm0121 commited on
Commit
d59ccb9
·
verified ·
1 Parent(s): 0db1bb9

Rollback to pre-HAR-flow deployment

Browse files

Restores the Space runtime to revision 89023bafdadab2fa791d9384f5a19e4ef75bb1c0, the version before the HAR-flow alignment deployment.

Files changed (3) hide show
  1. README.md +2 -7
  2. app.py +61 -188
  3. public/index.html +1 -1
README.md CHANGED
@@ -56,9 +56,6 @@ docker compose down
56
  - The page `proxy` / `providerProxy` value is the provider-stage proxy for the selected region. After checkout it is applied to ChatGPT approval plus Stripe provider-stage requests: init, payment method, confirm, redirect polling, and redirect resolution.
57
  - If the page proxy is blank, the provider stage also uses the server's local outbound route.
58
  - Proxy values may be entered with or without `http://`; when no scheme is present, the server automatically treats it as `http://...`.
59
- - PayPal extraction now forces ChatGPT checkout creation to `checkout_ui_mode=custom`, matching the successful HAR flow where the final result reported `skip_stripe_page=true` and returned a PayPal approval URL after following a Stripe `pm-redirects` URL.
60
- - Provider extraction retries the full checkout/init/payment-method/confirm/approve/poll sequence up to `OPENAI_PAY_PROVIDER_ATTEMPTS` times (default: 10, clamped to 1–10) before falling back to the hosted URL.
61
- - curl_cffi sessions default to `OPENAI_PAY_CURL_IMPERSONATE=chrome142`, matching the fingerprint family observed in the successful HAR progress logs. Override the environment variable if your installed curl_cffi build needs another supported profile.
62
 
63
  This mirrors the `opll` two-stage model: checkout can use a local/checkout route, then the post-checkout provider stage can switch to the US provider route.
64
 
@@ -116,7 +113,6 @@ Content-Type: application/json
116
  "proxy": "http://user:pass@host:port",
117
  "providerProxy": "http://user:pass@host:port",
118
  "billing_country": "US",
119
- "checkout_ui_mode": "custom",
120
  "payment_locale": "en",
121
  "stripe_publishable_key": ""
122
  }
@@ -141,9 +137,8 @@ https://checkout.stripe.com -> https://pay.openai.com
141
  - `paypal` + `billing_country=AU`: AU test behavior based on the latest
142
  finding — `AU/AUD` checkout and AU PayPal PaymentMethod billing profile.
143
 
144
- If Stripe provider redirect extraction fails across all configured attempts but
145
- the hosted checkout URL exists, the API falls back to the hosted long link and
146
- returns `fallback: true`, `extract_status: "FALLBACK_HOSTED"`, and
147
  `provider_error`.
148
 
149
  ## Troubleshooting
 
56
  - The page `proxy` / `providerProxy` value is the provider-stage proxy for the selected region. After checkout it is applied to ChatGPT approval plus Stripe provider-stage requests: init, payment method, confirm, redirect polling, and redirect resolution.
57
  - If the page proxy is blank, the provider stage also uses the server's local outbound route.
58
  - Proxy values may be entered with or without `http://`; when no scheme is present, the server automatically treats it as `http://...`.
 
 
 
59
 
60
  This mirrors the `opll` two-stage model: checkout can use a local/checkout route, then the post-checkout provider stage can switch to the US provider route.
61
 
 
113
  "proxy": "http://user:pass@host:port",
114
  "providerProxy": "http://user:pass@host:port",
115
  "billing_country": "US",
 
116
  "payment_locale": "en",
117
  "stripe_publishable_key": ""
118
  }
 
137
  - `paypal` + `billing_country=AU`: AU test behavior based on the latest
138
  finding — `AU/AUD` checkout and AU PayPal PaymentMethod billing profile.
139
 
140
+ If Stripe provider redirect extraction fails but the hosted checkout URL exists,
141
+ the API falls back to the hosted long link and returns `fallback: true` plus
 
142
  `provider_error`.
143
 
144
  ## Troubleshooting
app.py CHANGED
@@ -37,12 +37,6 @@ DEFAULT_TIMEOUT = 30
37
  BASE_DIR = Path(__file__).resolve().parent
38
  PUBLIC_DIR = BASE_DIR / "public"
39
  PAYPAL_HOST_SUFFIXES = ("paypal.com", "paypalobjects.com")
40
- DEFAULT_CHECKOUT_UI_MODE = "custom"
41
- DEFAULT_CURL_IMPERSONATE = os.getenv("OPENAI_PAY_CURL_IMPERSONATE", "chrome142").strip() or "chrome142"
42
- try:
43
- DEFAULT_PROVIDER_ATTEMPTS = max(1, min(10, int(os.getenv("OPENAI_PAY_PROVIDER_ATTEMPTS", "10") or "10")))
44
- except ValueError:
45
- DEFAULT_PROVIDER_ATTEMPTS = 10
46
  LOG_LEVEL = os.getenv("OPENAI_PAY_LOG_LEVEL", "INFO").strip().upper() or "INFO"
47
  logging.basicConfig(
48
  level=getattr(logging, LOG_LEVEL, logging.INFO),
@@ -55,7 +49,7 @@ APP_USERNAME = os.getenv("APP_USERNAME", "admin")
55
  APP_PASSWORD = os.getenv("APP_PASSWORD", "")
56
  DEFAULT_USER_AGENT = (
57
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
58
- "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
59
  )
60
  DEFAULT_STRIPE_RUNTIME_VERSION = "6f8494a281"
61
  JAPAN_BILLING_NAMES = [
@@ -158,7 +152,7 @@ class LongLinkRequest(BaseModel):
158
  provider_proxy: str = Field("", alias="providerProxy")
159
  stripe_publishable_key: str = ""
160
  billing_country: str = "US"
161
- checkout_ui_mode: str = DEFAULT_CHECKOUT_UI_MODE
162
  payment_locale: str = "en"
163
  link_type: str = "paypal"
164
  device_id: str = ""
@@ -181,18 +175,6 @@ class LongLinkResponse(BaseModel):
181
  provider_error: str = ""
182
  stripe_hosted_url: str
183
  long_url: str
184
- skip_stripe_page: bool = False
185
- extract_status: str = ""
186
- openai_payurl: str = ""
187
- payment_amount_known: bool = False
188
- payment_amount_minor: int = 0
189
- payment_amount_display: str = ""
190
- payment_amount_nonzero: bool = False
191
- payment_amount_source: str = ""
192
- checkout_url: str = ""
193
- chatgpt_checkout_url: str = ""
194
- provider_proxy_attempts: int = 1
195
- provider_proxy_pool_used: bool = False
196
 
197
 
198
  class LongLinkTaskStartResponse(BaseModel):
@@ -407,13 +389,7 @@ def http_error_detail(label: str, response: Any) -> str:
407
 
408
  def new_session() -> Any:
409
  if CurlCffiSession is not None:
410
- try:
411
- return CurlCffiSession(impersonate=DEFAULT_CURL_IMPERSONATE)
412
- except Exception:
413
- try:
414
- return CurlCffiSession(impersonate="chrome136")
415
- except Exception:
416
- return CurlCffiSession()
417
  return requests.Session()
418
 
419
 
@@ -481,23 +457,6 @@ def normalize_link_type(link_type: str) -> str:
481
  return aliases.get(value, "paypal")
482
 
483
 
484
- def normalize_checkout_ui_mode(mode: str) -> str:
485
- value = str(mode or DEFAULT_CHECKOUT_UI_MODE).strip().lower()
486
- if value in {"custom", "hosted"}:
487
- return value
488
- return DEFAULT_CHECKOUT_UI_MODE
489
-
490
-
491
- def effective_checkout_ui_mode(req: LongLinkRequest) -> str:
492
- # The HAR success path reports `checkout_ui_mode=custom` even when account
493
- # defaults expose hosted-style settings. Force custom for PP extraction so
494
- # old UI/API callers that still submit "hosted" do not recreate the stalled
495
- # requires_approval/no-redirect flow.
496
- if normalize_link_type(req.link_type) == "paypal":
497
- return "custom"
498
- return normalize_checkout_ui_mode(req.checkout_ui_mode)
499
-
500
-
501
  def effective_country(req: LongLinkRequest) -> str:
502
  return normalize_checkout_country(req.billing_country)
503
 
@@ -580,7 +539,7 @@ def build_chatgpt_session(req: LongLinkRequest) -> Any:
580
  "Content-Type": "application/json",
581
  "oai-device-id": device_id,
582
  "oai-language": "en-US",
583
- "sec-ch-ua": '"Google Chrome";v="142", "Not.A/Brand";v="8", "Chromium";v="142"',
584
  "sec-ch-ua-mobile": "?0",
585
  "sec-ch-ua-platform": '"Windows"',
586
  "sec-fetch-dest": "empty",
@@ -599,7 +558,7 @@ def build_chatgpt_session(req: LongLinkRequest) -> Any:
599
  def create_checkout(req: LongLinkRequest, chatgpt_session: Any | None = None) -> dict[str, Any]:
600
  billing_country = effective_country(req)
601
  currency = currency_for_country(billing_country)
602
- checkout_ui_mode = effective_checkout_ui_mode(req)
603
  checkout_proxy_configured = bool(
604
  getattr(chatgpt_session, "proxies", {}) if chatgpt_session is not None else checkout_stage_proxy(req)
605
  )
@@ -670,9 +629,6 @@ def create_checkout(req: LongLinkRequest, chatgpt_session: Any | None = None) ->
670
  "processor_entity": processor_entity,
671
  "billing_country": billing_country,
672
  "currency": currency,
673
- "checkout_ui_mode": str(data.get("checkout_ui_mode") or checkout_ui_mode),
674
- "requires_manual_approval": bool(data.get("requires_manual_approval")),
675
- "url": str(data.get("url") or ""),
676
  }
677
 
678
 
@@ -797,15 +753,15 @@ def stripe_confirm_return_url(cs_id: str, checkout: dict[str, Any], stripe_hoste
797
  return hosted_url
798
 
799
 
800
- def expected_amount_info(init_payload: Any) -> tuple[str, str]:
801
  if not isinstance(init_payload, dict):
802
- return "0", "fallback"
803
  total_summary = init_payload.get("total_summary")
804
  if isinstance(total_summary, dict) and total_summary.get("due") is not None:
805
- return str(total_summary.get("due")), "total_summary.due"
806
  invoice = init_payload.get("invoice")
807
  if isinstance(invoice, dict) and invoice.get("amount_due") is not None:
808
- return str(invoice.get("amount_due")), "invoice.amount_due"
809
  line_items = init_payload.get("line_items")
810
  if isinstance(line_items, list):
811
  total = 0
@@ -818,29 +774,8 @@ def expected_amount_info(init_payload: Any) -> tuple[str, str]:
818
  except Exception:
819
  pass
820
  if found:
821
- return str(total), "line_items.amount"
822
- return "0", "fallback"
823
-
824
-
825
- def expected_amount(init_payload: Any) -> str:
826
- amount, _source = expected_amount_info(init_payload)
827
- return amount
828
-
829
-
830
- def payment_amount_contract(init_payload: Any, currency: str) -> dict[str, Any]:
831
- amount_text, source = expected_amount_info(init_payload)
832
- try:
833
- amount_minor = int(amount_text)
834
- except Exception:
835
- amount_minor = 0
836
- currency_code = str(currency or "").upper() or "USD"
837
- return {
838
- "payment_amount_known": source != "fallback",
839
- "payment_amount_minor": amount_minor,
840
- "payment_amount_display": f"{currency_code} {amount_minor / 100:.2f}",
841
- "payment_amount_nonzero": amount_minor != 0,
842
- "payment_amount_source": source,
843
- }
844
 
845
 
846
  def stripe_context(cs_id: str, init_payload: dict[str, Any], req: LongLinkRequest) -> dict[str, Any]:
@@ -1577,9 +1512,6 @@ def build_long_link_response(req: LongLinkRequest, progress: Any | None = None,
1577
 
1578
  try:
1579
  link_type = normalize_link_type(req.link_type)
1580
- checkout_ui_mode = effective_checkout_ui_mode(req)
1581
- provider_attempt_limit = DEFAULT_PROVIDER_ATTEMPTS
1582
- post_checkout_proxy = provider_stage_proxy(req)
1583
  advance(8, "读取 Token", "已读取参数,准备创建 OpenAI Checkout")
1584
  log_info(
1585
  "api.long_link.start",
@@ -1589,117 +1521,69 @@ def build_long_link_response(req: LongLinkRequest, progress: Any | None = None,
1589
  effective_billing_country=effective_country(req),
1590
  currency=currency_for_country(effective_country(req)),
1591
  payment_locale=req.payment_locale,
1592
- checkout_ui_mode=checkout_ui_mode,
1593
- submitted_checkout_ui_mode=req.checkout_ui_mode,
1594
- provider_attempt_limit=provider_attempt_limit,
1595
  checkout_proxy_configured=bool(checkout_stage_proxy(req)),
1596
  checkout_proxy=checkout_stage_proxy(req),
1597
- provider_proxy_configured=bool(post_checkout_proxy),
1598
- provider_proxy=post_checkout_proxy,
1599
  custom_stripe_pk=bool(req.stripe_publishable_key.strip()),
1600
  custom_device_id=bool(req.device_id.strip()),
1601
  custom_user_agent=bool(req.user_agent.strip()),
1602
- curl_impersonate=DEFAULT_CURL_IMPERSONATE,
1603
  )
1604
-
1605
- checkout: dict[str, Any] | None = None
1606
- init_payload: dict[str, Any] = {}
1607
- stripe_hosted_url = ""
1608
- hosted_long_url = ""
 
 
 
 
 
 
 
 
 
 
1609
  provider = {
1610
  "payment_method_id": "",
1611
  "stripe_redirect_url": "",
1612
  "provider_redirect_url": "",
1613
- "long_url": "",
1614
  }
1615
  fallback = False
1616
  provider_error = ""
1617
- provider_attempts_used = 0
1618
-
1619
- for attempt in range(1, provider_attempt_limit + 1):
1620
- provider_attempts_used = attempt
1621
- log_info(
1622
- "api.provider_attempt.start",
1623
- attempt=attempt,
1624
- max_attempts=provider_attempt_limit,
1625
- checkout_ui_mode=checkout_ui_mode,
1626
  )
1627
- chatgpt = build_chatgpt_session(req)
1628
- advance(18, "OpenAI Checkout", f"正在创建 Checkout(尝试 {attempt}/{provider_attempt_limit})")
1629
- checkout = create_checkout(req, chatgpt)
1630
- apply_provider_proxy(chatgpt, post_checkout_proxy)
1631
- advance(40, "Stripe init", "正在初始化 Stripe 支付页")
1632
- init_payload = stripe_init(checkout["cs_id"], req, proxy_override=post_checkout_proxy)
1633
- stripe_hosted_url = str(init_payload.get("stripe_hosted_url") or "").strip()
1634
- if not stripe_hosted_url:
1635
- detail = f"stripe init response missing stripe_hosted_url, keys={response_keys(init_payload)}"
1636
- log_warning("stripe.init.missing_hosted_url", detail=detail)
1637
- raise HTTPException(status_code=502, detail=detail)
1638
- hosted_long_url = to_openai_pay_url(stripe_hosted_url)
1639
- log_info("api.hosted_url.ready", stripe_hosted_url=stripe_hosted_url, hosted_long_url=hosted_long_url)
1640
- advance(55, "重写长链", "已获得 hosted 长链,正在提取 PP 链")
1641
- provider = {
1642
- "payment_method_id": "",
1643
- "stripe_redirect_url": "",
1644
- "provider_redirect_url": "",
1645
- "long_url": hosted_long_url,
1646
- }
1647
- fallback = False
1648
- provider_error = ""
1649
- try:
1650
- advance(65, "Provider", f"正在创建 PayPal 支付方式并确认(尝试 {attempt}/{provider_attempt_limit})")
1651
- provider = create_provider_link(
1652
- chatgpt,
1653
- checkout,
1654
- init_payload,
1655
- stripe_hosted_url,
1656
- req,
1657
- provider_proxy=post_checkout_proxy,
1658
- )
1659
- advance(92, "Provider", "已获得 PP 跳转链接")
1660
- break
1661
- except HTTPException as exc:
1662
- fallback = True
1663
- provider_error = str(exc.detail)
1664
- will_retry = attempt < provider_attempt_limit
1665
- log_warning(
1666
- "provider.create.attempt_http_exception",
1667
- attempt=attempt,
1668
- max_attempts=provider_attempt_limit,
1669
- will_retry=will_retry,
1670
- status_code=exc.status_code,
1671
- detail=provider_error,
1672
- fallback_url=hosted_long_url,
1673
- )
1674
- if not will_retry:
1675
- advance(92, "回退 hosted", "PP 提取失败,返回 hosted 长链")
1676
- break
1677
- advance(72, "Provider", f"第 {attempt}/{provider_attempt_limit} 次未拿到 PP,重试全流程")
1678
- time.sleep(0.5)
1679
- except Exception as exc:
1680
- fallback = True
1681
- provider_error = repr(exc)
1682
- will_retry = attempt < provider_attempt_limit
1683
- log_warning(
1684
- "provider.create.attempt_exception",
1685
- attempt=attempt,
1686
- max_attempts=provider_attempt_limit,
1687
- will_retry=will_retry,
1688
- error=provider_error,
1689
- fallback_url=hosted_long_url,
1690
- )
1691
- if not will_retry:
1692
- advance(92, "回退 hosted", "PP 提取异常,返回 hosted 长链")
1693
- break
1694
- advance(72, "Provider", f"第 {attempt}/{provider_attempt_limit} 次异常,重试全流程")
1695
- time.sleep(0.5)
1696
-
1697
- if checkout is None:
1698
- raise HTTPException(status_code=502, detail="checkout flow did not produce a checkout session")
1699
-
1700
- amount_contract = payment_amount_contract(init_payload, checkout["currency"])
1701
- checkout_url = f"https://chatgpt.com/checkout/{checkout['processor_entity']}/{checkout['cs_id']}"
1702
- skip_stripe_page = not fallback and bool(provider.get("long_url"))
1703
  response_payload = LongLinkResponse(
1704
  ok=True,
1705
  cs_id=checkout["cs_id"],
@@ -1713,25 +1597,14 @@ def build_long_link_response(req: LongLinkRequest, progress: Any | None = None,
1713
  stripe_redirect_url=provider["stripe_redirect_url"],
1714
  provider_redirect_url=provider["provider_redirect_url"],
1715
  fallback=fallback,
1716
- provider_error=provider_error if fallback else "",
1717
  stripe_hosted_url=stripe_hosted_url,
1718
  long_url=provider["long_url"] or hosted_long_url,
1719
- skip_stripe_page=skip_stripe_page,
1720
- extract_status="OK" if not fallback else "FALLBACK_HOSTED",
1721
- openai_payurl=hosted_long_url,
1722
- checkout_url=checkout_url,
1723
- chatgpt_checkout_url=checkout_url,
1724
- provider_proxy_attempts=provider_attempts_used,
1725
- provider_proxy_pool_used=provider_attempt_limit > 1,
1726
- **amount_contract,
1727
  )
1728
  log_info(
1729
  "api.long_link.done",
1730
  elapsed_ms=elapsed_ms(started),
1731
  fallback=fallback,
1732
- extract_status=response_payload.extract_status,
1733
- skip_stripe_page=response_payload.skip_stripe_page,
1734
- provider_attempts=provider_attempts_used,
1735
  cs_id=response_payload.cs_id,
1736
  payment_method_id=response_payload.payment_method_id,
1737
  provider_redirect_url=response_payload.provider_redirect_url,
 
37
  BASE_DIR = Path(__file__).resolve().parent
38
  PUBLIC_DIR = BASE_DIR / "public"
39
  PAYPAL_HOST_SUFFIXES = ("paypal.com", "paypalobjects.com")
 
 
 
 
 
 
40
  LOG_LEVEL = os.getenv("OPENAI_PAY_LOG_LEVEL", "INFO").strip().upper() or "INFO"
41
  logging.basicConfig(
42
  level=getattr(logging, LOG_LEVEL, logging.INFO),
 
49
  APP_PASSWORD = os.getenv("APP_PASSWORD", "")
50
  DEFAULT_USER_AGENT = (
51
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
52
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36"
53
  )
54
  DEFAULT_STRIPE_RUNTIME_VERSION = "6f8494a281"
55
  JAPAN_BILLING_NAMES = [
 
152
  provider_proxy: str = Field("", alias="providerProxy")
153
  stripe_publishable_key: str = ""
154
  billing_country: str = "US"
155
+ checkout_ui_mode: str = "hosted"
156
  payment_locale: str = "en"
157
  link_type: str = "paypal"
158
  device_id: str = ""
 
175
  provider_error: str = ""
176
  stripe_hosted_url: str
177
  long_url: str
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
 
180
  class LongLinkTaskStartResponse(BaseModel):
 
389
 
390
  def new_session() -> Any:
391
  if CurlCffiSession is not None:
392
+ return CurlCffiSession(impersonate="chrome136")
 
 
 
 
 
 
393
  return requests.Session()
394
 
395
 
 
457
  return aliases.get(value, "paypal")
458
 
459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  def effective_country(req: LongLinkRequest) -> str:
461
  return normalize_checkout_country(req.billing_country)
462
 
 
539
  "Content-Type": "application/json",
540
  "oai-device-id": device_id,
541
  "oai-language": "en-US",
542
+ "sec-ch-ua": '"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"',
543
  "sec-ch-ua-mobile": "?0",
544
  "sec-ch-ua-platform": '"Windows"',
545
  "sec-fetch-dest": "empty",
 
558
  def create_checkout(req: LongLinkRequest, chatgpt_session: Any | None = None) -> dict[str, Any]:
559
  billing_country = effective_country(req)
560
  currency = currency_for_country(billing_country)
561
+ checkout_ui_mode = (req.checkout_ui_mode or "hosted").strip() or "hosted"
562
  checkout_proxy_configured = bool(
563
  getattr(chatgpt_session, "proxies", {}) if chatgpt_session is not None else checkout_stage_proxy(req)
564
  )
 
629
  "processor_entity": processor_entity,
630
  "billing_country": billing_country,
631
  "currency": currency,
 
 
 
632
  }
633
 
634
 
 
753
  return hosted_url
754
 
755
 
756
+ def expected_amount(init_payload: Any) -> str:
757
  if not isinstance(init_payload, dict):
758
+ return "0"
759
  total_summary = init_payload.get("total_summary")
760
  if isinstance(total_summary, dict) and total_summary.get("due") is not None:
761
+ return str(total_summary.get("due"))
762
  invoice = init_payload.get("invoice")
763
  if isinstance(invoice, dict) and invoice.get("amount_due") is not None:
764
+ return str(invoice.get("amount_due"))
765
  line_items = init_payload.get("line_items")
766
  if isinstance(line_items, list):
767
  total = 0
 
774
  except Exception:
775
  pass
776
  if found:
777
+ return str(total)
778
+ return "0"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779
 
780
 
781
  def stripe_context(cs_id: str, init_payload: dict[str, Any], req: LongLinkRequest) -> dict[str, Any]:
 
1512
 
1513
  try:
1514
  link_type = normalize_link_type(req.link_type)
 
 
 
1515
  advance(8, "读取 Token", "已读取参数,准备创建 OpenAI Checkout")
1516
  log_info(
1517
  "api.long_link.start",
 
1521
  effective_billing_country=effective_country(req),
1522
  currency=currency_for_country(effective_country(req)),
1523
  payment_locale=req.payment_locale,
1524
+ checkout_ui_mode=req.checkout_ui_mode,
 
 
1525
  checkout_proxy_configured=bool(checkout_stage_proxy(req)),
1526
  checkout_proxy=checkout_stage_proxy(req),
1527
+ provider_proxy_configured=bool(provider_stage_proxy(req)),
1528
+ provider_proxy=provider_stage_proxy(req),
1529
  custom_stripe_pk=bool(req.stripe_publishable_key.strip()),
1530
  custom_device_id=bool(req.device_id.strip()),
1531
  custom_user_agent=bool(req.user_agent.strip()),
 
1532
  )
1533
+ chatgpt = build_chatgpt_session(req)
1534
+ advance(18, "OpenAI Checkout", "正在创建 Checkout")
1535
+ checkout = create_checkout(req, chatgpt)
1536
+ post_checkout_proxy = provider_stage_proxy(req)
1537
+ apply_provider_proxy(chatgpt, post_checkout_proxy)
1538
+ advance(40, "Stripe init", "正在初始化 Stripe 支付页")
1539
+ init_payload = stripe_init(checkout["cs_id"], req, proxy_override=post_checkout_proxy)
1540
+ stripe_hosted_url = str(init_payload.get("stripe_hosted_url") or "").strip()
1541
+ if not stripe_hosted_url:
1542
+ detail = f"stripe init response missing stripe_hosted_url, keys={response_keys(init_payload)}"
1543
+ log_warning("stripe.init.missing_hosted_url", detail=detail)
1544
+ raise HTTPException(status_code=502, detail=detail)
1545
+ hosted_long_url = to_openai_pay_url(stripe_hosted_url)
1546
+ log_info("api.hosted_url.ready", stripe_hosted_url=stripe_hosted_url, hosted_long_url=hosted_long_url)
1547
+ advance(55, "重写长链", "已获得 hosted 长链,正在提取 PP 链")
1548
  provider = {
1549
  "payment_method_id": "",
1550
  "stripe_redirect_url": "",
1551
  "provider_redirect_url": "",
1552
+ "long_url": hosted_long_url,
1553
  }
1554
  fallback = False
1555
  provider_error = ""
1556
+ try:
1557
+ advance(65, "Provider", "正在创建 PayPal 支付方式并确认")
1558
+ provider = create_provider_link(
1559
+ chatgpt,
1560
+ checkout,
1561
+ init_payload,
1562
+ stripe_hosted_url,
1563
+ req,
1564
+ provider_proxy=post_checkout_proxy,
1565
  )
1566
+ advance(92, "Provider", "已获得 PP 跳转链接")
1567
+ except HTTPException as exc:
1568
+ fallback = True
1569
+ provider_error = str(exc.detail)
1570
+ advance(92, "回退 hosted", "PP 提取失败,返回 hosted 长链")
1571
+ log_warning(
1572
+ "provider.create.fallback_http_exception",
1573
+ status_code=exc.status_code,
1574
+ detail=provider_error,
1575
+ fallback_url=hosted_long_url,
1576
+ )
1577
+ except Exception as exc:
1578
+ fallback = True
1579
+ provider_error = repr(exc)
1580
+ advance(92, "回退 hosted", "PP 提取异常,返回 hosted 长链")
1581
+ log_warning(
1582
+ "provider.create.fallback_exception",
1583
+ error=provider_error,
1584
+ fallback_url=hosted_long_url,
1585
+ )
1586
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1587
  response_payload = LongLinkResponse(
1588
  ok=True,
1589
  cs_id=checkout["cs_id"],
 
1597
  stripe_redirect_url=provider["stripe_redirect_url"],
1598
  provider_redirect_url=provider["provider_redirect_url"],
1599
  fallback=fallback,
1600
+ provider_error=provider_error,
1601
  stripe_hosted_url=stripe_hosted_url,
1602
  long_url=provider["long_url"] or hosted_long_url,
 
 
 
 
 
 
 
 
1603
  )
1604
  log_info(
1605
  "api.long_link.done",
1606
  elapsed_ms=elapsed_ms(started),
1607
  fallback=fallback,
 
 
 
1608
  cs_id=response_payload.cs_id,
1609
  payment_method_id=response_payload.payment_method_id,
1610
  provider_redirect_url=response_payload.provider_redirect_url,
public/index.html CHANGED
@@ -417,7 +417,7 @@
417
  <div>
418
  <label for="checkoutMode">支付页模式</label>
419
  <select id="checkoutMode">
420
- <option value="custom" selected>custom: 对齐 HAR 成功流程</option>
421
  </select>
422
  </div>
423
  <div>
 
417
  <div>
418
  <label for="checkoutMode">支付页模式</label>
419
  <select id="checkoutMode">
420
+ <option value="hosted" selected>hosted: pay.openai.com 长链</option>
421
  </select>
422
  </div>
423
  <div>