@cib88 You can do it this way. Give it a try:
public function processPayment(Request $request)
{
$paymentMethod = $request->get('paymentMethod');
$email = $request->get('cardholder-email');
$paymentAmount = $request->get('amount') * 100;
try {
// Create a new Stripe customer object
$customer = (new User)->createOrGetStripeCustomer($email, $paymentMethod);
// Charge the customer
$stripeCharge = $customer->charge($paymentAmount, $paymentMethod, [
'currency' => 'GBP',
'receipt_email' => $email
]);
return redirect()->route('thankyou');
} catch (IncompletePayment $exception) {
return redirect()->route(
'cashier.payment',
[$exception->payment->id, 'redirect' => route('payment')],
);
} catch (Exception $e) {
return Redirect::back()->withErrors(['error' => $e->getMessage()]);
}
}
Keep in mind that the createOrGetStripeCustomer method will check if a customer with the provided email address already exists in Stripe, and if so, it will return the existing customer object. If no customer with the provided email address exists, it will create a new customer object. This can be useful if you want to make sure you don't create multiple customer objects for the same user.
Check more: https://laravel.com/docs/9.x/billing#creating-customers