debug: log all eBay setup API responses (opt_in + policy creation) to crash_log.txt
This commit is contained in:
@@ -218,6 +218,14 @@ public class EbayListingService
|
|||||||
/// Called automatically on first 20403 error. Opts the account in to SELLING_POLICY_MANAGEMENT
|
/// Called automatically on first 20403 error. Opts the account in to SELLING_POLICY_MANAGEMENT
|
||||||
/// then creates minimal default policies so posting can proceed without manual eBay setup.
|
/// then creates minimal default policies so posting can proceed without manual eBay setup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private static void LogSetup(string msg)
|
||||||
|
{
|
||||||
|
var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EbayListingTool");
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
File.AppendAllText(Path.Combine(dir, "crash_log.txt"),
|
||||||
|
$"{DateTime.Now:HH:mm:ss} [Setup] {msg}{Environment.NewLine}");
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SetupDefaultBusinessPoliciesAsync(string token)
|
private async Task SetupDefaultBusinessPoliciesAsync(string token)
|
||||||
{
|
{
|
||||||
// Step 1: opt in to the Business Policies programme
|
// Step 1: opt in to the Business Policies programme
|
||||||
@@ -227,9 +235,11 @@ public class EbayListingService
|
|||||||
using var req = MakeRequest(HttpMethod.Post,
|
using var req = MakeRequest(HttpMethod.Post,
|
||||||
$"{_auth.BaseUrl}/sell/account/v1/program/opt_in", token);
|
$"{_auth.BaseUrl}/sell/account/v1/program/opt_in", token);
|
||||||
req.Content = new StringContent(optInBody, Encoding.UTF8, "application/json");
|
req.Content = new StringContent(optInBody, Encoding.UTF8, "application/json");
|
||||||
await _http.SendAsync(req); // 204 = success; ignore other responses
|
var optInRes = await _http.SendAsync(req);
|
||||||
|
var optInBody2 = await optInRes.Content.ReadAsStringAsync();
|
||||||
|
LogSetup($"opt_in → {(int)optInRes.StatusCode} {optInBody2}");
|
||||||
}
|
}
|
||||||
catch { /* opt-in failure is non-fatal — account may already be opted in */ }
|
catch (Exception ex) { LogSetup($"opt_in exception: {ex.Message}"); }
|
||||||
|
|
||||||
// Step 2: create one policy of each required type (ignore errors — they may already exist)
|
// Step 2: create one policy of each required type (ignore errors — they may already exist)
|
||||||
await TryCreateFulfillmentPolicyAsync(token);
|
await TryCreateFulfillmentPolicyAsync(token);
|
||||||
@@ -271,9 +281,11 @@ public class EbayListingService
|
|||||||
$"{_auth.BaseUrl}/sell/account/v1/fulfillment_policy", token);
|
$"{_auth.BaseUrl}/sell/account/v1/fulfillment_policy", token);
|
||||||
req.Content = new StringContent(
|
req.Content = new StringContent(
|
||||||
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||||
await _http.SendAsync(req);
|
var res2 = await _http.SendAsync(req);
|
||||||
|
var body2 = await res2.Content.ReadAsStringAsync();
|
||||||
|
LogSetup($"fulfillment_policy create → {(int)res2.StatusCode} {body2}");
|
||||||
}
|
}
|
||||||
catch { }
|
catch (Exception ex) { LogSetup($"fulfillment_policy exception: {ex.Message}"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TryCreatePaymentPolicyAsync(string token)
|
private async Task TryCreatePaymentPolicyAsync(string token)
|
||||||
@@ -291,9 +303,11 @@ public class EbayListingService
|
|||||||
$"{_auth.BaseUrl}/sell/account/v1/payment_policy", token);
|
$"{_auth.BaseUrl}/sell/account/v1/payment_policy", token);
|
||||||
req.Content = new StringContent(
|
req.Content = new StringContent(
|
||||||
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||||
await _http.SendAsync(req);
|
var res2 = await _http.SendAsync(req);
|
||||||
|
var body2 = await res2.Content.ReadAsStringAsync();
|
||||||
|
LogSetup($"payment_policy create → {(int)res2.StatusCode} {body2}");
|
||||||
}
|
}
|
||||||
catch { }
|
catch (Exception ex) { LogSetup($"payment_policy exception: {ex.Message}"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TryCreateReturnPolicyAsync(string token)
|
private async Task TryCreateReturnPolicyAsync(string token)
|
||||||
@@ -314,9 +328,11 @@ public class EbayListingService
|
|||||||
$"{_auth.BaseUrl}/sell/account/v1/return_policy", token);
|
$"{_auth.BaseUrl}/sell/account/v1/return_policy", token);
|
||||||
req.Content = new StringContent(
|
req.Content = new StringContent(
|
||||||
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||||
await _http.SendAsync(req);
|
var res2 = await _http.SendAsync(req);
|
||||||
|
var body2 = await res2.Content.ReadAsStringAsync();
|
||||||
|
LogSetup($"return_policy create → {(int)res2.StatusCode} {body2}");
|
||||||
}
|
}
|
||||||
catch { }
|
catch (Exception ex) { LogSetup($"return_policy exception: {ex.Message}"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreateMerchantLocationAsync(string token, string postcode)
|
private async Task CreateMerchantLocationAsync(string token, string postcode)
|
||||||
@@ -533,3 +549,5 @@ public class EbayListingService
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user