Reputation: 4830
Upon cancel, I want to know how much time is left on the subscription's current billing cycle.
This question -- paypal-ipn-get-subscription-end-date-recurring got answered with a scenario where, upon the end of the cancellation period, a paypal event is sent at the end date. In my case, however, I want to know in advanced how much time is remaining and record a future date (like a credit) and allow the user to use that up that time or give them an advance on their signing up again with another payment method (delay their next bill for example).
There is a final_payment_date
under the deprecated billing agreements API: https://developer.paypal.com/docs/api/payments.billing-agreements/v1/ .. They say to use the subscription's API, but there is no end date available. It is possible to use the subscription API to set things up and still use this API.
Unfortunately, because I don't see a non-deprecated end-date anywhere I think I may need to dive into the implementation here:
Paypal's Monthly example from the link above. "[...] signs up on Tuesday, December 30, the subscriber is billed as follows:"
I'm close, instead of ending up on March 1st, I end up on March 2nd:
> d=new Date('2017-12-30')
2017-12-30T00:00:00.000Z
> d.setMonth(d.getMonth() + 1); d
2018-01-30T00:00:00.000Z
> d.setMonth(d.getMonth() + 1); d
2018-03-02T00:00:00.000Z
> d.setMonth(d.getMonth() + 1); d
2018-04-02T00:00:00.000Z
In any event, looks like I need to save the subscription's first billing time and as long as the plan is still active and current on payments, I'll have to calculate when their next bill will be.
Status ACTIVE
resource id I-79CLVAS5XM95
As a point of reference, the BILLING.SUBSCRIPTION.CREATED create_time is 2020-06-05T19:45:08.868Z
.
I-79CLVAS5XM95
Also save a date here, will use it to calculate the billing cycle
2020-06-05T19:35:10Z
2020-06-05T07:00:00Z
?Lookup resource.plan_id => https://api.sandbox.paypal.com/v1/billing/plans/P-1BC0896985601515LL3FNLCQ
DAY|WEEK|MONTH
and interval_count. For example, if the interval_unit is DAY with an interval_count of 2, the subscription is billed once every two days.plan.billing_cycles
[{
pricing_scheme: {
version: 1,
fixed_price: { currency_code: 'USD', value: '0.01' },
create_time: '2020-05-24T20:14:02Z',
update_time: '2020-05-24T20:14:02Z'
},
frequency: { interval_unit: 'DAY', interval_count: 1 },
tenure_type: 'REGULAR',
sequence: 1,
total_cycles: 0
}]
Upvotes: 1
Views: 1305
Reputation: 30359
This question -- paypal-ipn-get-subscription-end-date-recurring got answered with a scenario where, upon the end of the cancellation period, a paypal event is sent at the end date. In my case, however, I want to know in advanced how much time is remaining and record a future date
To know in advance, use resource.billing_info.next_billing_time
, not the resource.start_time (checkout time)
The example you quoted above:
Tuesday, December 30 = $25.99 USD
Friday, January 30 = $25.99 USD
Sunday, March 1= $25.99 USD
Wednesday, April 1= $25.99USD
Is due to February's shortness. February doesn't have a 30th to charge on, so PayPal opts to push the subscription forward to March 1 to keep everything roughly 30 days apart. This is explained in the documentation you linked to.
Upvotes: 1