I started using stripe for payments and have my test environment set up. Everything is working fine until the subscription is about the end. Like the tutorial said on Stripe's homepage, you should save the subscription ending date in database which I am doing.
So lets say user cancelled or his subscription ended. He is trying to log in again and is prompted a message to sign up for subscription again. Here I am getting the date and re-subscribing the user:
//create subscription
$customer = \Stripe\Subscription::create(array(
"customer" => $customer_id,
"plan" => "test"
));
//get curent end period
$end_date = $customer->current_period_end;
//getting something like this 1472625732
$next_payment_date = date('Y-m-d',$end_date);
which gets me the date from stripe response. I then convert it to timestamp that I can use in mysql and then I insert it. Everything that works but I think my subscription is cancelled too early.
In stripe I see this:
Current period:
2016/08/30 to 2016/08/31
And in my db I see 2016-08-31 00:00:00
, which cancels the subscription at midnight but stripe says the subscription is still active.
In my login script I check for that date in database and it says my subscription is not active which is not true.
Here comes my question, how can I prevent that kind of behavior? Is there any way to get the time as well when the subscription ends or is there a default time set up by stripe?
Problem is that timestamp 1472625732 that You get from the stripe is GMT: Wednesday, August 31, 2016 6:42:12 AM and after the call date('Y-m-d',$end_date);
on this timestamp, You lost(truncate) time part 6:42:12, and this lead that on stripe side subscription ends on August 31, 2016 6:42:12 AM While according Your database subscription ends on August 31, 2016 00:00:00 AM
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