Selly.gg API - CURL POSTFIELDS错误

时间:2018-05-24 09:43:32

标签: php curl

我正在尝试将Selly.gg支付API与我的系统集成。

创建付款的文档位于:https://developer.selly.gg/#create-a-payment

这是我的代码:

$ch = curl_init();

    $data = array(
        "title" => "My Payment",
        "gateway" => "PayPal",
        "email" => $_GET["email"],
        "value" => $price * $_GET["stock"],
        "currency" => "USD",
        "return_url" => "http://example.com",
        "webhook_url" => "http://example.com/callback.php?paid=true"
    );
    $data_curl = json_encode($data);

    curl_setopt($ch, CURLOPT_URL, "https://selly.gg/api/v2/pay");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_curl);
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Authorization: Basic ".base64_encode('EMAIL:APIKEY');
    $headers[] = "Content-Type: application/x-www-form-urlencoded";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        //echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);

    echo $result;

但是我得到了{"message":["Currency is not one we support","Currency can't be blank","Value is not a number","Value can't be blank","Email can't be blank","Gateway is not included in the list","Gateway can't be blank","Return url can't be blank","Webhook url can't be blank","Title is too short (minimum is 2 characters)"]}

注意 :我甚至尝试直接在POSTFIELDS中设置数组,但它与JSON编码数组的结果相同。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我解决了,这是我眼睛的错。

Content-Type: application/x-www-form-urlencoded标头必须为Content-Type: application/json