axm0121 commited on
Commit
b3185c1
·
verified ·
1 Parent(s): a9e312a

Migrate sanitized Rust iDEAL flow and simplify iDEAL inputs

Browse files
Files changed (3) hide show
  1. README.md +12 -13
  2. app.py +82 -34
  3. public/index.html +47 -40
README.md CHANGED
@@ -73,18 +73,18 @@ docker compose down
73
  - UPI mode is a capability-specific exception: it always creates an India checkout/profile (`IN/INR`) so Stripe offers UPI, regardless of the page country selector.
74
  - iDEAL mode is also capability-specific: it always creates a Netherlands checkout/profile (`NL/EUR`), keeps the checkout processor entity for approve/return-url handling (for example `openai_ie`), and uses Stripe `type=ideal` so the final provider link resolves to `pay.ideal.nl`.
75
  - Checkout creation uses the server's local outbound route by default. If that route gets blocked, set the optional `checkoutProxy` field or `OPENAI_PAY_CHECKOUT_PROXY` to a clean local/checkout-stage proxy.
76
- - iDEAL has two dedicated top-level proxy pools. `checkoutProxy` accepts a newline/comma/semicolon/space separated pool; each rebuild round selects one entry and reuses it for NL Checkout, Stripe init/PM/confirm, ChatGPT/Stripe tax sync, iDEAL redirect resolution, and approve. `promotionProxy` is a separate pool used only for `/backend-api/payments/checkout/update` on the same `cs_id`; after the update the selected Checkout proxy is restored.
77
- - The combined iDEAL branch follows the sanitized Rust runtime profile independently of PP/UPI: `NL/EUR`, custom Checkout, Safari 17.6, `nl-NL`, `Europe/Amsterdam`, a five-round checkout rebuild policy, and 20 sequential same-CS approve attempts with fresh proxy SID after the first attempt. PP and UPI retain their existing Chrome/provider-pool/approve behavior.
78
  - The page `proxy` / `providerProxy` value is route-only. It can be a single proxy or a newline/comma/semicolon/space separated list. After checkout, each provider proxy is tried serially from the provider-stage boundary (`Stripe init` → payment method → confirm → approve → redirect polling/resolution or UPI instruction extraction) until a PayPal URL, iDEAL URL, or UPI instruction/QR link is found. It must not change billing country, currency, or PaymentMethod billing.
79
  - When Stripe returns `requires_approval`, the approve step uses an HF-compatible same-`cs_id` worker pool: one initial approve request, then concurrent bounded retries until one approve result succeeds or attempts are exhausted. The pool clones the current provider-stage session per worker, so it keeps the active auth token/proxy route without sharing one mutable session across threads.
80
  - UPI mode has an optional request/UI switch `upiCheckoutLoopEnabled`. When enabled, an unresolved UPI extraction reruns the whole flow from ChatGPT checkout creation up to `OPENAI_PAY_UPI_CHECKOUT_LOOP_ATTEMPTS` times (default `20`) and stops as soon as a real UPI instruction URL or QR link is extracted. This is an outer checkout loop, not provider-proxy concurrency.
81
  - PayPal mode has a matching optional request/UI switch `paypalCheckoutLoopEnabled`. When enabled, an unresolved/fallback PP extraction reruns the whole flow from ChatGPT checkout creation up to `OPENAI_PAY_PAYPAL_CHECKOUT_LOOP_ATTEMPTS` times (default `20`) and stops as soon as a PayPal approval URL is extracted. Provider proxy entries inside each round remain serial/sticky; this is not provider-proxy concurrency.
82
- - iDEAL mode has the optional request/UI switch `idealCheckoutLoopEnabled`. When enabled, a failed or non-iDEAL round reruns the whole flow from ChatGPT checkout creation up to `OPENAI_PAY_IDEAL_CHECKOUT_LOOP_ATTEMPTS` times (default `20`) and stops only when the final URL host is `ideal.nl` or a subdomain such as `pay.ideal.nl`.
83
  - The server remembers the last successful provider proxy in process memory. If the same proxy appears in the next submitted list, the serial retry order starts from that successful proxy, then wraps through the remaining entries.
84
  - Checkout country/currency and PaymentMethod billing remain the selected billing/profile region. The post-checkout provider stage remains pinned to the US/OpenAI LLC path only for approve/return-url semantics.
85
  - If the page proxy is blank, the provider stage also uses the server's local outbound route.
86
  - Proxy values may be entered with or without `http://`; when no scheme is present, the server automatically treats it as `http://...`.
87
- - The default network/browser fingerprint is unified on Chrome 142 (`curl_cffi` impersonation, `User-Agent`, and client hints). Override with `OPENAI_PAY_BROWSER_MAJOR` or `OPENAI_PAY_CURL_IMPERSONATE` only when the installed curl_cffi build requires it.
88
 
89
  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.
90
 
@@ -148,12 +148,12 @@ Stripe payment-page polling still use the configured post-approval settle window
148
  (`3` retry-confirms and `20` polls by default); this loop starts a fresh checkout
149
  instead of spending additional time on the same unresolved checkout.
150
 
151
- iDEAL full-flow retry is request controlled and default-off. Set
152
- `idealCheckoutLoopEnabled: true` (or enable the iDEAL checkbox in the web UI) to
153
- restart from ChatGPT checkout when one round fails or does not resolve to an
154
- `ideal.nl` host. The loop is capped by
155
- `OPENAI_PAY_IDEAL_CHECKOUT_LOOP_ATTEMPTS=20` by default and logs
156
- `ideal.checkout_loop.*` events.
157
 
