Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AC-1705] Update PayPal Verification URL to point to updated domain #3338

Merged
21 changes: 13 additions & 8 deletions src/Billing/Utilities/PayPalIpnClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ public class PayPalIpnClient
{
private readonly HttpClient _httpClient = new HttpClient();
private readonly Uri _ipnUri;
private readonly ILogger<PayPalIpnClient> _logger;

public PayPalIpnClient(IOptions<BillingSettings> billingSettings)
public PayPalIpnClient(IOptions<BillingSettings> billingSettings, ILogger<PayPalIpnClient> logger)
{
var bSettings = billingSettings?.Value;
_ipnUri = new Uri(bSettings.PayPal.Production ? "https://www.paypal.com/cgi-bin/webscr" :
"https://www.sandbox.paypal.com/cgi-bin/webscr");
_ipnUri = new Uri(bSettings.PayPal.Production ? "https://ipnpb.paypal.com/cgi-bin/webscr" :
"https://ipnpb.sandbox.paypal.com/cgi-bin/webscr");
_logger = logger;
}

public async Task<bool> VerifyIpnAsync(string ipnBody)
{
_logger.LogInformation("Verifying IPN with PayPal at {Timestamp}: {VerificationUri}", DateTime.UtcNow, _ipnUri);
if (ipnBody == null)
{
_logger.LogError("No IPN body.");
throw new ArgumentException("No IPN body.");
}

Expand All @@ -30,6 +34,7 @@ public async Task<bool> VerifyIpnAsync(string ipnBody)
Method = HttpMethod.Post,
RequestUri = _ipnUri
};
_httpClient.DefaultRequestHeaders.Add("User-Agent", "CSharp-IPN-VerificationScript");
cyprain-okeke marked this conversation as resolved.
Show resolved Hide resolved
var cmdIpnBody = string.Concat("cmd=_notify-validate&", ipnBody);
cyprain-okeke marked this conversation as resolved.
Show resolved Hide resolved
request.Content = new StringContent(cmdIpnBody, Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await _httpClient.SendAsync(request);
Expand All @@ -42,14 +47,14 @@ public async Task<bool> VerifyIpnAsync(string ipnBody)
{
return true;
}
else if (responseContent.Equals("INVALID"))

if (responseContent.Equals("INVALID"))
{
_logger.LogWarning("Received an INVALID response from PayPal: {ResponseContent}", responseContent);
return false;
}
else
{
throw new Exception("Failed to verify IPN.");
}
_logger.LogError("Failed to verify IPN: {ResponseContent}", responseContent);
throw new Exception("Failed to verify IPN.");
}

public class IpnTransaction
Expand Down
Loading