如何解决如何使用 ASP .NET MVC 集成 PayPal 订阅 API
我按照此 PayPal 文档 https://developer.paypal.com/docs/api/subscriptions/v1 获取订阅 API。我想使用 ASP .NET MVC 调用这个 API https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriberId}。此 API 需要使用 PayPal clientID 和 secretID 的授权令牌,我已成功创建令牌,但在调用订阅 API 时遇到问题。
curl -v -X GET
https://api.sandBox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token"
另外,我刚刚使用 react JS 调用了这个 API,我得到了想要的结果。但是在 ASP .NET MVC 中如何调用这个订阅 API 呢? 反应 JS 代码:
async function checkPayPalPaymentStatus(subscriberId,access_token) {
var token = `Bearer ${access_token}`;
return await fetch(
`https://api.sandBox.paypal.com/v1/billing/subscriptions/${subscriberId}`,{
method: "GET",headers: {
Accept: "application/json","Content-Type": "application/json",Authorization: token,},}
).then((response) => response.json());
}
ASP .NET MVC 代码:
[HttpGet]
[Route("api/paypal/checkPayPalPaymentStatus")]
public async Task<object> CheckPayPalPaymentStatus(string accesstoken)
{
try
{
//
string url = "https://api.sandBox.paypal.com/v1/billing/subscriptions/" + "I-BW452GLLEP1G";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers["Authorization"] = "Bearer " + Convert.ToBase64String(Encoding.Default.GetBytes(accesstoken));
request.Accept = "application/json";
request.Method = "GET";
request.ContentType = "application/json";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
JObject jsonConvertedResponseString = JObject.Parse(responseString);
return new
{
Success = true,Message = "",Data = jsonConvertedResponseString
};
}
catch (Exception ex)
{
return new
{
Success = false,Message = ex.Message,Data = dbnull.Value
};
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。