158
  PayPal, UPI, and iDEAL provider extraction are guarded to avoid consuming a paid checkout
159
  when only a 0$ approval/instruction chain is desired. After Stripe init exposes
@@ -250,8 +250,7 @@ Content-Type: application/json
250
  "payment_locale": "en",
251
  "stripe_publishable_key": "",
252
  "upiCheckoutLoopEnabled": false,
253
- "paypalCheckoutLoopEnabled": false,
254
- "idealCheckoutLoopEnabled": false
255
  }
256
  ```
257
 
@@ -271,7 +270,7 @@ https://checkout.stripe.com -> https://pay.openai.com
271
 
272
  - `paypal` uses the selected `billing_country` for checkout billing country, currency, and PayPal PaymentMethod billing country/profile. Optional `paypalCheckoutLoopEnabled` repeats the entire checkout/provider flow up to 20 times by default if a round falls back without extracting a PayPal approval URL.
273
  - `upi` forces checkout billing country and currency to `IN/INR`, creates a Stripe `type=upi` PaymentMethod, approves manual checkout when required, then returns UPI instruction/QR fields (`upi_hosted_url`, `upi_qr_png`, `upi_qr_svg`, `upi_intent_id`) when available. Optional `upiCheckoutLoopEnabled` repeats the entire checkout/provider flow up to 20 times by default if a round does not extract a real UPI link.
274
- - `ideal` forces checkout billing country and currency to `NL/EUR`, creates a Stripe `type=ideal` PaymentMethod, approves manual checkout if Stripe asks for it, then resolves the final provider redirect to an `ideal.nl` host such as `https://pay.ideal.nl/transactions/...`. Optional `idealCheckoutLoopEnabled` repeats the complete checkout/provider flow up to 20 rounds by default until a real `ideal.nl` URL is extracted.
275
  - The default remains `US/USD`, but the UI and backend support the full country/currency set shown on the page (for example `AU/AUD`, `JP/JPY`, `DE/EUR`, `GB/GBP`).
276
  - Proxy fields are independent route controls and do not override the selected billing/profile region.
277
 
 
73
  - UPI mode is a capability-specific exception: it always creates an India checkout/profile (`IN/INR`) so Stripe offers UPI, regardless of the page country selector.
74
  - iDEAL mode is also capability-specific: it always creates a Netherlands checkout/profile (`NL/EUR`), keeps the checkout processor entity for approve/return-url handling (for example `openai_ie`), and uses Stripe `type=ideal` so the final provider link resolves to `pay.ideal.nl`.
75
  - Checkout creation uses the server's local outbound route by default. If that route gets blocked, set the optional `checkoutProxy` field or `OPENAI_PAY_CHECKOUT_PROXY` to a clean local/checkout-stage proxy.
76
+ - iDEAL has exactly two editable routing inputs in the combined page. `checkoutProxy` accepts a newline/comma/semicolon/space separated pool; each rebuild round selects one entry and reuses it for NL Checkout, Stripe init/PM/confirm, ChatGPT/Stripe tax sync, iDEAL redirect resolution, and approve. `promotionProxy` is a separate pool used only for `/backend-api/payments/checkout/update` on the same `cs_id`; after the update the selected Checkout proxy is restored. Generic Provider, billing, locale, Stripe-key, device-id, and User-Agent fields are hidden and excluded from iDEAL browser requests.
77
+ - The combined iDEAL branch follows the sanitized Rust runtime profile independently of PP/UPI: `NL/EUR`, custom Checkout, Safari 17.6 with macOS client hints and the captured ChatGPT client version/build headers, `nl-NL`, `Europe/Amsterdam`, token-account email for tax/PaymentMethod billing when available, a five-round checkout rebuild policy, 20 sequential same-CS approve attempts with fresh proxy SID after the first attempt, and 20 Stripe redirect polls when confirm does not require approval. PP and UPI retain their existing Chrome/provider-pool/approve behavior.
78
  - The page `proxy` / `providerProxy` value is route-only. It can be a single proxy or a newline/comma/semicolon/space separated list. After checkout, each provider proxy is tried serially from the provider-stage boundary (`Stripe init` → payment method → confirm → approve → redirect polling/resolution or UPI instruction extraction) until a PayPal URL, iDEAL URL, or UPI instruction/QR link is found. It must not change billing country, currency, or PaymentMethod billing.
79
  - When Stripe returns `requires_approval`, the approve step uses an HF-compatible same-`cs_id` worker pool: one initial approve request, then concurrent bounded retries until one approve result succeeds or attempts are exhausted. The pool clones the current provider-stage session per worker, so it keeps the active auth token/proxy route without sharing one mutable session across threads.
80
  - UPI mode has an optional request/UI switch `upiCheckoutLoopEnabled`. When enabled, an unresolved UPI extraction reruns the whole flow from ChatGPT checkout creation up to `OPENAI_PAY_UPI_CHECKOUT_LOOP_ATTEMPTS` times (default `20`) and stops as soon as a real UPI instruction URL or QR link is extracted. This is an outer checkout loop, not provider-proxy concurrency.
81
  - PayPal mode has a matching optional request/UI switch `paypalCheckoutLoopEnabled`. When enabled, an unresolved/fallback PP extraction reruns the whole flow from ChatGPT checkout creation up to `OPENAI_PAY_PAYPAL_CHECKOUT_LOOP_ATTEMPTS` times (default `20`) and stops as soon as a PayPal approval URL is extracted. Provider proxy entries inside each round remain serial/sticky; this is not provider-proxy concurrency.
