简体   繁体   English

PayPal 订阅 IPN 下一个账单日期

[英]PayPal Subscription IPN Next Billing Date

My web app uses PayPal monthly subscriptions.我的网络应用程序使用 PayPal 每月订阅。 I receive IPN notifications when payments are made, users signup/cancel, etc and this all seems to work well.我在付款、用户注册/取消等时收到 IPN 通知,这一切似乎都运行良好。

One thing that appears to be missing from the IPN messages is any sort of indication about the next billing date. IPN 消息中似乎缺少的一件事是有关下一个计费日期的任何指示。 https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#id091EB0901HT https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/#id091EB0901HT

At first I thought that since it's a monthly subscription, I can simply add a month to the previous date, but PayPal seems to have a funky way of figuring out the next payment date - it's not always 30 or 31 days or a month.起初我以为因为它是按月订阅,所以我可以简单地在前一个日期上加一个月,但 PayPal 似乎有一种确定下一个付款日期的时髦方法——它并不总是 30 或 31 天或一个月。

The next billing date is available from within PayPal itself, but doesn't seem to be sent along in any IPN messages.下一个计费日期可从 PayPal 内部获得,但似乎没有在任何 IPN 消息中发送。

Does anyone know of a simple way to work this out from the information that is available in the IPN messages?有谁知道从 IPN 消息中可用的信息中解决这个问题的简单方法?

I recently came across this issue too.我最近也遇到了这个问题。 I'm not sure one can get a consistent scheme as to what a "month" of subscription means.我不确定人们能否就订阅“一个月”的含义获得一致的方案。 For instance, if you sign up for your service on the 31st of March, is the next payment due on the 30th of April or on the 1st of May?例如,如果您在 3 月 31 日注册服务,下一次付款是在 4 月 30 日还是 5 月 1 日到期? You just have to pick one and communicate clearly it to your users.您只需要选择一个并将其清楚地传达给您的用户。 Its unfortunate PayPal doesn't afford us this courtesy.不幸的是,PayPal 无法为我们提供这种礼遇。

In the end I decided to give the users access to the service for 32 days or 367 days, for monthly and annual subscriptions respectively.最后,我决定让用户访问该服务 32 天或 367 天,分别按月和按年订阅。 I know you may "lose" out on a day or two here and there but I think its better to allow some grace access rather than risk giving the user less time than paid for.我知道你可能会在这里和那里“输掉”一两天,但我认为最好允许一些宽限访问,而不是冒险给用户的时间少于支付的时间。

If all goes well, it doesn't actually matter how long you activated the account for if you also listen for the subscr_eot and subscr_payment IPNs (see https://stackoverflow.com/a/1195246/1852838 ).如果一切顺利,如果您还收听subscr_eotsubscr_payment IPN,激活帐户的时间实际上并不重要(请参阅https://stackoverflow.com/a/1195246/1852838 )。 I renew the above period from the date of the next payment so that the subscription is always in sync with the PayPal payment cycle.我从下一次付款之日起续订上述期限,以便订阅始终与 PayPal 付款周期同步。 PayPal will send you the eot IPN when the last paid period ends so you can terminate the subscription on the server side. PayPal 将在最后一个付费期结束时向您发送eot IPN,以便您可以在服务器端终止订阅。 This means it doesn't matter so much how much "grace" you decide to give them.这意味着你决定给予他们多少“恩典”并不重要。

In terms of a providing a "paid until" I would simply provide the "grace" date as you are the one who actually decides how long this is.就提供“支付至”而言,我将简单地提供“宽限期”日期,因为您是真正决定这一期限的人。 I would, however, recommend that you also let them know that they should make a payment by the next most conservative estimate for the next payment.但是,我建议您也让他们知道他们应该在下一次付款时按照最保守的估计付款。 This would be 30 days after the last payment or the end of the month if that falls after it.这将是最后一次付款后的 30 天或月末(如果在此之后)。

this might help you.这可能会帮助你。 to specify exactly days, do not use paypal's MONTHLY type.要准确指定天数,请不要使用 paypal 的MONTHLY类型。 instead specify DAY like this:而是像这样指定DAY

following will charge the client each 30 days:以下将每 30 天向客户收费:

    ->setfrequency_interval('30')
    ->setfrequency('DAY')

Monthly recurring payments were collected roughly every 30 days.每月定期付款大约每 30 天收取一次。

