【问题标题】:Can I just add Card Details without charging the customer with Stripe?我可以只添加卡片详细信息而不向客户收取 Stripe 费用吗?
【发布时间】:2018-03-12 17:12:27
【问题描述】:

我需要我的客户添加他们的信用卡信息,但我不想立即向他们收费。有什么办法,我可以在使用 Stripes checkout 解决方案时添加他们的详细信息以便稍后收费,然后先存储他们的卡令牌?

我在后端使用 Laravel Cashier。

【问题讨论】:

    标签: laravel stripe-payments laravel-cashier


    【解决方案1】:

    对于 Laravel 收银员,真的很难做到这一点。你必须稍微调整一下..

    但使用 Stripe,您可以创建客户并稍后向他们收取信息。

    \Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Create a Customer:
    $customer = \Stripe\Customer::create([
        'source' => 'tok_mastercard',
        'email' => 'paying.user@example.com',
    ]);
    
    // Charge the Customer instead of the card:
    $charge = \Stripe\Charge::create([
        'amount' => 1000,
        'currency' => 'usd',
        'customer' => $customer->id,
    ]);
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // When it's time to charge the customer again, retrieve the customer ID.
    $charge = \Stripe\Charge::create([
        'amount' => 1500, // $15.00 this time
        'currency' => 'usd',
        'customer' => $customer_id, // Previously stored, then retrieved
    ]);
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:
      // Set Stripe API key
      \Stripe\Stripe::setApiKey("sk_test_HGJJKJLJLKHKJHGJHGKH");
      
      // Retrieve Customer
      $customer = \Stripe\Customer::retrieve("cus_KJHKJHJKJKHKJHKJ");
      
      // Create new card
      $data = [
          "type"        => "card",
          "card"        => [
              "exp_month" => "01",
              "exp_year"  => "20",
              "number"    => "4242424242424242",
              "cvc"       => "123",
          ],
      ];
      $card = \Stripe\Source::create($data);
      
      // Assign the created card to the customer
      $customer->sources->create(["source" => $card['id']]);
      

      【讨论】:

        【解决方案3】:

        输入卡详细信息

         $token=Token::create(['card'=>
           [
                'number'=>'4242 4242 4242 4242',
                'exp_month'=>12,
                'exp_year'=>2022,
                'cvc'=>121
           
            ],
          )];
        **//Set Stripe API key**
        $stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
        
                   $stripe=$stripe->customers->createSource(
                    $customer->id,
                    ['source' => $token->id
                ]);
        

        参考 https://stripe.com/docs/api/tokens/create_card

        【讨论】:

        • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
        猜你喜欢
        • 1970-01-01
        • 2020-03-28
        • 2016-08-08
        • 1970-01-01
        • 2014-09-26
        • 2017-02-08
        • 2018-05-21
        • 2018-06-18
        • 1970-01-01
        相关资源
        最近更新 更多