chargebee / chargebee-php

PHP library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=php
MIT License
72 stars 62 forks source link

Util::serialize isnt serializing correctly #35

Closed kriskoch closed 2 years ago

kriskoch commented 3 years ago

When data is being seriazled it is losing the prefix.

For example I was using the function HostedPage::checkoutOneTime. My data array looked something like this

$data = [
'customer' => ['email'=> 'example@example.org', 'id' => '_test12345_'],
'addons' => ['id'=> ['test-addon']]]

as per the documentation - https://apidocs.chargebee.com/docs/api/hosted_pages?prod_cat_ver=1&lang=curl#checkout_one-time_payments

However after Util::serialize is called the data is being transformed like the following'

$serialized = ['customer[email]' => 'example@example.org', 'customer[id]' => '_test12345_', 'id[0]' => 'test-addon']

As you can seem the addons prefix is missing from the serialized data causing addon selection not working.

But I am not even sure why you are calling Util::serialize to begin with?? You are using guzzle, pass in the data array directly into. So skip the whole $ser_params = Util::serialize($params);
pass $params directly into Guzzle::doRequest

kriskoch commented 3 years ago

Hmm never mind, I noticed in UtilTest.php you are suppose to configure it this way 'addons' => [['id' => 'test-addon'], ['id' => 'test-addon2']]

Not sure why the configuration is different than the API shows, and especially not documented. But at least that works.

cb-jagrutijain commented 2 years ago

Hi @kriskoch may I know why the 'addons' => [id] is an array and not just a string like others, eg customer id? Is there a particular place in the API document that mentioned or pointed you to use an array for addon id?

cb-yateshmathuria commented 2 years ago

Closing this issue.