【发布时间】:2019-09-05 22:00:57
【问题描述】:
我无法让 Stripe API 更新客户电子邮件。当用户登录时,会有一个表单来更新他们的电子邮件地址。电子邮件地址在我的数据库表中更新,但我无法让 Stripe API 更新客户。
这是我正在使用的代码:
if (isset($customerid)) {
try {
$cu = \Stripe\Customer::update(
$customer_id,
[
'email' => $_SESSION['email'],
]
);
$output = "<p>Success!</p>";
} catch (\Stripe\Error\Card $e) {
// Use the variable $error to save any errors
// To be displayed to the customer later in the page
$body = $e->getJsonBody();
$err = $body['error'];
$error = $err['message'];
$output = "Error: $error";
}
// Add additional error handling here as needed
}
$customerid 来自我的数据库,错误例程是从我的卡更新代码中粘贴的。
这是来自日志的请求 POST 正文:
{
"email": {
"0": "myemail@mydomain.com"
}
}
脚本运行时出现致命错误:
Fatal error: Uncaught Stripe\Error\InvalidRequest: Invalid string: {:"0"=>"myemail@mydomain.com"}
以及日志中的以下内容:
{
"error": {
"message": "Invalid string: {:"0"=>"myemail@mydomain.com"}",
"param": "email",
"type": "invalid_request_error"
}
}
有什么想法或建议吗?
这是每个 Marcin 的 php 代码应该是什么样子的吗?显然我是个菜鸟。
if (isset($customerid)) {
try {
$cu = \Stripe\Customer::update(
$customer_id,
[
"email": "myemail@mydomain.com",
]
);
$output = "<p>Success!</p>";
} catch (\Stripe\Error\Card $e) {
// Use the variable $error to save any errors
// To be displayed to the customer later in the page
$body = $e->getJsonBody();
$err = $body['error'];
$error = $err['message'];
$output = "Error: $error";
}
// Add additional error handling here as needed
}
我最初的做法是从 API 参考,我试图模仿他们的例子:
\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxx");
\Stripe\Customer::update(
'cus_ElRYM0KexefrGt',
[
'metadata' => ['order_id' => '6735'],
]
);
【问题讨论】:
标签: php stripe-payments