Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe API - Next Payment date

I am signing my customers to a monthly recurring billing using the stripe API.

How can I display when their next payment is due given this respone:

"subscription": {
    "current_period_end": 1306060846,
    "status": "trialing",
    "plan": {
      "interval": "month",
      "amount": 1000,
      "trial_period_days": 0,
      "object": "plan",
      "id": "Basic"
    },
    "current_period_start": 1305974416,
    "start": 1305974416,
    "object": "subscription",
    "trial_start": 1305974416,
    "trial_end": 1306060846,
    "customer": "O8ygDbcWW9aswmxctU9z",
  },
  "id": "O8ygDbcWW9aswmxctU9z"
}
like image 626
dagda1 Avatar asked Mar 21 '14 11:03

dagda1


People also ask

Can you schedule payments on Stripe?

Stripe offers flexibility by enabling your customers to schedule payments for a future date through the Hosted Invoice Page. The scheduled payments feature lets your customers take action immediately so that they won't forget to pay.

What is a subscription cycle?

Subscription Cycle means each billing cycle which is one (1) month in length unless we communicate a different time period to you in writing at the time of sign up; Sample 1.

How does Stripe payment API work?

The API uses a single object to track each process. You create the object at the start of the process, and after every step you can check its status to see what needs to happen next. For instance, while completing a payment, a customer might try several payment methods.


2 Answers

trial_end gives the next_payment_date in timestamp.

You can transfer it into date format using date function in php.

Update: As of mid 2019, for a subscription not currently in trial, you'll find the Unix timestamp for the next billing period in the Subscription object as current_period_end.

like image 188
Pinu Avatar answered Oct 25 '22 20:10

Pinu


You can check the status of the subscription as follows:

customer = Stripe::Customer.retrieve("cus_7G9REJXtaW05QY")
subscription = customer.subscriptions.retrieve("sub_7HFIqkWIDqEhho")

if subscription.status == 'trialing'
  next_payment_date = Time.at(subscription.trial_end).strftime("%B %d, %Y")
end

After the trail ends you can check the current_period_end attribute from the subscription

next_payment_date = Time.at(subscription.current_period_end).strftime("%B %d, %Y")

Moreover, you can use the current_period_end if you have only one month trial. That would work in all the cases.

PS: For the status check, the word is trialing and not trialling, if I am not wrong, there is a spelling mistake by Stripe team. :-)

like image 20
Sagar Ranglani Avatar answered Oct 25 '22 21:10

Sagar Ranglani