Reputation: 28898
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"
}
Upvotes: 20
Views: 18238
Reputation: 5691
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. :-)
Upvotes: 5
Reputation: 412
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
.
Upvotes: 29
Reputation: 4539
As far as I know, it is not fully possible. trial_end
(if set) will be the first payment date. current_period_end
will be the next charge attempt, but if there is a decline, the next charges will follow the schedule in the settings (e.g. retry after 1 day, retry after 3 days, cancel). You must track declines and to calculate the next payment date using the rules from the settings.
Upvotes: 1
Reputation: 203
$timestamp = "2306060846";
$next_payment_date = date('Y-m-d',$timestamp));
It gives you time in Y-m-d format
Upvotes: 9