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!