coinbase / coinbase-commerce-php

Coinbase Commerce PHP
MIT License
136 stars 156 forks source link

Required parameter missing: pricing_type #32

Closed mayanxoni closed 3 years ago

mayanxoni commented 4 years ago

I'm trying to create a new charge using cURL from the following PHP code:

public function btc_create_charge() {
    $post = [
        'name' => 'user1',
        'description' => 'passuser1',
        'local_price' => [
            'amount' => '100.00',
            'currency' => 'USD'
        ],
        'pricing_type' => 'fixed_price'
    ];
    // echo "<pre>"; print_r(json_encode($post)); die;
    $ch = curl_init();

    curl_setopt_array(
        $ch, array(
        CURLOPT_URL => "https://api.commerce.coinbase.com/charges",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => json_encode($post),
        CURLOPT_HTTPHEADER => array(
            "X-CC-Api-Key: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
            "X-CC-Version: 2018-03-22"
        ),
    ));
    $server_output = curl_exec($ch);
    curl_close ($ch);
    $res=json_decode($server_output, true);
    echo '<pre>'; print_r($res); die;
}

Expected output:

JSON Response

I'm getting the following output:

Array
(
    [error] => Array
        (
            [type] => invalid_request
            [message] => Required parameter missing: pricing_type
        )

)

NOTE: I'm able to perform other operations using my API key, so I presume there's no problem with that.

renatofrota commented 4 years ago

Please note:

  1. you have posted this issue in coinbase-commerce-php repository but you're not using it.

  2. You're using the regular API directly and not passing Content-Type as required. Check it here: https://commerce.coinbase.com/docs/api/#create-a-charge

mayanxoni commented 4 years ago

@renatofrota I'm using the Coinbase Commerce API along with PHP, that's why I posted it here. I also tried it by passing Content-Type in the headers, but still no luck.

P.S.: I couldn't actually figure out about where to post this issue.

babacarcissedia commented 3 years ago

@renatofrota try the support page directly on coinbase maybe.

mayanxoni commented 3 years ago

@renatofrota try the support page directly on coinbase maybe.

I had scraped (not literally) all of their support pages, but couldn't find any help. That's why I created this issue. I think I should close this issue, as I'm no longer working on the project.