Php 搜索客户以更新卡详细信息

Php 搜索客户以更新卡详细信息,php,stripe-payments,Php,Stripe Payments,我正在尝试做一个页面,允许更新卡的客户。 要更新卡片详细信息,我以stripe文档为例,仅此而已: if (isset($_POST['stripeToken'])){ $customer = \Stripe\Customer::all(["limit" => 100, "email" => $mail]); $customerid = intval($customer->id); try { $cu = \Stripe\Customer::upda

我正在尝试做一个页面,允许更新卡的客户。 要更新卡片详细信息,我以stripe文档为例,仅此而已:

if (isset($_POST['stripeToken'])){
    $customer = \Stripe\Customer::all(["limit" => 100, "email" => $mail]);
    $customerid = intval($customer->id);
  try {
    $cu = \Stripe\Customer::update(
      $customerid,
      [
        'source' => $_POST['stripeToken'],
      ]
    );
    echo "Your card details have been updated!";
  }
  catch(\Stripe\Exception\CardException $e) {

    $body = $e->getJsonBody();
    $err  = $body['error'];
    $error = $err['message'];
  }
}

?>
<html>
<head>
</head>
<body>
<form action="updatecard.php" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="<?php echo $params['public_test_key']; ?>"
    data-image="img/logo-b.jpeg"
    data-name="Your Website Name  f"
    data-panel-label="Update Card Details"
    data-label="Update Card Details"
    data-allow-remember-me=false
    data-locale="auto">
  </script>
</form>
</body>
</html>
关于这一点,我有两个问题:

第一:如何将邮件从条带表单传递到POST方法


第二个:我用电子邮件搜索客户哪里错了?

您调用的API方法是列出客户。这不会返回一个客户,而是一个客户列表,其中包含0、1或多个客户。这意味着对象本身是条带列表,元素位于数据数组中

您需要更改这行代码:

$customerid = intval($customer->id);
相反,您希望检查是否有任何结果,然后访问第一个客户的id(如果有):

$customers = \Stripe\Customer::all(["limit" => 100, "email" => $mail]);
if(count($customers->data == 0 )
{
    // handle cases where there are no match
}
else
{
    $customerid = $customers->data[0]->id;
    // then update
}
$customers = \Stripe\Customer::all(["limit" => 100, "email" => $mail]);
if(count($customers->data == 0 )
{
    // handle cases where there are no match
}
else
{
    $customerid = $customers->data[0]->id;
    // then update
}