如何在未来的日期向 PayPal 添加取消订阅功能?

发布于 2025-01-13 00:11:41 字数 1337 浏览 0 评论 0原文

我正在寻找一种方法来实现贝宝订阅的未来日期取消,在他们的文档或任何地方都找不到它。我希望它能像这样工作,所以当订阅结束前还有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2025-01-20 00:11:41

如果您要集成当前版本的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文