Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jim1506's avatar

Stripe and Cashier Help

I am getting somewhat confused by Cashier and Stripe and a lot out there seems to be contradictory and older.

I am using a table Customer so I have set the .env accordingly. The initial form for customer just gets their name, email, country and password and then goes to a controller method:

$cu = new Customer;

        $cu->name = $request->name;
        $cu->email = $request->email;
        $cu->country = $request->country;
        $cu->plan_id = 3;
        $cu->password = Hash::make($request->password);
        $cu->save();

        $cu->createAsStripeCustomer();


        //make the ID a session variable
        session(['customer' => $cu->id]);

        return redirect()->route('formStarterPayment',['id' => $cu->id, 'intent' => $cu->createSetupIntent()]);

The Stripe ID is recorded in the database.

Next is the payment page. I have a table of plans so I get the information at the start of the view and pass in the cost and the customer's email:

<form action="/subscriptionPayment" method="POST">
  @csrf
  <script
          src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="{{ env('STRIPE_KEY') }}"
          data-amount="{{ $amount }}"
          data-name="{{ $pl->name }}"
          data-email="{{ $fs->email }}"
          data-currency="gbp">
        </script>
</form>

This is where confusion starts as I am trying to set up a subscription.

if I dd($request) I get

"stripeToken" => "tok_1FybOgF7aDMrgjaugPzXdejn"
      "stripeTokenType" => "card"
      "stripeEmail" =>appropriate email

so my function is

    $tokenType = $request->stripeTokenType;
    $email = $request->stripeEmail;

    $stripeToken = $request->stripeToken;

    $cu = Cust::find( session('customer') );
    $pl = Plan::find(3);

    $cu->createOrGetStripeCustomer();

    $amount = $pl->cost *100;

    $cu->stripeToken = $stripeToken;
    $cu->save();

    $paymentMethod = $cu->paymentMethods();
    $intent = $cu->createSetupIntent();

    $cu->newSubscription($pl->name, $pl->test_stripe_plan)
        ->trialDays($pl->freePeriod)
        ->create($stripeToken,
          ['email' => $email]);

This fails with an error message that there is no such payment method and then the token is given.

I am using Laravel 5.8 with the latest Cashier and obviously I have checked what is the database and it is fine.

I will be grateful for any help!

0 likes
5 replies
bugsysha's avatar

Yeah, it looks that you've got things bit backwards. You do not need to call createSetupIntent again and you are passing stripe token instead of payment method.

If you did everything correctly you should get the response from stripe which contains setupIntenet and has payment_method which you then pass to create method when creating newSubscription. In your place I would delete all logic that you have in your "function" and start from scratch.

jim1506's avatar

Thanks. I am still a bit confused. So I get the customer info and save it and then use

$cu->createAsStripeCustomer();

and then pass details to the card form

return redirect()->route('formStarterPayment',['id' => $cu->id, 'intent' => $cu->createSetupIntent()]);

but the form is sending back as dd()

Illuminate\Http\Request {#43 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure($guard = null) {#470 ▶}
  #routeResolver: Closure() {#472 ▶}
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#45 ▶}
  +request: Symfony\Component\HttpFoundation\ParameterBag {#44 ▼
    #parameters: array:4 [▼
      "_token" => "po0h3Y99nYZ0Qy9rK9TaNrdTB365cRKyEHzPXLHQ"
      "stripeToken" => "tok_1Fyf16F7aDMrgjaucGFx296w"
      "stripeTokenType" => "card"
      "stripeEmail" => "[email protected]"
    ]
  }
  +query: Symfony\Component\HttpFoundation\ParameterBag {#51 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#47 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#48 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#46 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#49 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/subscriptionPayment"
  #requestUri: "/subscriptionPayment"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Illuminate\Session\Store {#504 ▶}
  #locale: null
  #defaultLocale: "en"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"

Not quite certain where I am to get the setupIntent and payment_method

bugsysha's avatar

The form snippet you've posted is not mentioned in the documentation. Maybe that is the key. Replace checkout.js with v3.

jim1506's avatar

Thanks. I will retry it and let you know. The version of the .js was from a tutorial!

bugsysha's avatar

Probably some old tutorial. Just follow the docs and it should work.

Please or to participate in this conversation.