If the subscription terms are $25.99 USD a month and the subscriber signs up on Thursday, July 31. The subscriber is billed as follows:如果订阅条款为每月 25.99 美元,并且订阅者在 7 月 31 日星期四注册。订阅者的账单如下:

  • Thursday, July 31 = $25.99 USD 7 月 31 日星期四 = 25.99 美元
  • Saturday, August 31 = $25.99 USD 8 月 31 日星期六 = 25.99 美元
  • Wednesday, October 1= $25.99 USD 10 月 1 日,星期三 = 25.99 美元
  • Saturday, November 1= $25.99 USD 11 月 1 日星期六 = 25.99 美元

Worst case scenario is when the original subscription date is on the 31st of the month .最坏的情况是原始订阅日期是当月 31 日

I was allowing for a month and then +1 day just to be safe, but then this happened.为了安全起见,我允许一个月,然后 +1 天,但后来发生了这种情况。

Subscription started on 31st 31日开始订阅

The customer subscribed and paid on 31 Jan. Because that's the last day of the month, PayPal charged them again on 28 Feb. My code then figured next payment date (+1 day grace) = 29 March.客户在 1 月 31 日订阅并付款。因为那是当月的最后一天,PayPal 于 2 月 28 日再次向他们收费。然后我的代码计算出下一个付款日期(+1 天宽限期)= 3 月 29 日。 But, of course it's not.但是,当然不是。 It's 31 Mar.现在是 3 月 31 日。

I keep track of that "next payment date" even though it's not 100% accurate and show it on the user's profile page.我会跟踪那个“下一个付款日期”,即使它不是 100% 准确并显示在用户的个人资料页面上。 It seems crazy to me that PayPal don't include this vital piece of information in the IPN data. PayPal 没有在 IPN 数据中包含这一重要信息,这对我来说似乎很疯狂。

Solution 1解决方案 1

One option is to allow a longer grace period, or to make exceptions if the payment date is the last day of any given month.一种选择是允许更长的宽限期,或者如果付款日期是任何给定月份的最后一天,则可以例外。 This works okay, but shows slightly wrong info to the user some of the time.这可以正常工作,但有时会向用户显示稍微错误的信息。

Solution 2解决方案 2

Track the day-of-month value of the original date of the subscription.跟踪订阅原始日期的月份值。 That way you can always refer back to it.这样你就可以随时参考它。 So in my example, that day-of-month is 31. I keep that value, and then whenever I need to update the "next payment date" I can just use that day of the month on the upcoming month.因此,在我的示例中,该日期为 31。我保留该值,然后每当我需要更新“下一个付款日期”时,我就可以在下个月使用该月的那一天。 For shorter months, just use the last day of the month if it is < the stored day-of-month.对于较短的月份,如果该月的最后一天 < 存储的月份,则只需使用该月份的最后一天。

 let m  = moment.utc('2021-05-31T06:52:19Z')
 for (let i = 0; i < 20; i++) {
   const date = m.get('date')
   m.add(3, 'month') // any number of months
   if ((date === 29 || date === 30) && m.get('month') === 1) {
     m.add(1, 'day')
   }
   console.log(m.format())
}

If it is incorrect, let me know, please.如果不正确,请告诉我。 I tested it on real subscriptions for 1, 2, 3 and 4 months.我在实际订阅中测试了 1、2、3 和 4 个月。 At least first next billing date is same至少第一个下一个计费日期相同

Also it matches with examples from docs, except this:它也与文档中的示例相匹配,除了这个:

Example: Monthly recurring payments due and collected on the 31st If the subscription terms are $25.99 USD a month and the subscriber signs up on Thursday, July 31. The subscriber is billed as follows:示例:在 31 日到期并收取的每月定期付款 如果订阅条款为每月 25.99 美元,并且订阅者在 7 月 31 日星期四注册。订阅者的账单如下:

Thursday, July 31 = $25.99 USD Saturday, August 31 = $25.99 USD Wednesday, October 1 = $25.99 USD Saturday, November 1 = $25.99 USD and so on 7 月 31 日星期四 = 25.99 美元 8 月 31 日星期六 = 25.99 美元 10 月 1 日星期三 = 25.99 美元 11 月 1 日星期六 = 25.99 美元等等

But matches this:但匹配这个:

Recurring payments are collected on the same day of the month.定期付款在每月的同一天收取。 If the initial recurring payment falls on the 31st, PayPal eventually adjusts the billing cycle to the last of the month.如果最初的定期付款是在 31 日,PayPal 最终会将结算周期调整为当月的最后一天。 If the initial recurring payment falls on the 29th or 30th, PayPal adjusts the billing cycle to the first of the month on the following February.如果初始定期付款在 29 日或 30 日进行,PayPal 会将结算周期调整为次年 2 月的第一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM