如何在未来的日期向 PayPal 添加取消订阅功能?
我正在寻找一种方法来实现贝宝订阅的未来日期取消,在他们的文档或任何地方都找不到它。我希望它能像这样工作,所以当订阅结束前还有 14 天或更短的时间时,我们无法结束本月的计费周期(我们将在下个月结束)。目前取消工作正常:这是到目前为止的代码。
paypal.configure({
mode: process.env.NODE_ENV === 'development' ? 'sandbox' : 'live',
client_id: process.env.NODE_ENV === 'development' ? paypalConfig.sandboxClientId : paypalConfig.productionClientId,
client_secret: process.env.NODE_ENV === 'development' ? paypalConfig.sandboxSecret : paypalConfig.productionSecret
});
const cancelBillingAgreementSync = Meteor.wrapAsync(paypal.billingAgreement.cancel, paypal.billingAgreement);
const getBillingAgreementSync = Meteor.wrapAsync(paypal.billingAgreement.get, paypal.billingAgreement);
try {
const oldBillingAgreement = getBillingAgreementSync(user.billing.paypalBillingAgreementId);
if (oldBillingAgreement && oldBillingAgreement.state && oldBillingAgreement.state.toLowerCase() === 'active') {
cancelBillingAgreementSync(user.billing.paypalBillingAgreementId, { note: 'Plan cancellation' });
if (manual) {
Meteor.users.update(Meteor.userId(), { $set: { 'plan.cancelled': true } });
}
}
} catch (err) {
console.error(err);
throw new Meteor.Error(err.code || err.type || 500, err.message || err.reason);
}```
I am looking for a way to implement future date cancellation to paypal subscription, can't find it in their docs nor anywhere. I want it to work like that so when we have 14 days or less before subscription ends we cannot end the billing cycle this month (we are ending it the next month). It is working normally for cancellation in present time: here is the code so far.
paypal.configure({
mode: process.env.NODE_ENV === 'development' ? 'sandbox' : 'live',
client_id: process.env.NODE_ENV === 'development' ? paypalConfig.sandboxClientId : paypalConfig.productionClientId,
client_secret: process.env.NODE_ENV === 'development' ? paypalConfig.sandboxSecret : paypalConfig.productionSecret
});
const cancelBillingAgreementSync = Meteor.wrapAsync(paypal.billingAgreement.cancel, paypal.billingAgreement);
const getBillingAgreementSync = Meteor.wrapAsync(paypal.billingAgreement.get, paypal.billingAgreement);
try {
const oldBillingAgreement = getBillingAgreementSync(user.billing.paypalBillingAgreementId);
if (oldBillingAgreement && oldBillingAgreement.state && oldBillingAgreement.state.toLowerCase() === 'active') {
cancelBillingAgreementSync(user.billing.paypalBillingAgreementId, { note: 'Plan cancellation' });
if (manual) {
Meteor.users.update(Meteor.userId(), { $set: { 'plan.cancelled': true } });
}
}
} catch (err) {
console.error(err);
throw new Meteor.Error(err.code || err.type || 500, err.message || err.reason);
}```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要集成当前版本的 PayPal 订阅,则不会使用结算协议。订阅将根据您指定的计划计费。
付款人随时可以取消订阅,因此您需要提前计费。没有办法“阻止”过去 14 天内取消付款,也无法保证下一次付款能够成功计费。
If you are integrating the current version of PayPal Subscriptions, billing agreements are not used. Subscriptions will bill according to the Plan you specify.
Subscriptions can always be cancelled by the payer, so you need to bill ahead. There is no way to "prevent" one from being cancelled during the last 14 days, nor will there ever be any guarantee that the next payment will bill successfully.