fix: wire up auto Business Policy setup trigger on 20403 error

This commit is contained in:
2026-04-17 01:42:09 +01:00
parent 1c906c5f6c
commit c34a2fd5a5

View File

@@ -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<string> 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;
}
}