|
|
|
|
@ -15,9 +15,9 @@ public class PayPalIpnClient
@@ -15,9 +15,9 @@ public class PayPalIpnClient
|
|
|
|
|
public PayPalIpnClient(IOptions<BillingSettings> billingSettings, ILogger<PayPalIpnClient> 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<bool> VerifyIpnAsync(string ipnBody) |
|
|
|
|
@ -29,19 +29,16 @@ public class PayPalIpnClient
@@ -29,19 +29,16 @@ public class PayPalIpnClient
|
|
|
|
|
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 class PayPalIpnClient
@@ -53,6 +50,7 @@ public class PayPalIpnClient
|
|
|
|
|
_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."); |
|
|
|
|
} |
|
|
|
|
|