Laravel & Stripe - 无法识别的请求 URL (GET: /v1/customers/)

Moh*_*din 3 php laravel stripe-payments laravel-cashier

尝试使用 Laravel Cashier 添加新订阅时收到此错误消息。

Unrecognized request URL (GET: /v1/customers/). If you are trying to list objects, remove the trailing slash. If you are trying to retrieve an object, make sure you passed a valid (non-empty) identifier in your code. Please see https://stripe.com/docs or we can help at https://support.stripe.com/.
Run Code Online (Sandbox Code Playgroud)

令牌响应

{"id":"tok_1GsaDFLKmUMWfYhkwUv2t8Gh","object":"token","card":{"id":"card_1GsaDFLKmUMWfYhkwCiyh7ir","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":"44444","address_zip_check":"unchecked","brand":"Visa","country":"US","cvc_check":"unchecked","dynamic_last4":null,"exp_month":4,"exp_year":2044,"funding":"credit","last4":"4242","metadata":{},"name":null,"tokenization_method":null},"client_ip":"128.101.156.106","created":1591819673,"livemode":false,"type":"card","used":false}
Run Code Online (Sandbox Code Playgroud)

代码

$request->user()
->newSubscription($plan->name, $plan->stripe_plan)
->create($request->stripeToken); //error here
Run Code Online (Sandbox Code Playgroud)

Sel*_*Sel 10

stripe_id您的users表中的列不是时会发生这种情况NULL。检查该字段是否不是空字符串(即它必须是NULL)。


Ale*_*ris 0

This is because you need to create a customer in stripe before you can create a new subscription for them. Try adding the following before your current code:

$user = $request->user();
$user->createOrGetStripeCustomer();

$user->newSubscription($plan->name, $plan->stripe_plan)
       ->create($request->stripeToken);
Run Code Online (Sandbox Code Playgroud)