【问题标题】:Getting token to create customer using Stripe使用 Stripe 获取令牌以创建客户
【发布时间】:2018-05-30 06:27:22
【问题描述】:

我正在使用 Checkout 在我的 ASP.NET Core 应用程序中实现 Stripe。

我知道如何获取令牌以使用 Checkout 向信用卡收费,但我从哪里获取令牌以创建客户?

在文档中,我看到我需要获取令牌来创建客户,但不确定该令牌来自何处。 https://stripe.com/docs/api/dotnet#create_customer

据我所知,一个令牌只能使用一次,因此它与我在信用卡收费之前获得的令牌不可能相同。

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    正如我在这里引用的条纹document

    当您收集客户的付款信息时,会创建一个 Stripe 令牌。此令牌只能使用一次,但这并不意味着您每次付款都必须要求提供客户的银行卡详细信息。

    Stripe 提供了一个 Customer 对象,可以很容易地保存它——并且 其他——供以后使用的信息。您可以使用客户对象 创建订阅或未来的一次性费用。

    您要做的就是创建一个您在购买时获得的客户 客户的卡详细信息并向该客户收费。

    使用下面的代码 sn-p 来做,这样你就可以创建一个客户并使用单个令牌收费

    StripeConfiguration.SetApiKey(secret_key_of_your_account);
    var token = model.Token; // Using ASP.NET MVC
    
    var customers = new StripeCustomerService();
    var charges = new StripeChargeService();
    
    var customer = customers.Create(new StripeCustomerCreateOptions {
      Email = "paying.user@example.com",
      SourceToken = token
    });
    
    // 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.
    var charge = charges.Create(new StripeChargeCreateOptions {
      Amount = 1500, // $15.00 this time
      Currency = "usd",
      CustomerId = customer.Id
    });
    

    阅读参考文档了解更多详情

    【讨论】:

    • 感谢您的详细解答!
    • 继续贡献:)
    • 如果客户已经存在,或者可能存在,如果客户不存在,我们如何创建? stackoverflow.com/questions/51144576/…
    • 发布了我的答案以链接您可以检查。或者可以在这里查看stackoverflow.com/a/51147376/4049271
    • 不确定我是否需要为此创建一个新问题。反正。之后产生的费用将限于结账时最初验证的总金额。对吗?
    【解决方案2】:
      \Stripe\Stripe::setApiKey("----");
      \Stripe\Stripe::setApiKey(".................");
         $token=   \Stripe\Token::create(array(
         "card" => array(
           "number" => "4242424242424242",
           "exp_month" => 1,
           "exp_year" => 2019,
           "cvc" => "314"
         )
       ));
       $request['stripe_token'] =$token['id'];
      // When Contact person have not Stripe Customer id then we have to do the following process.
         try {
          $customer = \Stripe\Customer::create([
            "description" => "Customer for ".$contactDetails['email'],
            "source" => $request['stripe_token'] // obtained with Stripe.js
          ]);
           // update its customerid in the contact table
    
          // Create Customer then save its id in table and use the customer id when you are  verifiying the customer token
          $result=  \Stripe\Charge::create(array(
            "amount" => $request['amount'],
            "currency" => $request['currency'],
            "customer" => $customer
          ));
          $status = $result['succeeded'];
           if($result['status'] == "succeeded"){
               $success = 'Your payment was successful.';
               $all['payment_done'] = "1";
              $FinalArray = array('status'=>'true','message'=>'Your payment done successful.','result'=>$all);
           }else{
             $FinalArray = array('status'=>'fail','message'=>'Your Token is not generated successfully','result'=>[]);
           }
    
      }
         catch (Exception $e) {
           $error = $e->getMessage();
            $all['payment_done'] = "0";
            $FinalArray = array('status'=>'false','message'=>'The Stripe token id is not correctly','result'=>$all);
         }
    

    【讨论】:

      猜你喜欢
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 2023-01-18
      • 2015-01-15
      • 2021-11-09
      • 2015-12-26
      相关资源
      最近更新 更多