chargebee / chargebee-php

PHP library for the Chargebee API.

Home Page:https://apidocs.chargebee.com/docs/api?lang=php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON payload issue

niolap opened this issue · comments

Hi there :)

I would like to send a payload as JSON to Chargebee API but it only works in URL encoded format, not in JSON format.
I need to send JSON from the requests Python package without the Chargebee wrapper.
Any idea?

As URL encoded: does work

$ curl  https://***********-test.chargebee.com/api/v2/payment_sources/create_card \
>      -u **************************************:\
>      -d customer_id="cbdemo_douglas" \
>      -d card[number]="378282246310005" \
>      -d card[cvv]="100" \
>      -d card[expiry_year]=2022 \
>      -d card[expiry_month]=12
{
    "payment_source": {
        "id": "pm_BTcLSfTGD1TtShje",
        "updated_at": 1662057402,
        "resource_version": 1662057402861,
        ...
        }
    }
}

As JSON: does not work

$ curl https://***********-test.chargebee.com/api/v2/payment_sources/create_card \
>      -u **************************************:\
>      -H 'content-type: application/json' \
>      -H 'accept: application/json' \
>      -d '{
>       "customer_id":"cbdemo_douglas",
>       "card":{
>         "number":"378282246310005",
>         "cvv":"100",
>         "expiry_year":"2022",
>         "expiry_month":"12"
>       }
>     }'
{"message":"customer_id : cannot be blank","type":"invalid_request","api_error_code":"invalid_request","param":"customer_id","error_code":"param_required","error_msg":"cannot be blank","error_param":"customer_id","http_status_code":400}

re-opened in the correct repo chargebee/chargebee-python#54