axm0121 commited on
Commit
bfc4cff
·
verified ·
1 Parent(s): 02e3fd8

Restore UPI IN-VN-IN with dynamic provider SID and sticky poll

Browse files
Files changed (2) hide show
  1. app.py +10 -6
  2. tests/test_app.py +4 -6
app.py CHANGED
@@ -6876,13 +6876,17 @@ def request_for_retry_attempt(req: LongLinkRequest, attempt: int) -> LongLinkReq
6876
  # UPI is country-bound and PayPal should follow its billing profile. iDEAL
6877
  # itself is selected by the NL billing data; forcing the proxy to NL broke
6878
  # routes that had already succeeded through the configured provider lane.
6879
- # UPI keeps the configured dynamic provider unchanged. Its IN/INR
6880
- # eligibility comes from checkout and billing data, while confirm and poll
6881
- # must stay on the same provider session selected for this attempt.
6882
- provider_country = "ID" if gopay_mode else (effective_pm_country(req) if link_type == "paypal" else "")
6883
  provider_source = base_provider_proxy or base_checkout_proxy
6884
  if provider_source and provider_country:
6885
- aligned_provider = proxy_for_required_country(provider_source, provider_country)
 
 
 
 
6886
  if not aligned_provider:
6887
  raise HTTPException(
6888
  status_code=422,
@@ -7233,7 +7237,7 @@ def start_upi_long_link_task(req: LongLinkRequest, request: Request) -> LongLink
7233
  raise HTTPException(status_code=403, detail="CDK only supports iDEAL extraction")
7234
  req = apply_runtime_defaults(req)
7235
  checkout_proxy = checkout_stage_proxy(req)
7236
- provider_proxy = normalize_proxy_url(provider_stage_proxy(req) or checkout_proxy)
7237
  req = req.model_copy(
7238
  update={
7239
  "link_type": "upi",
 
6876
  # UPI is country-bound and PayPal should follow its billing profile. iDEAL
6877
  # itself is selected by the NL billing data; forcing the proxy to NL broke
6878
  # routes that had already succeeded through the configured provider lane.
6879
+ # UPI keeps the IN -> VN -> IN country chain while proxy_for_attempt keeps
6880
+ # the dynamic SID/session for this provider attempt. Confirm and poll then
6881
+ # reuse that same provider proxy unchanged.
6882
+ provider_country = "IN" if link_type == "upi" else "ID" if gopay_mode else (effective_pm_country(req) if link_type == "paypal" else "")
6883
  provider_source = base_provider_proxy or base_checkout_proxy
6884
  if provider_source and provider_country:
6885
+ aligned_provider = (
6886
+ proxy_with_region(provider_source, "IN")
6887
+ if link_type == "upi"
6888
+ else proxy_for_required_country(provider_source, provider_country)
6889
+ )
6890
  if not aligned_provider:
6891
  raise HTTPException(
6892
  status_code=422,
 
7237
  raise HTTPException(status_code=403, detail="CDK only supports iDEAL extraction")
7238
  req = apply_runtime_defaults(req)
7239
  checkout_proxy = checkout_stage_proxy(req)
7240
+ provider_proxy = proxy_with_region(provider_stage_proxy(req) or checkout_proxy, "IN")
7241
  req = req.model_copy(
7242
  update={
7243
  "link_type": "upi",
tests/test_app.py CHANGED
@@ -111,15 +111,13 @@ class PaymentFlowTests(unittest.TestCase):
111
  )
112
  planned = app.request_for_retry_attempt(req, 1)
113
  self.assertEqual(planned.approve_proxy, planned.checkout_proxy)
114
- # The configured proxy is authoritative. Its country marker
115
- # is not rewritten or rejected to match billing/PM country.
116
  self.assertEqual(app.proxy_country_hint(planned.checkout_proxy), "MX")
117
- expected_provider = "MX" if link_type == "ideal" else "TR"
118
  self.assertEqual(app.proxy_country_hint(planned.provider_proxy), expected_provider)
119
  if link_type == "paypal":
120
  self.assertEqual(app.proxy_country_hint(planned.promotion_proxy), "MX")
121
 
122
- def test_upi_keeps_dynamic_provider_unchanged_for_confirm_and_poll(self):
123
  provider_proxy = "http://buyer-region-TR-session-dynamic:secret@proxy.example:8080"
124
  req = app.LongLinkRequest(
125
  accessToken="token-value",
@@ -135,8 +133,8 @@ class PaymentFlowTests(unittest.TestCase):
135
  with patch.object(app, "get_runtime_config", return_value=config):
136
  planned = app.request_for_retry_attempt(req, 1)
137
 
138
- self.assertEqual(app.proxy_country_hint(planned.provider_proxy), "TR")
139
- self.assertIn("buyer-region-TR-session-", planned.provider_proxy)
140
  stripe = FakeStripeSession([])
141
  app.set_proxy_url(stripe, planned.provider_proxy)
142
  self.assertEqual(app.redirect_poll_proxy_pool(planned, stripe), [planned.provider_proxy])
 
111
  )
112
  planned = app.request_for_retry_attempt(req, 1)
113
  self.assertEqual(planned.approve_proxy, planned.checkout_proxy)
 
 
114
  self.assertEqual(app.proxy_country_hint(planned.checkout_proxy), "MX")
115
+ expected_provider = {"ideal": "MX", "upi": "IN"}.get(link_type, "TR")
116
  self.assertEqual(app.proxy_country_hint(planned.provider_proxy), expected_provider)
117
  if link_type == "paypal":
118
  self.assertEqual(app.proxy_country_hint(planned.promotion_proxy), "MX")
119
 
120
+ def test_upi_keeps_in_dynamic_provider_for_confirm_and_poll(self):
121
  provider_proxy = "http://buyer-region-TR-session-dynamic:secret@proxy.example:8080"
122
  req = app.LongLinkRequest(
123
  accessToken="token-value",
 
133
  with patch.object(app, "get_runtime_config", return_value=config):
134
  planned = app.request_for_retry_attempt(req, 1)
135
 
136
+ self.assertEqual(app.proxy_country_hint(planned.provider_proxy), "IN")
137
+ self.assertIn("buyer-region-IN-session-", planned.provider_proxy)
138
  stripe = FakeStripeSession([])
139
  app.set_proxy_url(stripe, planned.provider_proxy)
140
  self.assertEqual(app.redirect_poll_proxy_pool(planned, stripe), [planned.provider_proxy])