【问题标题】:Laravel & Stripe - Unrecognized request URL (GET: /v1/customers/)Laravel & Stripe - 无法识别的请求 URL (GET: /v1/customers/)
【发布时间】:2020-09-30 08:14:30
【问题描述】:

我在尝试使用 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/.

令牌响应

{"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}

代码

$request->user()
->newSubscription($plan->name, $plan->stripe_plan)
->create($request->stripeToken); //error here

【问题讨论】:

  • Stripe 的端点永远不会以/ 结尾。从外观上看,您提供的代码不是此错误的来源。更有可能的是,您在尝试检索客户时传递了一个空白 id,或者当您想要获取 /v1/customers 时尝试获取 /v1/customers/(请注意缺少尾部斜杠)。
  • 但它指向那行代码
  • 请提供$request->user()的底层定义。

标签: php laravel stripe-payments laravel-cashier


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    这是因为您需要先创建一个条带客户,然后才能为他们创建新订阅。尝试在当前代码之前添加以下内容:

    $user = $request->user();
    $user->createOrGetStripeCustomer();
    
    $user->newSubscription($plan->name, $plan->stripe_plan)
           ->create($request->stripeToken);
    

    【讨论】:

    • $user->createOrGetStripeCustomer() 上仍有错误消息;
    • 同上
    猜你喜欢
    • 2021-03-04
    • 2014-06-08
    • 2016-04-06
    • 2013-02-19
    • 2021-11-16
    • 1970-01-01
    • 2019-03-18
    • 2014-01-09
    • 2021-07-02
    相关资源
    最近更新 更多