From c34a2fd5a538c84917707db3bad3d7810886b6c9 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 17 Apr 2026 01:42:09 +0100 Subject: [PATCH] fix: wire up auto Business Policy setup trigger on 20403 error --- EbayListingTool/Services/EbayListingService.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/EbayListingTool/Services/EbayListingService.cs b/EbayListingTool/Services/EbayListingService.cs index 2ddfe55..b0cf720 100644 --- a/EbayListingTool/Services/EbayListingService.cs +++ b/EbayListingTool/Services/EbayListingService.cs @@ -20,7 +20,8 @@ public class EbayListingService private string? _fulfillmentPolicyId; private string? _paymentPolicyId; private string? _returnPolicyId; - private string? _merchantLocationKey; + + private bool _triedPolicySetup; public EbayListingService(EbayAuthService auth, EbayCategoryService categoryService) { @@ -35,6 +36,7 @@ public class EbayListingService _paymentPolicyId = null; _returnPolicyId = null; _merchantLocationKey = null; + _triedPolicySetup = false; } public async Task PostListingAsync(ListingDraft draft) @@ -92,8 +94,17 @@ public class EbayListingService var json = await res.Content.ReadAsStringAsync(); if (!res.IsSuccessStatusCode) + { + if (!_triedPolicySetup && json.Contains("20403")) + { + _triedPolicySetup = true; + await SetupDefaultBusinessPoliciesAsync(token); + await EnsurePoliciesAndLocationAsync(token, postcode); + return; + } throw new HttpRequestException( $"Could not fetch fulfillment policies ({(int)res.StatusCode}): {json}"); + } var arr = JObject.Parse(json)["fulfillmentPolicies"] as JArray; _fulfillmentPolicyId = arr?.Count > 0 @@ -519,3 +530,5 @@ public class EbayListingService return req; } } + +