Php 条带:向已创建的客户添加新卡

Php 条带:向已创建的客户添加新卡,php,laravel,stripe-payments,stripe.js,Php,Laravel,Stripe Payments,Stripe.js,我已经添加了一个stripe客户,我正在考虑向客户添加新卡。我四处搜索,但没有找到任何符合我以下问题的答案 有没有自己的任何形式的新卡添加 以下是添加新卡的正确方法吗 $customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key); // Got the customer details successfully from the above call. $card = $customer->cards->c

我已经添加了一个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或元素来收集客户的卡详细信息

    向客户添加新卡的过程如下:

  • 使用签出或元素[0]收集并标记客户的卡详细信息。这将为您提供一个代表该卡的条纹令牌
  • 将此令牌发送到后端,您可以在后端使用类似于以下代码的代码将卡保存给客户:
  • [0]-或


    [1] -

    您需要先创建客户,然后检索该客户。然后
    $customer->sources->create(数组(“source”=>“tok_万事达卡”)看一看@SafoorSafdar请定义
    (数组(“source”=>“tok_mastercard”)
    你评论的一部分,那就是我被卡住的部分。
    $token = $_POST['stripeToken']; #for example
    $customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key);
    $customer->sources->create(array("source" => $token));