【问题标题】:Stripe Add Usage with PHP CURL使用 PHP CURL 进行条纹添加用法
【发布时间】:2021-06-21 17:01:33
【问题描述】:

您好,我正在向客户添加用法,但出现以下错误:

{
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameter: {\"quantity\":1,\"timestamp\":1624294464}",
    "param": "{\"quantity\":1,\"timestamp\":1624294464}",
    "type": "invalid_request_error"
  }
}

这很奇怪,因为quantity && timestamp 是请求中的必需参数。

这是我现在的代码。

注意:我正在使用 laravel,但我不想使用 php 库。

$url = 'https://api.stripe.com/v1/subscription_items/'.$subscriptionItemObj->stripe_id.'/usage_records';
$fields = ["quantity"=>1, "timestamp" => $dt->getTimestamp()];
$fieldsEncoded = json_encode($fields);
$headers  = [ 'Authorization: Bearer '.env('STRIPE_SECRET') ];

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsEncoded);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$output = curl_exec($ch);
curl_close($ch);

你知道为什么会这样吗?

【问题讨论】:

    标签: php api curl strip


    【解决方案1】:

    您正在将帖子参数编码为 json。像param1=val1&param2=val2一样传递它

     $fields = 'quantity=1&timestamp='.$dt->getTimestamp();
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    

    参考php.net

    【讨论】:

      猜你喜欢
      • 2017-03-15
      • 1970-01-01
      • 2017-11-26
      • 2012-03-23
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2017-06-02
      相关资源
      最近更新 更多