2

I'm trying to make the below work:

$company->subscription('default')->swapAndInvoice($price_id,['quantity'=>$quantity]);

But I'm getting the following message:

Received both items and quantity parameters. Please pass in only one.

I've also tried this:

$company->subscription('default')->swapAndInvoice($price_id,['items' => ['quantity'=>$quantity]]);

But then I get an invalid array error:

[2020-11-20 10:48:53] local.ERROR: Invalid array {"userId":1,"exception":"[object] (Stripe\\Exception\\InvalidRequestException(code: 0): Invalid array at C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\Exception\\ApiErrorException.php:38)
[stacktrace]
#0 C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\Exception\\InvalidRequestException.php(35): Stripe\\Exception\\ApiErrorException::factory('Invalid array', 400, '{\
  \"error\": {\
...', Array, Object(Stripe\\Util\\CaseInsensitiveArray), NULL)
#1 C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\ApiRequestor.php(187): Stripe\\Exception\\InvalidRequestException::factory('Invalid array', 400, '{\
  \"error\": {\
...', Array, Object(Stripe\\Util\\CaseInsensitiveArray), NULL, 'items')
#2 C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\ApiRequestor.php(149): Stripe\\ApiRequestor::_specificAPIError('{\
  \"error\": {\
...', 400, Object(Stripe\\Util\\CaseInsensitiveArray), Array, Array)
#3 C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\ApiRequestor.php(461): Stripe\\ApiRequestor->handleErrorResponse('{\
  \"error\": {\
...', 400, Object(Stripe\\Util\\CaseInsensitiveArray), Array)
#4 C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\ApiRequestor.php(118): Stripe\\ApiRequestor->_interpretResponse('{\
  \"error\": {\
...', 400, Object(Stripe\\Util\\CaseInsensitiveArray))
#5 C:\\xampp\\htdocs\\myproject\\vendor\\stripe\\stripe-php\\lib\\ApiOperations\\Request.php(63): Stripe\\ApiRequestor->request('post', '/v1/subscriptio...', Array, Array)

What's the right way of passing a new quantity when swaping to a new plan?

Inigo EC
  • 2,178
  • 3
  • 22
  • 31

1 Answers1

3

So I kept digging, and I found out the way to call it is:

$company->subscription('default')->swapAndInvoice([$price_id => ['quantity' => $quantity]]);

I eventually found this out when I went from this issue, to this commit. There is a function called test_swapping_subscription_and_adopting_new_quantity where you can see how it's done.

Inigo EC
  • 2,178
  • 3
  • 22
  • 31