jcalfee314
jcalfee314

Reputation: 4830

Finding the paypal subscription end date upon cancel

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:

https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/subscription-billing-cycles/?mark=cycle#

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.

BILLING.SUBSCRIPTION.CREATED (webhook received)

Status ACTIVE resource id I-79CLVAS5XM95

As a point of reference, the BILLING.SUBSCRIPTION.CREATED create_time is 2020-06-05T19:45:08.868Z.

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

Answers (1)

Preston PHX
Preston PHX

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

Related Questions