82
+ - iDEAL always follows the Rust five-round rebuild policy. A failed or non-iDEAL round restarts from ChatGPT checkout creation up to `OPENAI_PAY_IDEAL_REBUILD_ATTEMPTS=5`; there is no iDEAL loop checkbox in the combined page.
83
  - The server remembers the last successful provider proxy in process memory. If the same proxy appears in the next submitted list, the serial retry order starts from that successful proxy, then wraps through the remaining entries.
84
  - Checkout country/currency and PaymentMethod billing remain the selected billing/profile region. The post-checkout provider stage remains pinned to the US/OpenAI LLC path only for approve/return-url semantics.
85
  - If the page proxy is blank, the provider stage also uses the server's local outbound route.
86
  - Proxy values may be entered with or without `http://`; when no scheme is present, the server automatically treats it as `http://...`.
87
+ - PP/UPI use the default Chrome 142 network/browser fingerprint. iDEAL overrides the request headers with the migrated Safari 17.6/macOS profile while retaining the installed `curl_cffi` transport. Override `OPENAI_PAY_BROWSER_MAJOR` or `OPENAI_PAY_CURL_IMPERSONATE` only when the installed curl_cffi build requires it.
88
 
89
  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.
90
 
 
148
  (`3` retry-confirms and `20` polls by default); this loop starts a fresh checkout
149
  instead of spending additional time on the same unresolved checkout.
150
 
151
+ iDEAL full-flow retry is automatic and follows the sanitized Rust backend. One
152
+ submission rebuilds Checkout up to `OPENAI_PAY_IDEAL_REBUILD_ATTEMPTS=5` times
153
+ and logs `ideal.checkout_loop.*` events. Approval is sequential and same-CS
154
+ (`OPENAI_PAY_IDEAL_APPROVE_ATTEMPTS=20`), while a confirm result that does not
155
+ require approval polls Stripe up to
156
+ `OPENAI_PAY_IDEAL_REDIRECT_POLL_ATTEMPTS=20` before rebuilding the round.
157
 
158
  PayPal, UPI, and iDEAL provider extraction are guarded to avoid consuming a paid checkout
159
  when only a 0$ approval/instruction chain is desired. After Stripe init exposes
 
250
  "payment_locale": "en",
251
  "stripe_publishable_key": "",
252
  "upiCheckoutLoopEnabled": false,
253
+ "paypalCheckoutLoopEnabled": false
 
254
  }
255
  ```
256
 
 
270
 
271
  - `paypal` uses the selected `billing_country` for checkout billing country, currency, and PayPal PaymentMethod billing country/profile. Optional `paypalCheckoutLoopEnabled` repeats the entire checkout/provider flow up to 20 times by default if a round falls back without extracting a PayPal approval URL.
272
  - `upi` forces checkout billing country and currency to `IN/INR`, creates a Stripe `type=upi` PaymentMethod, approves manual checkout when required, then returns UPI instruction/QR fields (`upi_hosted_url`, `upi_qr_png`, `upi_qr_svg`, `upi_intent_id`) when available. Optional `upiCheckoutLoopEnabled` repeats the entire checkout/provider flow up to 20 times by default if a round does not extract a real UPI link.
273
+ - `ideal` accepts only the access token plus `checkoutProxy` and `promotionProxy` from the combined page. It forces `NL/EUR`, creates a Stripe `type=ideal` PaymentMethod, approves manual checkout if Stripe asks for it, automatically rebuilds Checkout up to five rounds, and resolves the final provider redirect to an `ideal.nl` host such as `https://pay.ideal.nl/transactions/...`.
274
  - The default remains `US/USD`, but the UI and backend support the full country/currency set shown on the page (for example `AU/AUD`, `JP/JPY`, `DE/EUR`, `GB/GBP`).
275
  - Proxy fields are independent route controls and do not override the selected billing/profile region.
276
 
