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"
}
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.
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.
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.
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
.
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 nottrialling
, if I am not wrong, there is a spelling mistake by Stripe team. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With