我正在尝试将Paypal集成到NodeJS中的应用程序中。我使用REST API,因为官方的npm数据包已被弃用。假设我有一个有两个计划的产品,planA
和planB
,这是订阅等经常性支付所必需的。假设一个客户订阅了planA,费用为10美元。过了一段时间,他想转向成本为20美元的planB,解锁平台中的优质内容。
我找到了API:POST/v1/billing/subscriptions/{id}/revise
哪一个应该能够发送planIDplanB
来切换到它。您也可以发送effective_time
字段来指定更改何时生效。调用这个API后,Paypal回复了6个链接,我使用第一个(approve
(将客户重定向到Paypal域,以确认其切换计划的意愿。用户登录后,确认并点击";接受并订阅";对于新计划,页面总是给我以下错误:Things don't appear to be working at the moment. Please try again later.
,尽管计划更改顺利(我可以通过仪表板进行验证(。
我想知道我该怎么做才能避免那个错误。我想澄清的是,在设置中,通过仪表板,在Account settings
->Website payments
->Website preferences
,我暂时具有选项Block non-encrypted website payment
到Off
。提前感谢大家!
设置"阻止未加密的网站支付";与此问题无关,也不会产生任何影响。它只适用于传统的纯HTML支付,您不应该对此感到担忧。
Edit:啊,是的,重定向集成需要一个带有return_url的application_context。对于与SDK一起使用,不使用redirect_url,因此API不需要该字段。
上一个答案如下:
您描述的问题似乎是PayPal网站的问题,可能只发生在沙盒模式或某些浏览器/cookie中。您可以根据需要进行测试,并在需要时联系PayPal的支持人员。
也可以使用JS SDK进行修改,而不是重定向。对于客户端集成(没有API(,可以使用actions.subscription.revise
来完成。在SDK引用中搜索该文本。
要将JS SDK与您正在使用的API调用结合起来,请让您的按钮代码从服务器获取修改后的订阅ID。这里有一个创建的示例,您可以将其修改为修订,因为它本质上是一样的(您可能只是使用/revise
端点/path/on/your/server(
<script src="https://www.paypal.com/sdk/js?client-id=..........&vault=true&intent=subscription"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
style: {
label:'subscribe' //Optional text in button
},
createSubscription: function(data, actions) {
return fetch('/path/on/your/server/paypal/subscription/create/', {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(serverData) {
console.log(serverData);
return serverData.id;
});
},
onApprove: function(data, actions) {
/* Optional: At this point, notify your server of the activated subscription...
fetch('/path/on/your/server/paypal/subscription/activated/' + data.subscriptionID , {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(serverData) {
//
});
*/
//You could additionally subscribe to a webhook for the BILLING.SUBSCRIPTION.ACTIVATED event (just in case), as well as other future subscription events
//Ref: https://developer.paypal.com/docs/api-basics/notifications/webhooks/event-names/#subscriptions
// Show a message to the buyer, or redirect to a success page
alert('You successfully subscribed! ' + data.subscriptionID);
}
}).render('#paypal-button-container');
</script>