stripe / stripe-php

PHP library for the Stripe API.

Home Page:https://stripe.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Items invalid array error when creating a subscription.

Ksewellfoundry opened this issue · comments

Describe the bug

Creating a subscription through php-stripe that I got from git. In order to do so I must add customer and items.price. the documentation couldn't be clearer.

I have created the array properly yet it doesn't not accept it as an array.

Included is the my array

{
"items": {
"price": "price_1N2bG7Bs4nlLq9kduI7egQD7"
},
"customer": "cus_Nnzo6BMOhhlejZ"
}

Yet I receive the following error.

{
"error": {
"message": "Invalid array",
"param": "items",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_NSeZL29PIOq4Rl?t=1682908288",
"type": "invalid_request_error"
}
}

I have seen similar issue reported with stripe-ruby.

To Reproduce

  1. Create or retrieve customer (id)
  2. Create or retrieve product (id)
  3. Create or retrieve price (id) for that product
  4. Use customer and price (id) to create a subscription.
  5. Fails, with 400 error with details from the stripe dashboard saying invalid array on param items.

Expected behavior

Is supposed to create a subscription like the documentation specifies. This is not a difficult proposition but it is not working in the least.

I have created a payload which makes it easier to create the parameters with variables.

Code snippets

$subscriptionPayload['customer'] = $stripeID;
$subscriptionPayload['items']['price'] = $strpriceID;
	
$addSub = $stripe->subscriptions->create([
	$subscriptionPayload
]);

OS

Unbuntu 22.04

PHP version

PHP Version 8.0

Library version

stripe-php v10.12.0

API version

2022-11-15

Additional context

No response

Hey @Ksewellfoundry, Github issues are limited to bugs with the stripe-php library itself. This is more an integration support question due to your code being incorrect. It's better directed at our support team instead which will be able to help. You can contact them here: https://support.stripe.com/contact

To unblock you though the problem has to do with how you are passing the items data. It's supposed to be an array of arrays as a Subscription can have multiple Prices in it. You can see a really simple example straight in our API Reference here:

$stripe->subscriptions->create([
  'customer' => 'cus_ABC',
  'items' => [
    ['price' => 'price_123'],
  ],
]);