"EXPECTED_INTEGER","detail":"Expected an integer value.","field":"amount_money.amount"
"EXPECTED_INTEGER","detail":"Expected an integer value.","field":"amount_money.amount"
我已经阅读了这个 post 并确认我发送的是一个整数 100
但由于某种原因我一直收到错误消息
我收到了来自 POST
赞
的收费金额
$charge_amount = $_POST['charge_amount'];
然后在我的 API 中,我将其发送为
$request_body = array (
"customer_id" => $customer->getId(),
"customer_card_id" => $card->getId(),
"amount_money" => array (
"amount" => $charge_amount,
"currency" => 'USD'
),
"idempotency_key" => uniqid(),
);
但这没有用。所以我决定像这样静态更改值
$request_body = array (
"customer_id" => $customer->getId(),
"customer_card_id" => $card->getId(),
"amount_money" => array (
"amount" => 100,
"currency" => 'USD'
),
"idempotency_key" => uniqid(),
);
这奏效了。
为什么 POST
不起作用?我确认 100
的值是通过 post 和 echo $charge_amount
传入的。我什至尝试更改为 "amount" => "$charge_amount",
,但效果不佳。
最后我得到的错误是
[HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"EXPECTED_INTEGER","detail":"Expected an integer value.","field":"amount_money.amount"}]}
$_POST['charge_amount']
将成为 字符串 "100"
.
通过 $charge_amount = (int)$_POST['charge_amount'];
或 $charge_amount = intval($_POST['charge_amount']);
转换为整数(在本例中,这两个是 functionally identical)
您可以使用 var_dump, if it isn't INT, cast it as such by either type juggling:
检查相关变量的数据类型
$my_string = (int) '100';
或使用函数intval
$my_string = intval('100');
我已经阅读了这个 post 并确认我发送的是一个整数 100
但由于某种原因我一直收到错误消息
我收到了来自 POST
赞
$charge_amount = $_POST['charge_amount'];
然后在我的 API 中,我将其发送为
$request_body = array (
"customer_id" => $customer->getId(),
"customer_card_id" => $card->getId(),
"amount_money" => array (
"amount" => $charge_amount,
"currency" => 'USD'
),
"idempotency_key" => uniqid(),
);
但这没有用。所以我决定像这样静态更改值
$request_body = array (
"customer_id" => $customer->getId(),
"customer_card_id" => $card->getId(),
"amount_money" => array (
"amount" => 100,
"currency" => 'USD'
),
"idempotency_key" => uniqid(),
);
这奏效了。
为什么 POST
不起作用?我确认 100
的值是通过 post 和 echo $charge_amount
传入的。我什至尝试更改为 "amount" => "$charge_amount",
,但效果不佳。
最后我得到的错误是
[HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"EXPECTED_INTEGER","detail":"Expected an integer value.","field":"amount_money.amount"}]}
$_POST['charge_amount']
将成为 字符串 "100"
.
通过 $charge_amount = (int)$_POST['charge_amount'];
或 $charge_amount = intval($_POST['charge_amount']);
转换为整数(在本例中,这两个是 functionally identical)
您可以使用 var_dump, if it isn't INT, cast it as such by either type juggling:
检查相关变量的数据类型$my_string = (int) '100';
或使用函数intval
$my_string = intval('100');