在Stripe中,哪里可以获取SourceToken来创建客户?

时间:2019-03-29 20:18:18

标签: asp.net token stripe-payments payment customer

在哪里可以从Stripe中获得用于创建客户的SourceToken?

以下是使用SourceToken的代码示例:

if (Request.Form["stripeToken"] != null) {
    var customers = new CustomerService();
    var charges = new ChargeService();

    var customer = customers.Create(new CustomerCreateOptions {
        Email = Request.Form["stripeEmail"],
        SourceToken = Request.Form["stripeToken"]
    });

    var charge = charges.Create(new ChargeCreateOptions {
        Amount = 500,
        Description = "Sample Charge",
        Currency = "usd",
        CustomerId = customer.Id
    });

    Console.WriteLine(charge);
}

SourceToken中的json是什么?

{
  "id": "tok_1EL43MKfPgrABB02rh7IGG7l",
  "object": "token",
  "card": {
    "id": "card_1EL43MKfPgrABB02yFgReMXc",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Visa",
    "country": "US",
    "cvc_check": "pass",
    "dynamic_last4": null,
    "exp_month": 12,
    "exp_year": 2020,
    "funding": "credit",
    "last4": "4242",
    "metadata": {},
    "name": "foo@gmail.com",
    "tokenization_method": null
  },
  "client_ip": "194.44.142.6",
  "created": 1554278556,
  "email": "foo@gmail.com",
  "livemode": false,
  "type": "card",
  "used": false
}

这是我得到json的方式:

var stripe = Stripe('pk_test_ob6s7KZxZU1mouJbbsuFBjEe');

var handler = StripeCheckout.configure({
    key: 'pk_test_ob6s7KZxZU1mouJbbsuFBjEe',
    token: function(token, args) {
        var stop = 0;
    }
  });

  document.getElementById('myBtn').addEventListener('click', function(e) {
    // Open Checkout with further options
    handler.open({
      name: 'Demo Site',
      description: '2 widgets ($20.00)',
      amount: 2000
    });
    e.preventDefault();
  });

var stop = 0;行。

该示例摘自here

谢谢。

1 个答案:

答案 0 :(得分:0)

该JSON中的SourceToken为"tok_1EL43MKfPgrABB02rh7IGG7l"

在创建带有附加源(例如令牌)的客户之后,您可以retrieve the customer将包括该客户的源(它们将在{{1}下的sources对象中列出}}记录。

令牌本身在创建源和客户期间被消耗,结果是可重用的源。