首页 文章

我可以添加卡片详细信息而无需向Stripe客户收费吗?

提问于
浏览
-1

我需要我的客户添加他们的信用卡信息,但我不想立即收取费用 . 有没有办法,我可以在使用Stripes checkout 解决方案时添加他们的详细信息以便稍后收费并只存储他们的卡片令牌?

我在后端使用Laravel Cashier .

2 回答

  • 0

    与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
    ]);
    

    希望这可以帮助 .

  • 0
    // 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']]);
    

相关问题