I am working on future subscription, when i run the code, It create 2 subscription 1 is active and another is trial, don't know why is it creating 2 subscription ? For that active subscription it creates payment that is wrong, i have set the trial_end
as "2018-06-20" still it started subscription from today, can anyone please help me how can i resolve this issue ? here i have added my code
<?php
require_once('init.php');
if (isset($_POST['stripeToken'])) {
\Stripe\Stripe::setApiKey("*****************");
\Stripe\Stripe::setApiVersion("2018-05-21");
$token = $_POST['stripeToken'];
try {
$plan_id = time();
/************ check if plan exists ***************/
$plan_created = \Stripe\Plan::create(array(
"amount" => 1200,
"interval" => "day",
"product" => array(
"name" => "test",
),
"currency" => "usd",
"id" => $plan_id,
)
);
//Create Customer:
$customer = \Stripe\Customer::create(array(
'source' => $token,
'description'=> 'Test Customer',
'email' => 'testabc123@gmail.com',
'plan' => $plan_id
));
// Charge the order:
$dateTime = new DateTime('2018-06-20');
$date_timestamp = $dateTime->format('U');
$charge = \Stripe\Subscription::create(array(
'customer' => $customer->id,
"items" => array(
array(
"plan" => $plan_id,
),
),
"trial_end"=>$date_timestamp,
)
);
echo "<pre>";
print_r($charge);
die;
} catch (Stripe\Error\Card $e) {
// The card has been declined
}
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<form action="" method="post">
<script src="http://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="pk_test_4Ak5l6azsnSsVrpVJbIepoBu"
data-amount="5000" data-description="One year's subscription"></script>
</form>
<script>
$(document).ready(function () {
$("button").trigger("click");
});
</script>