diff --git a/src/Billing/Utilities/PayPalIpnClient.cs b/src/Billing/Utilities/PayPalIpnClient.cs index 1762f92a11fc..0534faf76c1b 100644 --- a/src/Billing/Utilities/PayPalIpnClient.cs +++ b/src/Billing/Utilities/PayPalIpnClient.cs @@ -15,9 +15,9 @@ public class PayPalIpnClient public PayPalIpnClient(IOptions billingSettings, ILogger logger) { var bSettings = billingSettings?.Value; - _ipnUri = new Uri(bSettings.PayPal.Production ? "https://ipnpb.paypal.com/cgi-bin/webscr" : - "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr"); _logger = logger; + _ipnUri = new Uri(bSettings.PayPal.Production ? "https://www.paypal.com/cgi-bin/webscr" : + "https://www.sandbox.paypal.com/cgi-bin/webscr"); } public async Task VerifyIpnAsync(string ipnBody) @@ -29,19 +29,16 @@ public async Task VerifyIpnAsync(string ipnBody) throw new ArgumentException("No IPN body."); } - var request = new HttpRequestMessage - { - Method = HttpMethod.Post, - RequestUri = _ipnUri - }; - _httpClient.DefaultRequestHeaders.Add("User-Agent", "CSharp-IPN-VerificationScript"); + var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = _ipnUri }; var cmdIpnBody = string.Concat("cmd=_notify-validate&", ipnBody); request.Content = new StringContent(cmdIpnBody, Encoding.UTF8, "application/x-www-form-urlencoded"); var response = await _httpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { + _logger.LogError("Failed to receive a successful response from PayPal IPN verification service. Response: {Response}", response); throw new Exception("Failed to verify IPN, status: " + response.StatusCode); } + var responseContent = await response.Content.ReadAsStringAsync(); if (responseContent.Equals("VERIFIED")) { @@ -53,6 +50,7 @@ public async Task VerifyIpnAsync(string ipnBody) _logger.LogWarning("Received an INVALID response from PayPal: {ResponseContent}", responseContent); return false; } + _logger.LogError("Failed to verify IPN: {ResponseContent}", responseContent); throw new Exception("Failed to verify IPN."); }