我正在使用Stripe作为我设计的网站的支付网关。我已经能够创建并向客户收费,但我还希望将客户ID存储在我的数据库中。我如何检索客户ID?这是我的代码片段:
...
// Create a Customer
$customer = \Stripe\Customer::create(array(
'email' => $email,
'card' => $token,
//'address_line1' = $addr1 . " ". $addr2 . " ". $city . " " . " " .$country ,
//'address_zip' = $postcode,
'description' =>'Partnership' . " " . $fname . " " . $lname
));
// Charge the Customer instead of the card
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'gbp',
"metadata" => array("order_id" => "6735")
));
//retrieve customer id
$customerId = \Stripe\Charge::retrieve($charge['customer']);
这是我收到的错误消息:
Notice: Undefined variable: charge
Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Could not determine which URL to request: Stripe\Charge instance has invalid ID: ' in ....
1. enter code here
答案 0 :(得分:0)
将客户对象分配给$customer
变量后,您可以通过$customer->id
访问其ID。这就是您在费用创建请求中传递客户ID的原因。
您应该这样做以在数据库中保存ID。