如何在创建客户后从条带对象中检索条带客户 ID

How to retrieve the stripe customer id from the stripe object after creation of the customer

<?php
require_once('Stripe/lib/Stripe.php');
Stripe::setApiKey(trim($pkey));

try
{
  $customer = Stripe_Customer::create(array(
    'email' => $_POST['stripeEmail'],
    'source'  => $_POST['stripeToken'],
    'plan' => trim($plan)
  ));

}
catch(Exception $e)
{
  //header('Location:oops.html');
  error_log("unable to sign up customer:" . $_POST['stripeEmail'].
    ", error:" . $e->getMessage());
}
?>

这里我想获取客户 ID,所以我打印了 $customer 对象,它提供了条带对象,但我不知道如何从该结果中检索客户 ID。 如果有人知道请帮助我。 提前致谢

只需使用以下代码行即可获取客户 ID。

 $customer = $stripe->customers()->create([
       'email' => $_POST['stripeEmail'],
       'source'  => $_POST['stripeToken'],
       'plan' => trim($plan)
    ]);

echo $customer['id'];

这对你有帮助。

您可以使用客户对象来获取 id

$customer = Stripe_Customer::create(array(
    'email' => $_POST['stripeEmail'],
    'source'  => $_POST['stripeToken'],
    'plan' => trim($plan)
));

echo $customer->id;