shakurov / laravel-coinbase

Laravel wrapper for the Coinbase Commerce API
MIT License
44 stars 24 forks source link

createCheckout fails with "type":"invalid_request","message":"Requested info must specify desired customer info fields" #14

Closed scottsuhy closed 1 year ago

scottsuhy commented 3 years ago

Required Information

Expected behaviour

Actual behaviour

Simple call to API

$checkout = Coinbase::createCheckout([
    'name' => 'Name',
    'description' => 'Description',
    'local_price' => [
        'amount' => 100,
        'currency' => 'USD',
    ],
    'pricing_type' => 'fixed_price',
]);

results in error:

[2021-07-13 15:35:43] local.ERROR: Client error: `POST https://api.commerce.coinbase.com/checkouts?name=Name&description=Description&local_price%5Bamount%5D=100&local_price%5Bcurrency%5D=USD&pricing_type=fixed_price` resulted in a `400 Bad Request` response:
{"error":{"type":"invalid_request","message":"Requested info must specify desired customer info fields"}}

even though 'request_info' is optional per https://commerce.coinbase.com/docs/api/#create-a-checkout

Steps to reproduce

Generic install on generic laravel create controller with the following function

public function createCheckout(Request $request){
    $checkout = Coinbase::createCheckout([
        'name' => 'Name',
        'description' => 'Description',
        'local_price' => [
            'amount' => 100,
            'currency' => 'USD',
        ],
        'pricing_type' => 'fixed_price',
    ]);

    return $checkout;
}

Extra details

Charge and Events api's work as expected.

Using curl works fine:

COINBASE_COMMERCE_API_KEY=aaaaa-bbbbb-ccccc-ddddd
curl -X POST https://api.commerce.coinbase.com/checkouts \
-H "Content-Type: application/json" \
-H "X-CC-Api-Key: $COINBASE_COMMERCE_API_KEY" \
-H "X-CC-Version: 2018-03-22" \
-d '{"name": "The Sovereign Individual", "description": "Mastering the Transition to the Information Age", "local_price": {"amount": "1.00", "currency": "USD"}, "pricing_type": "fixed_price", "requested_info": ["email"]}'

and once I create it with Curl, getCheckouts works fine too.

alykhan2212 commented 2 years ago

@scottsuhy Have you found any solution I am facing same issue

scottsuhy commented 2 years ago

no, i'm just did the transactions direct and built my own UI to manage it.. i'm not sure cb is serious about the platform or they would have commented. i'm looking for alternatives.

alykhan2212 commented 2 years ago

For now I have found 2 issues. 1: Checkout requires extra parameter requested_info like you passed with curl. coinbase doc ref 2: Second issue is related with this package. In this makeRequest() funcion while making request author passed ['query' => $query, 'body' => json_encode($params)] and when I dump the $query array before request I found the array empty, I shuffle these variable this way ['query' => $params, 'body' => json_encode($query)] createCheckout worked fine. although I haven't tested other functions (charge, createCharge) after these changes.

jeybin commented 2 years ago

Try adding requested info parameter to the request

public function createCheckout(Request $request){
    $checkout = Coinbase::createCheckout([
        'name' => 'Name',
        'description' => 'Description',
        'requested_info' => ['name','email'],
        'local_price' => [
            'amount' => 100,
            'currency' => 'USD',
        ],
        'pricing_type' => 'fixed_price',
    ]);

    return $checkout;
}

Please refer : Coinbase-documentation

CookieMC337 commented 1 year ago

Is there a solution? I also have this error.

antimech commented 1 year ago

requested_info is optional but must be present:

$checkout = Coinbase::createCheckout([
    'name' => 'Name',
    'description' => 'Description',
    'requested_info' => [],
    'local_price' => [
        'amount' => 100,
        'currency' => 'USD',
    ],
    'pricing_type' => 'fixed_price',
]);

Also, createCheckout will be fixed soon (#20), this is the correct code:

/**
 * Creates a new checkout.
 *
 * @param  array  $params
 * @return array
 */
public function createCheckout(array $params = [])
{
    return $this->makeRequest('post', 'checkouts', [], $params);
}
antimech commented 1 year ago

Fixed in #20