Creating Customers

Learn how to create Stripe customers with Laravel.

Introduction

A customer in any kind of business plays a pivotal and important role. Apart from creating transactions, Stripe also provides us with a feature to handle and create customers.

In the code snippet below, a customer is created with the help of the Stripe library, which will be linked with the Stripe dashboard.

1 <?php
2 namespace App\Http\Controllers;
3 use Illuminate\Http\Request;
4 use Stripe;
5 use Stripe\Customer;
6
7 class StripeController extends Controller
8 {
9 public function createCustomer()
10 {
11 // Set your Stripe secret key
12 Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
13
14 // Create a customer
15 $customer = Customer::create([
16 'name' => 'John Doe',
17 'email' => 'john.doe@example.com',
18 'description' => 'Customer for John Doe',
19 ]);
20
21 // We can save the customer ID in our database if needed
22 $customerID = $customer->id;
23
24 return $customer;
25 }
26 }
27 ?>
Stripe customer creation

In the code snippet above: ...