Creating Products and Prices in Stripe

Introduction

Products, along with their prices, are the core resource of any e-commerce website. Accepting online payments for these products via Stripe plays an important role in facilitating transactions.

By going through the following steps, we can create products and their prices in Stripe.

Step 1: Import Stripe’s required libraries

After the successful installation of Stripe in Laravel, we can create products and their pricing. Stripe provides two libraries, both of which we’ll need: Stripe\Price and Stripe\Products.

Step 2: Create products using Stripe’s Products library

In the code below:

  • Line 5: Import the Stripe library to create products.

  • Line 9: We define the createProductWithPrice() function, which is called to create the product.

  • Lines 11–15: We configure the Stripe key, and then the Product::create function is utilized to create products on the Stripe website.

Using the code snippet below, we create a product with the required description.

Get hands-on with 1400+ tech skills courses.