首页 文章

使用现有卡信息和客户ID在条带中创建令牌

提问于
浏览
0

我正在使用带有php的stripe.js,我在为现有/已保存的卡创建令牌时遇到问题,而对于新卡,一切正常 . 是否有任何基于cardId和customerId生成令牌的功能

1 回答

  • 2

    从现有的Customer或Card对象创建新令牌既不必要也不可能 . 将卡存储在Customer对象后,您只需使用密钥和客户ID即可完成收费 . 来自the docs

    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    \Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token ID submitted by the form:
    $token = $_POST['stripeToken'];
    
    // Create a Customer:
    $customer = \Stripe\Customer::create(array(
      "email" => "paying.user@example.com",
      "source" => $token,
    ));
    
    // Charge the Customer instead of the card:
    $charge = \Stripe\Charge::create(array(
      "amount" => 1000,
      "currency" => "usd",
      "customer" => $customer->id
    ));
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
    $charge = \Stripe\Charge::create(array(
      "amount" => 1500, // $15.00 this time
      "currency" => "usd",
      "customer" => $customer_id
    ));
    

    如果您对如何在Stripe上实施特定付款流程有任何其他疑问,我建议您与Stripe support联系 .

相关问题