5

I got this error message when trying to add a new subscription using 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/.

Token response

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

Code

$request->user()
->newSubscription($plan->name, $plan->stripe_plan)
->create($request->stripeToken); //error here
Nurdin
  • 23,382
  • 43
  • 130
  • 308
  • Stripe's endpoints never end with a `/`. By the look of it, the code you've provided isn't where this error is coming from. More likely, you're either passing a blank id when trying to retrieve a Customer, or you're otherwise trying to GET `/v1/customers/` when you want to GET `/v1/customers` (note the lack of a trailing slash). – taintedzodiac Jun 10 '20 at 19:45
  • but its point to that line of code – Nurdin Jun 11 '20 at 02:12
  • Please provide the underlying definition of `$request->user()`. – taintedzodiac Jun 12 '20 at 18:56

2 Answers2

11

This happens when the stripe_id column in your users table is not NULL. Check that the field is not an empty string (i.e. it must be NULL).

Sel
  • 342
  • 1
  • 12
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);
Alex Harris
  • 6,172
  • 2
  • 32
  • 57