1

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

{
  "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);

你知道为什么会发生这种情况吗?

4

1 回答 1

0

您正在将帖子参数编码为 json。就这样过去吧param1=val1&param2=val2

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

参考php.net

在此处输入图像描述

于 2021-06-21T17:24:29.660 回答