mirror of
https://github.com/bitwarden/server.git
synced 2025-04-15 18:18:12 -05:00
[AC-1705] Update PayPal Verification URL to point to updated domain (#3338)
* change the url to match the paypal documentation * Adding user-agent to the header * Add a missing using statement * Add more logs * Resolving pr comments
This commit is contained in:
parent
37e9d70bee
commit
95bf85dc6e
@ -10,18 +10,22 @@ public class PayPalIpnClient
|
|||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient = new HttpClient();
|
private readonly HttpClient _httpClient = new HttpClient();
|
||||||
private readonly Uri _ipnUri;
|
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;
|
var bSettings = billingSettings?.Value;
|
||||||
_ipnUri = new Uri(bSettings.PayPal.Production ? "https://www.paypal.com/cgi-bin/webscr" :
|
_ipnUri = new Uri(bSettings.PayPal.Production ? "https://ipnpb.paypal.com/cgi-bin/webscr" :
|
||||||
"https://www.sandbox.paypal.com/cgi-bin/webscr");
|
"https://ipnpb.sandbox.paypal.com/cgi-bin/webscr");
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> VerifyIpnAsync(string ipnBody)
|
public async Task<bool> VerifyIpnAsync(string ipnBody)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Verifying IPN with PayPal at {Timestamp}: {VerificationUri}", DateTime.UtcNow, _ipnUri);
|
||||||
if (ipnBody == null)
|
if (ipnBody == null)
|
||||||
{
|
{
|
||||||
|
_logger.LogError("No IPN body.");
|
||||||
throw new ArgumentException("No IPN body.");
|
throw new ArgumentException("No IPN body.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +34,7 @@ public class PayPalIpnClient
|
|||||||
Method = HttpMethod.Post,
|
Method = HttpMethod.Post,
|
||||||
RequestUri = _ipnUri
|
RequestUri = _ipnUri
|
||||||
};
|
};
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("User-Agent", "CSharp-IPN-VerificationScript");
|
||||||
var cmdIpnBody = string.Concat("cmd=_notify-validate&", ipnBody);
|
var cmdIpnBody = string.Concat("cmd=_notify-validate&", ipnBody);
|
||||||
request.Content = new StringContent(cmdIpnBody, Encoding.UTF8, "application/x-www-form-urlencoded");
|
request.Content = new StringContent(cmdIpnBody, Encoding.UTF8, "application/x-www-form-urlencoded");
|
||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
@ -42,14 +47,14 @@ public class PayPalIpnClient
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (responseContent.Equals("INVALID"))
|
|
||||||
|
if (responseContent.Equals("INVALID"))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Received an INVALID response from PayPal: {ResponseContent}", responseContent);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
_logger.LogError("Failed to verify IPN: {ResponseContent}", responseContent);
|
||||||
{
|
throw new Exception("Failed to verify IPN.");
|
||||||
throw new Exception("Failed to verify IPN.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IpnTransaction
|
public class IpnTransaction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user