我已经添加了一个 Stripe 客户,我正在考虑向客户添加新卡。我四处搜寻,但找不到任何可以确认的内容来回答我的以下问题。
以下是添加新卡的正确方法吗?
$customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key);
// Got the customer details successfully from the above call.
$card = $customer->cards->create(
array(
"card" =>
array(
"number"=> "4242424242424242",
"exp_month" => "12",
"exp_year" => "2016",
"cvc" => "123"
)
)
);
Stripe 没有专门用于向客户添加新卡的直接表单,但是您可以使用 Checkout 或 Elements 来收集客户的卡详细信息。
向客户添加新卡的流程如下:
$token = $_POST['stripeToken']; #for example
$customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key);
$customer->sources->create(array("source" => $token));
[0] - https://stripe.com/docs/checkout 或 https://stripe.com/docs/stripe-js/elements/quickstart
@karllekko 的答案现在似乎已经过时了。我发现以下目前似乎效果很好。
$email = $_POST['email'];
$customers = \Stripe\Customer::all(['email' => $email]);
$customer = $customers->data[0];
$token = $_POST['stripeToken'];
$newCard = \Stripe\Customer::createSource($customer->id, ['source' => $token]);