mirror of
https://github.com/bitwarden/server.git
synced 2025-02-02 23:41:21 +01:00
[AC-1783] PayPal IPN Changes (#3404)
* Reverted changes to the domain for the PayPal IPN client, and added more logging * Removing User-Agent as it wasn't in the IPN client previously
This commit is contained in:
parent
a3e440209a
commit
abc7b35a3d
@ -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
|
||||
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
|
||||
_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.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user