Reputation: 63
I am trying to create a subscription using stripe API. But it wont save once i included the "trial_period_days_" => $trial_days to the code.
$trial_days contains an integer which subtracts the days left on the present month and adds 14 days. This is executing perfectly if you echo it out it will show the number.
$trial_days = (date("m", strtotime("-1 months"))+14);
Here is my code.
$stripe_subscription = \Stripe\Subscription::create(array(
"customer" => $stripe_customer->id,
"items" => array(
"plan" => $stripe_plan->id,
"trial_period_days" => $trial_days
)
));
Here is the API JSON Map
"items": {
"object": "list",
"data": [
{
"id": "si_DPjpkyc3UVZfuI",
"object": "subscription_item",
"created": 1534221712,
"metadata": {
},
"plan": {
"id": "plan_DPjnUAy2jqHSkS",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 5000,
"billing_scheme": "per_unit",
"created": 1534221598,
"currency": "aud",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"nickname": "FPA",
"product": "prod_DPjmRCMbpYGdgJ",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
Please Help. Thanks!
Upvotes: 0
Views: 1265
Reputation: 131
You have trial_period_days
under items
when it should be at the same level as items
, like so:
$stripe_subscription = \Stripe\Subscription::create(array(
"customer" => $stripe_customer->id,
"items" => array(
"plan" => $stripe_plan->id
),
"trial_period_days" => $trial_days
));
That ought to fix your issue.
Upvotes: 1
Reputation: 1431
Can you try to use something like this
$subscription = \Stripe\Subscription::create([
'customer' => 'cus_4fdAW5ftNQow1a',
'items' => [['plan' => 'plan_CBb6IXqvTLXp3f']],
'trial_end' => 1536048827,
]);
It will work. I am using this in my current Org.
Upvotes: 0