Laravel 收银员 - $stripeToken 从何而来?

Laravel Cashier - where does $stripeToken come from?

Laravel 收银台上的 documentation 非常模糊,遗漏了一些非常重要的细节,例如 $stripeToken 是什么以及它来自哪里?

所以要创建一个新的订阅,我们这样做:

$user->newSubscription('main', 'premium')->create($stripeToken);

这是用户第一次订阅,那么 $stripeToken 究竟来自哪里?

在文档中说:

The create method, which accepts a Stripe credit card / source token, will begin the subscription as well as update your database with the customer ID and other relevant billing information.

这是否意味着我必须先在 Stripe 中手动创建客户对象,然后将客户 ID 作为 $stripeToken 传递?它提到了卡的详细信息,但我如何传递它们? return 的格式是什么?

如果 $stripeToken 是 Stripe 中的客户 ID,那么 Cashier 会假设我们已经在 Stripe 中创建了客户,而我们不会第一次创建这些客户。

有人能解释一下吗?

您可以使用Stripe JS to get the stripeToken but if you are using the custom form then you can use Stripe checkout方法。

使用这两种方式,您将在 javascript 中获得 stripeToken,然后您必须将此令牌传递给您的 REST API 以进行进一步处理。

原来stripeToken一般是stripe.js表单提交时生成的

因为我使用的是 API 驱动的结帐表单而不是标准的 html 提交表单,所以我需要使用 Stripe API 根据提供的卡详细信息创建令牌。

$stripeToken = Token::create(array(
                       "card" => array(
                           "number"    => $request->get('number'),
                           "exp_month" => str_before($request->get('expiry'), '/'),
                           "exp_year"  => str_after($request->get('expiry'), '/'),
                           "cvc"       => $request->get('cvc'),
                           "name"      => $request->get('name')
                       )
                   ));

然后我用$stripeToken->id传过去:

$user->newSubscription('main', 'premium')->create($stripeToken->id);