app.py CHANGED
@@ -133,7 +133,6 @@ REQUIRE_IDEAL_ZERO_AMOUNT = env_bool("OPENAI_PAY_IDEAL_REQUIRE_ZERO_AMOUNT", Tru
133
  ZERO_AMOUNT_CHECKOUT_RETRIES = env_int("OPENAI_PAY_ZERO_AMOUNT_CHECKOUT_RETRIES", 2, minimum=0, maximum=10)
134
  UPI_CHECKOUT_LOOP_ATTEMPTS = env_int("OPENAI_PAY_UPI_CHECKOUT_LOOP_ATTEMPTS", 20, minimum=1, maximum=20)
135
  PAYPAL_CHECKOUT_LOOP_ATTEMPTS = env_int("OPENAI_PAY_PAYPAL_CHECKOUT_LOOP_ATTEMPTS", 20, minimum=1, maximum=20)
136
- IDEAL_CHECKOUT_LOOP_ATTEMPTS = env_int("OPENAI_PAY_IDEAL_CHECKOUT_LOOP_ATTEMPTS", 20, minimum=1, maximum=20)
137
  REQUIRE_REDIRECT_CAPABLE_ZERO_AMOUNT = env_bool("OPENAI_PAY_REQUIRE_REDIRECT_CAPABLE_ZERO_AMOUNT", False)
138
  ZERO_AMOUNT_REDIRECT_CAPABLE_CHECKOUT_RETRIES = env_int(
139
  "OPENAI_PAY_ZERO_AMOUNT_REDIRECT_CAPABLE_CHECKOUT_RETRIES",
@@ -161,8 +160,18 @@ IDEAL_PROVIDER_REGION = "NL"
161
  IDEAL_AMOUNT_LIMIT_MINOR = env_int("OPENAI_PAY_IDEAL_AMOUNT_LIMIT_MINOR", 50, minimum=0, maximum=10000)
162
  IDEAL_REBUILD_ATTEMPTS = env_int("OPENAI_PAY_IDEAL_REBUILD_ATTEMPTS", 5, minimum=1, maximum=20)
163
  IDEAL_APPROVE_ATTEMPTS = env_int("OPENAI_PAY_IDEAL_APPROVE_ATTEMPTS", 20, minimum=1, maximum=100)
 
 
 
 
 
 
164
  IDEAL_SAFARI_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_6_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15"
165
  IDEAL_ACCEPT_LANGUAGE = "nl-NL,nl;q=0.9,en;q=0.8"
 
 
 
 
166
  PROVIDER_HOST_SUFFIXES = {
167
  "paypal": PAYPAL_HOST_SUFFIXES,
168
  "ideal": IDEAL_HOST_SUFFIXES,
@@ -556,8 +565,6 @@ def proxy_with_fresh_sid(proxy: str) -> str:
556
 
557
  def checkout_stage_proxies(req: LongLinkRequest) -> list[str]:
558
  configured = split_proxy_urls(req.checkout_proxy or os.getenv("OPENAI_PAY_CHECKOUT_PROXY", ""))
559
- if normalize_link_type(req.link_type) == "ideal":
560
- return configured or provider_stage_proxies(req)
561
  return configured
562
 
563
 
@@ -1020,7 +1027,7 @@ def find_token(value: Any) -> str:
1020
  return ""
1021
 
1022
 
1023
- def normalize_access_token(raw: str) -> str:
1024
  token = str(raw or "").strip()
1025
  if not token:
1026
  return ""
@@ -1029,7 +1036,32 @@ def normalize_access_token(raw: str) -> str:
1029
  return find_token(json.loads(token)) or token
1030
  except json.JSONDecodeError:
1031
  return token
1032
- return token
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
 
1034
 
1035
  def extract_processor_entity(data: Any) -> str:
@@ -1180,26 +1212,33 @@ def build_chatgpt_session(req: LongLinkRequest) -> Any:
1180
  curl_impersonate=DEFAULT_CURL_IMPERSONATE,
1181
  )
1182
  session = new_session()
1183
- session.headers.update(
1184
- {
1185
- "User-Agent": user_agent,
1186
- "Accept": "*/*",
1187
- "Accept-Language": IDEAL_ACCEPT_LANGUAGE if is_ideal else "en-US,en;q=0.9",
1188
- "Authorization": f"Bearer {access_token}",
1189
- "Origin": "https://chatgpt.com",
1190
- "Referer": "https://chatgpt.com/",
1191
- "Content-Type": "application/json",
1192
- "oai-device-id": device_id,
1193
- "oai-language": "nl-NL" if is_ideal else "en-US",
1194
- "sec-ch-ua": DEFAULT_SEC_CH_UA,
1195
- "sec-ch-ua-mobile": "?0",
1196
- "sec-ch-ua-platform": '"Windows"',
1197
- "sec-fetch-dest": "empty",
1198
- "sec-fetch-mode": "cors",
1199
- "sec-fetch-site": "same-origin",
1200
- "Cookie": f"oai-did={device_id}",
1201
- }
1202
- )
 
 
 
 
 
 
 
1203
  if checkout_proxy:
1204
  set_proxy_url(session, checkout_proxy)
1205
  # Checkout may use an optional local/checkout proxy. After checkout,
@@ -1351,6 +1390,7 @@ def update_ideal_tax_regions(
1351
  path = "/backend-api/payments/checkout/taxes"
1352
  referer = f"https://chatgpt.com/checkout/{checkout['processor_entity']}/{checkout['cs_id']}"
1353
  billing = dict(IDEAL_BILLING)
 
1354
  taxes_body = {
1355
  "checkout_session_id": checkout["cs_id"],
1356
  "checkout_email": billing["email"],
@@ -2706,7 +2746,7 @@ def chatgpt_approve_ideal(chatgpt: Any, cs_id: str, checkout: dict[str, Any]) ->
2706
  raise HTTPException(502, last_detail or f"iDEAL approve failed after {IDEAL_APPROVE_ATTEMPTS} attempts")
2707
 
2708
 
2709
- def redirect_url_after_confirm(
2710
  chatgpt: Any,
2711
  stripe: Any,
2712
  confirm_payload: dict[str, Any],
@@ -2813,7 +2853,18 @@ def redirect_url_after_confirm(
2813
  submission_state=submission.get("state") if isinstance(submission, dict) else "",
2814
  response_keys=response_keys(confirm_payload),
2815
  )
2816
- return stripe_payment_page_redirect_url(stripe, cs_id, stripe_pk, req, timeout_seconds=30, max_attempts=3, ctx=ctx)
 
 
 
 
 
 
 
 
 
 
 
2817
 
2818
 
2819
  def resolve_external_redirect(
@@ -3140,7 +3191,9 @@ def create_provider_link(
3140
  payment_method_billing_country=payment_method_billing_country,
3141
  init_checksum_present=bool(ctx.get("init_checksum")),
3142
  )
3143
- billing = billing_for_link_type(link_type, payment_method_billing_country)
 
 
3144
  log_info(
3145
  "provider.billing.ready",
3146
  checkout_country=checkout_billing_country,
@@ -3506,8 +3559,7 @@ def _build_long_link_response_once(
3506
  upi_checkout_loop_attempts=UPI_CHECKOUT_LOOP_ATTEMPTS,
3507
  paypal_checkout_loop_enabled=paypal_checkout_loop_enabled(req),
3508
  paypal_checkout_loop_attempts=PAYPAL_CHECKOUT_LOOP_ATTEMPTS,
3509
- ideal_checkout_loop_enabled=ideal_checkout_loop_enabled(req),
3510
- ideal_checkout_loop_attempts=IDEAL_CHECKOUT_LOOP_ATTEMPTS,
3511
  )
3512
  check_task_cancelled("before_chatgpt_session")
3513
  chatgpt = build_chatgpt_session(req)
@@ -3961,10 +4013,6 @@ def paypal_checkout_loop_enabled(req: LongLinkRequest) -> bool:
3961
  return normalize_link_type(req.link_type) == "paypal" and bool(req.paypal_checkout_loop_enabled)
3962
 
3963
 
3964
- def ideal_checkout_loop_enabled(req: LongLinkRequest) -> bool:
3965
- return normalize_link_type(req.link_type) == "ideal" and bool(req.ideal_checkout_loop_enabled)
3966
-
3967
-
3968
  def checkout_loop_kind(req: LongLinkRequest) -> str:
3969
  if upi_checkout_loop_enabled(req):
3970
  return "upi"
 
133
  ZERO_AMOUNT_CHECKOUT_RETRIES = env_int("OPENAI_PAY_ZERO_AMOUNT_CHECKOUT_RETRIES", 2, minimum=0, maximum=10)
134
  UPI_CHECKOUT_LOOP_ATTEMPTS = env_int("OPENAI_PAY_UPI_CHECKOUT_LOOP_ATTEMPTS", 20, minimum=1, maximum=20)
135
  PAYPAL_CHECKOUT_LOOP_ATTEMPTS = env_int("OPENAI_PAY_PAYPAL_CHECKOUT_LOOP_ATTEMPTS", 20, minimum=1, maximum=20)
 
136
  REQUIRE_REDIRECT_CAPABLE_ZERO_AMOUNT = env_bool("OPENAI_PAY_REQUIRE_REDIRECT_CAPABLE_ZERO_AMOUNT", False)
137
  ZERO_AMOUNT_REDIRECT_CAPABLE_CHECKOUT_RETRIES = env_int(
138
  "OPENAI_PAY_ZERO_AMOUNT_REDIRECT_CAPABLE_CHECKOUT_RETRIES",
 
160
  IDEAL_AMOUNT_LIMIT_MINOR = env_int("OPENAI_PAY_IDEAL_AMOUNT_LIMIT_MINOR", 50, minimum=0, maximum=10000)
161
  IDEAL_REBUILD_ATTEMPTS = env_int("OPENAI_PAY_IDEAL_REBUILD_ATTEMPTS", 5, minimum=1, maximum=20)
162
  IDEAL_APPROVE_ATTEMPTS = env_int("OPENAI_PAY_IDEAL_APPROVE_ATTEMPTS", 20, minimum=1, maximum=100)
163
+ IDEAL_REDIRECT_POLL_ATTEMPTS = env_int(
164
+ "OPENAI_PAY_IDEAL_REDIRECT_POLL_ATTEMPTS",
165
+ 20,
166
+ minimum=1,
167
+ maximum=100,
168
+ )
169
  IDEAL_SAFARI_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_6_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15"
170
  IDEAL_ACCEPT_LANGUAGE = "nl-NL,nl;q=0.9,en;q=0.8"
171
+ IDEAL_SEC_CH_UA = '"Safari";v="17", "Not.A/Brand";v="8"'
172
+ IDEAL_SEC_CH_UA_PLATFORM = '"macOS"'
173
+ IDEAL_CHATGPT_CLIENT_VERSION = "prod-db390ebea64862bf1899c420a4c736e0cf639747"
174
+ IDEAL_CHATGPT_CLIENT_BUILD_NUMBER = "7904904"
175
  PROVIDER_HOST_SUFFIXES = {
176
  "paypal": PAYPAL_HOST_SUFFIXES,
177
  "ideal": IDEAL_HOST_SUFFIXES,
 
565
 
566
  def checkout_stage_proxies(req: LongLinkRequest) -> list[str]:
567
  configured = split_proxy_urls(req.checkout_proxy or os.getenv("OPENAI_PAY_CHECKOUT_PROXY", ""))
 
 
568
  return configured
569
 
570
 
 
1027
  return ""
1028
 
1029
 
1030
+ def normalize_access_token(raw: str) -> str:
1031
  token = str(raw or "").strip()
1032
  if not token:
1033
  return ""
 
1036
  return find_token(json.loads(token)) or token
1037
  except json.JSONDecodeError:
1038
  return token
1039
+ return token
1040
+
1041
+
1042
+ def account_email_from_token(raw: str) -> str:
1043
+ token = normalize_access_token(raw)
1044
+ try:
1045
+ parts = token.split(".")
1046
+ if len(parts) < 2:
1047
+ return ""
1048
+ padded = parts[1] + "=" * (-len(parts[1]) % 4)
1049
+ payload = json.loads(base64.urlsafe_b64decode(padded.encode("ascii")).decode("utf-8"))
1050
+ except Exception:
1051
+ return ""
1052
+ if not isinstance(payload, dict):
1053
+ return ""
1054
+ profile = payload.get("https://api.openai.com/profile")
1055
+ if isinstance(profile, dict):
1056
+ for key in ("email", "email_address"):
1057
+ value = str(profile.get(key) or "").strip()
1058
+ if "@" in value:
1059
+ return value
1060
+ for key in ("email", "preferred_username", "upn"):
1061
+ value = str(payload.get(key) or "").strip()
1062
+ if "@" in value:
1063
+ return value
1064
+ return ""
1065
 
1066
 
1067
  def extract_processor_entity(data: Any) -> str:
 
1212
  curl_impersonate=DEFAULT_CURL_IMPERSONATE,
1213
  )
1214
  session = new_session()
1215
+ headers = {
1216
+ "User-Agent": user_agent,
1217
+ "Accept": "*/*",
1218
+ "Accept-Language": IDEAL_ACCEPT_LANGUAGE if is_ideal else "en-US,en;q=0.9",
1219
+ "Authorization": f"Bearer {access_token}",
1220
+ "Origin": "https://chatgpt.com",
1221
+ "Referer": "https://chatgpt.com/",
1222
+ "Content-Type": "application/json",
1223
+ "oai-device-id": device_id,
1224
+ "oai-language": "nl-NL" if is_ideal else "en-US",
1225
+ "sec-ch-ua": IDEAL_SEC_CH_UA if is_ideal else DEFAULT_SEC_CH_UA,
1226
+ "sec-ch-ua-mobile": "?0",
1227
+ "sec-ch-ua-platform": IDEAL_SEC_CH_UA_PLATFORM if is_ideal else '"Windows"',
1228
+ "sec-fetch-dest": "empty",
1229
+ "sec-fetch-mode": "cors",
1230
+ "sec-fetch-site": "same-origin",
1231
+ "Cookie": f"oai-did={device_id}",
1232
+ }
1233
+ if is_ideal:
1234
+ headers.update(
1235
+ {
1236
+ "oai-session-id": str(uuid.uuid4()),
1237
+ "oai-client-version": IDEAL_CHATGPT_CLIENT_VERSION,
1238
+ "oai-client-build-number": IDEAL_CHATGPT_CLIENT_BUILD_NUMBER,
1239
+ }
1240
+ )
1241
+ session.headers.update(headers)
1242
  if checkout_proxy:
1243
  set_proxy_url(session, checkout_proxy)
1244
  # Checkout may use an optional local/checkout proxy. After checkout,
 
1390
  path = "/backend-api/payments/checkout/taxes"
1391
  referer = f"https://chatgpt.com/checkout/{checkout['processor_entity']}/{checkout['cs_id']}"
1392
  billing = dict(IDEAL_BILLING)
1393
+ billing["email"] = account_email_from_token(req.access_token) or billing["email"]
1394
  taxes_body = {
1395
  "checkout_session_id": checkout["cs_id"],
1396
  "checkout_email": billing["email"],
 
2746
  raise HTTPException(502, last_detail or f"iDEAL approve failed after {IDEAL_APPROVE_ATTEMPTS} attempts")
2747
 
2748
 
2749
+ def redirect_url_after_confirm(
2750
  chatgpt: Any,
2751
  stripe: Any,
2752
  confirm_payload: dict[str, Any],
 
2853
  submission_state=submission.get("state") if isinstance(submission, dict) else "",
2854
  response_keys=response_keys(confirm_payload),
2855
  )
2856
+ if payment_method_type == "ideal":
2857
+ return stripe_payment_page_redirect_url(
2858
+ stripe,
2859
+ cs_id,
2860
+ stripe_pk,
2861
+ req,
2862
+ timeout_seconds=max(DEFAULT_TIMEOUT, IDEAL_REDIRECT_POLL_ATTEMPTS),
2863
+ max_attempts=IDEAL_REDIRECT_POLL_ATTEMPTS,
2864
+ delay_seconds=1,
2865
+ ctx=ctx,
2866
+ )
2867
+ return stripe_payment_page_redirect_url(stripe, cs_id, stripe_pk, req, timeout_seconds=30, max_attempts=3, ctx=ctx)
2868
 
2869
 
2870
  def resolve_external_redirect(
 
3191
  payment_method_billing_country=payment_method_billing_country,
3192
  init_checksum_present=bool(ctx.get("init_checksum")),
3193
  )
3194
+ billing = billing_for_link_type(link_type, payment_method_billing_country)
3195
+ if link_type == "ideal":
3196
+ billing["email"] = account_email_from_token(req.access_token) or billing["email"]
3197
  log_info(
3198
  "provider.billing.ready",
3199
  checkout_country=checkout_billing_country,
 
3559
  upi_checkout_loop_attempts=UPI_CHECKOUT_LOOP_ATTEMPTS,
3560
  paypal_checkout_loop_enabled=paypal_checkout_loop_enabled(req),
3561
  paypal_checkout_loop_attempts=PAYPAL_CHECKOUT_LOOP_ATTEMPTS,
3562
+ ideal_rebuild_attempts=IDEAL_REBUILD_ATTEMPTS,
 
3563
  )
3564
  check_task_cancelled("before_chatgpt_session")
3565
  chatgpt = build_chatgpt_session(req)
 
4013
  return normalize_link_type(req.link_type) == "paypal" and bool(req.paypal_checkout_loop_enabled)
4014
 
4015
 
 
 
 
 
4016
  def checkout_loop_kind(req: LongLinkRequest) -> str:
4017
  if upi_checkout_loop_enabled(req):
4018
  return "upi"
public/index.html CHANGED
@@ -19,11 +19,15 @@
19
  --danger: #b42318;
20
  }
21
 
22
- * {
23
- box-sizing: border-box;
24
- }
25
-
26
- body {
 
 
 
 
27
  margin: 0;
28
  min-height: 100vh;
29
  background: var(--bg);
@@ -510,14 +514,14 @@
510
  <option value="ideal">iDEAL 提链(强制 NL/EUR)</option>
511
  </select>
512
  </div>
513
- <div>
514
- <label for="checkoutMode">支付页模式</label>
515
  <select id="checkoutMode">
516
  <option value="hosted" selected>hosted: pay.openai.com 长链</option>
517
  </select>
518
  </div>
519
- <div>
520
- <label for="paymentLocale">支付页语言</label>
521
  <select id="paymentLocale">
522
  <option value="en" selected>英文</option>
523
  <option value="zh-CN">简体中文</option>
@@ -531,13 +535,13 @@
531
  <option value="pt-BR">葡萄牙文</option>
532
  </select>
533
  </div>
534
- <div>
535
- <label for="billingCountry">账单/资料地区</label>
536
- <select id="billingCountry"></select>
537
- </div>
538
- <div>
539
- <label for="currency">币种</label>
540
- <input id="currency" readonly />
541
  </div>
542
  <div id="upiLoopRow" class="option-row hidden">
543
  <input id="upiCheckoutLoopEnabled" type="checkbox" />
@@ -553,13 +557,6 @@
553
  <small>默认关闭;勾选后,每轮都会从 OpenAI Checkout 重新开始并按现有 Provider 池串行重试。成功拿到 PayPal BA/approve 链后立即停止。</small>
554
  </div>
555
  </div>
556
- <div id="idealLoopRow" class="option-row hidden">
557
- <input id="idealCheckoutLoopEnabled" type="checkbox" />
558
- <div>
559
- <label for="idealCheckoutLoopEnabled">开启 iDEAL 失败后重开 Checkout,最多 20 次</label>
560
- <small>默认关闭;勾选后,每轮都会从 OpenAI Checkout 重新开始。成功解析到 ideal.nl / pay.ideal.nl 链后立即停止。</small>
561
- </div>
562
- </div>
563
  <div id="providerProxyRow">
564
  <label for="proxy">Provider 代理列表(每行一个,不决定 billing)</label>
565
  <textarea
@@ -581,7 +578,7 @@
581
  </div>
582
  </div>
583
 
584
- <details>
585
  <summary>高级选项</summary>
586
  <div class="grid">
587
  <div id="checkoutProxyAdvancedRow">
@@ -854,8 +851,9 @@
854
  }
855
 
856
  function updateCountryMode() {
857
- const linkType = $("linkType").value || "paypal";
858
- const forcedCountry = forcedCountryForLinkType(linkType);
 
859
  if (forcedCountry) {
860
  if (!$("billingCountry").disabled && $("billingCountry").value) {
861
  lastFlexibleCountry = $("billingCountry").value;
@@ -873,20 +871,22 @@
873
  updateCurrency();
874
  $("upiLoopRow").classList.toggle("hidden", linkType !== "upi");
875
  $("paypalLoopRow").classList.toggle("hidden", linkType !== "paypal");
876
- $("idealLoopRow").classList.add("hidden");
877
  $("providerProxyRow").classList.toggle("hidden", linkType === "ideal");
878
  $("idealCheckoutProxyRow").classList.toggle("hidden", linkType !== "ideal");
879
  $("idealPromotionProxyRow").classList.toggle("hidden", linkType !== "ideal");
880
- $("checkoutProxyAdvancedRow").classList.toggle("hidden", linkType === "ideal");
 
 
 
 
 
 
881
  if (linkType !== "upi") {
882
  $("upiCheckoutLoopEnabled").checked = false;
883
  }
884
  if (linkType !== "paypal") {
885
  $("paypalCheckoutLoopEnabled").checked = false;
886
  }
887
- if (linkType !== "ideal") {
888
- $("idealCheckoutLoopEnabled").checked = false;
889
- }
890
  const label = linkTypeLabel(linkType);
891
  generateButton.textContent = `提取 ${label} 链(${$("billingCountry").value}/${$("currency").value})`;
892
  setStatus(
@@ -915,23 +915,30 @@
915
 
916
  function buildPayload(accessToken) {
917
  const linkType = $("linkType").value || "paypal";
 
 
 
 
 
 
 
 
918
  return {
919
  accessToken,
920
  link_type: linkType,
921
- proxy: linkType === "ideal" ? "" : $("proxy").value.trim(),
922
- checkoutProxy: linkType === "ideal" ? $("idealCheckoutProxyPool").value.trim() : $("checkoutProxy").value.trim(),
923
- promotionProxy: linkType === "ideal" ? $("idealPromotionProxyPool").value.trim() : "",
924
- providerProxy: linkType === "ideal" ? "" : $("proxy").value.trim(),
925
- billing_country: $("billingCountry").value,
926
- checkout_ui_mode: linkType === "ideal" ? "custom" : $("checkoutMode").value,
927
- payment_locale: linkType === "ideal" ? "nl-NL" : $("paymentLocale").value,
928
  stripe_publishable_key: $("stripeKey").value.trim(),
929
  device_id: $("deviceId").value.trim(),
930
  user_agent: $("userAgent").value.trim(),
931
  upiCheckoutLoopEnabled: ($("linkType").value || "paypal") === "upi" && $("upiCheckoutLoopEnabled").checked,
932
  paypalCheckoutLoopEnabled: ($("linkType").value || "paypal") === "paypal" && $("paypalCheckoutLoopEnabled").checked,
933
- idealCheckoutLoopEnabled: ($("linkType").value || "paypal") === "ideal" && $("idealCheckoutLoopEnabled").checked,
934
- };
935
  }
936
 
937
  function setProgress(progress, stage, message, isError = false) {
 
19
  --danger: #b42318;
20
  }
21
 
22
+ * {
23
+ box-sizing: border-box;
24
+ }
25
+
26
+ .hidden {
27
+ display: none !important;
28
+ }
29
+
30
+ body {
31
  margin: 0;
32
  min-height: 100vh;
33
  background: var(--bg);
 
514
  <option value="ideal">iDEAL 提链(强制 NL/EUR)</option>
515
  </select>
516
  </div>
517
+ <div id="checkoutModeRow">
518
+ <label for="checkoutMode">支付页模式</label>
519
  <select id="checkoutMode">
520
  <option value="hosted" selected>hosted: pay.openai.com 长链</option>
521
  </select>
522
  </div>
523
+ <div id="paymentLocaleRow">
524
+ <label for="paymentLocale">支付页语言</label>
525
  <select id="paymentLocale">
526
  <option value="en" selected>英文</option>
527
  <option value="zh-CN">简体中文</option>
 
535
  <option value="pt-BR">葡萄牙文</option>
536
  </select>
537
  </div>
538
+ <div id="billingCountryRow">
539
+ <label for="billingCountry">账单/资料地区</label>
540
+ <select id="billingCountry"></select>
541
+ </div>
542
+ <div id="currencyRow">
543
+ <label for="currency">币种</label>
544
+ <input id="currency" readonly />
545
  </div>
546
  <div id="upiLoopRow" class="option-row hidden">
547
  <input id="upiCheckoutLoopEnabled" type="checkbox" />
 
557
  <small>默认关闭;勾选后,每轮都会从 OpenAI Checkout 重新开始并按现有 Provider 池串行重试。成功拿到 PayPal BA/approve 链后立即停止。</small>
558
  </div>
559
  </div>
 
 
 
 
 
 
 
560
  <div id="providerProxyRow">
561
  <label for="proxy">Provider 代理列表(每行一个,不决定 billing)</label>
562
  <textarea
 
578
  </div>
579
  </div>
580
 
581
+ <details id="advancedOptions">
582
  <summary>高级选项</summary>
583
  <div class="grid">
584
  <div id="checkoutProxyAdvancedRow">
 
851
  }
852
 
853
  function updateCountryMode() {
854
+ const linkType = $("linkType").value || "paypal";
855
+ const isIdeal = linkType === "ideal";
856
+ const forcedCountry = forcedCountryForLinkType(linkType);
857
  if (forcedCountry) {
858
  if (!$("billingCountry").disabled && $("billingCountry").value) {
859
  lastFlexibleCountry = $("billingCountry").value;
 
871
  updateCurrency();
872
  $("upiLoopRow").classList.toggle("hidden", linkType !== "upi");
873
  $("paypalLoopRow").classList.toggle("hidden", linkType !== "paypal");
 
874
  $("providerProxyRow").classList.toggle("hidden", linkType === "ideal");
875
  $("idealCheckoutProxyRow").classList.toggle("hidden", linkType !== "ideal");
876
  $("idealPromotionProxyRow").classList.toggle("hidden", linkType !== "ideal");
877
+ $("checkoutModeRow").classList.toggle("hidden", isIdeal);
878
+ $("paymentLocaleRow").classList.toggle("hidden", isIdeal);
879
+ $("billingCountryRow").classList.toggle("hidden", isIdeal);
880
+ $("currencyRow").classList.toggle("hidden", isIdeal);
881
+ $("advancedOptions").classList.toggle("hidden", isIdeal);
882
+ $("saveProxy").classList.toggle("hidden", isIdeal);
883
+ $("clearProxy").classList.toggle("hidden", isIdeal);
884
  if (linkType !== "upi") {
885
  $("upiCheckoutLoopEnabled").checked = false;
886
  }
887
  if (linkType !== "paypal") {
888
  $("paypalCheckoutLoopEnabled").checked = false;
889
  }
 
 
 
890
  const label = linkTypeLabel(linkType);
891
  generateButton.textContent = `提取 ${label} 链(${$("billingCountry").value}/${$("currency").value})`;
892
  setStatus(
 
915
 
916
  function buildPayload(accessToken) {
917
  const linkType = $("linkType").value || "paypal";
918
+ if (linkType === "ideal") {
919
+ return {
920
+ accessToken,
921
+ link_type: "ideal",
922
+ checkoutProxy: $("idealCheckoutProxyPool").value.trim(),
923
+ promotionProxy: $("idealPromotionProxyPool").value.trim(),
924
+ };
925
+ }
926
  return {
927
  accessToken,
928
  link_type: linkType,
929
+ proxy: $("proxy").value.trim(),
930
+ checkoutProxy: $("checkoutProxy").value.trim(),
931
+ promotionProxy: "",
932
+ providerProxy: $("proxy").value.trim(),
933
+ billing_country: $("billingCountry").value,
934
+ checkout_ui_mode: $("checkoutMode").value,
935
+ payment_locale: $("paymentLocale").value,
936
  stripe_publishable_key: $("stripeKey").value.trim(),
937
  device_id: $("deviceId").value.trim(),
938
  user_agent: $("userAgent").value.trim(),
939
  upiCheckoutLoopEnabled: ($("linkType").value || "paypal") === "upi" && $("upiCheckoutLoopEnabled").checked,
940
  paypalCheckoutLoopEnabled: ($("linkType").value || "paypal") === "paypal" && $("paypalCheckoutLoopEnabled").checked,
941
+ };
 
942
  }
943
 
944
  function setProgress(progress, stage, message, isError = false) {