Hi,
Sorry if this isn’t totally Livewire related, but I’m currently playing around with adding Stripe payments and have setup a Checkout Livewire component but I haven’t done this before and so a little confused and unsure what’s best practice. My goal is to capture user data to create an account as they pay (think WooCommerce checkout form).
What I have currently sends payments to Stripe and sets up Stripe customers
public function completeOrder()
{
$this->validate();
Stripe::setApiKey(env('STRIPE_SK'));
$customer = Customer::create();
$this->customer = $customer->id;
$paymentIntent = PaymentIntent::create([
'amount' => 2000,
'currency' => 'gbp',
'customer' => $this->customer,
'setup_future_usage' => 'off_session',
'description' => 'Laravel Playground'
]);
$this->fill([
'clientSecret' => $paymentIntent->client_secret,
'paymentIntentId' => $paymentIntent->id
]);
$this->dispatchBrowserEvent('submit-payment');
}
public function createCustomer()
{
Stripe::setApiKey(env('STRIPE_SK'));
Customer::update($this->customer, [
'name' => $this->firstName. ' ' . $this->lastName,
'email' => $this->email,
'phone' => $this->phone,
'address' => [
'country' => $this->country,
'state' => $this->county,
'city' => $this->city,
'line1' => $this->streetAddress,
'postal_code' => $this->postcode,
],
'shipping' => [
'name' => $this->firstName. ' ' . $this->lastName,
'phone' => $this->phone,
'address' => [
'country' => $this->country,
'state' => $this->county,
'city' => $this->city,
'line1' => $this->streetAddress,
'postal_code' => $this->postcode,
]
],
'description' => 'Creating a new customer!'
]);
// PaymentIntent::update($this->paymentIntentId, [
// 'customer' => $customer->id
// ]);
}
However the Stripe documentation says to create the PaymentIntent as soon as possible. I initially had the PaymentIntent in the mount method, but I wanted to set the card for future use which means you need to create Customer before the PaymentIntent (like below).
public function mount()
{
Stripe::setApiKey(env('STRIPE_SK'));
$customer = Customer::create();
$this->customer = $customer->id;
$paymentIntent = PaymentIntent::create([
'amount' => 2000,
'currency' => 'gbp',
'customer' => $this->customer,
'setup_future_usage' => 'off_session',
'description' => 'Laravel Playground'
]);
$this->fill([
'clientSecret' => $paymentIntent->client_secret,
'paymentIntentId' => $paymentIntent->id
]);
}
But doing this creates an empty customer on the Stripe dashboard and if the user clicks away there will just be an empty customer. Any advice on how to set this up would be greatly appreciated.
Again sorry if this is more of Stripe question.
Thanks