x Contact us ask us for an offer
Thank you for your message. We will contact you as soon as we understand your needs!
  • Witaj Hello!
  • Masz pytania? Any questions?
  • Skontaktuj się contact us
    we can help you with your business!
Blog
  • 16
    Nov
    Author: matix November 16, 2018 17:12
    Stripe Integration in PHP – tutorial how to do e-commerce using Stripe

    Stripe is a popular payment processor. One of the reasons why is so popular is the great API so allow start-ups to grow faster and be more financial-fluent.
    
If you need more information about the Stripe service, just check out the official website at https://stripe.com.

    In this tutorial, we show you how you can integrate Stripe using PHP and Symfony framework.

    We recommend to try it in practice (code!) so you can get some Stripe skills immediately!

    Approach:
    - Use Stripe as much as we can, so we use the Stripe’s backend and its database with metadata,
    - Create 2 categories (vegetables, fruits) and 4 products (cucumber, apple, lettuce, leek),
    - Create 1 product service (Catering) so a user can order the catering service and will be charged automatically once a month,

    We will skip the process of registration in Stripe as you can do it yourself – it’s simple!



    Define products in Stripe


    As already mentioned, we need to create 4 products and 1 service.
    Let’s start to investigate, how products can be defined in Stripe backend.

    After you log-in to your Stripe account, you can start defining your products.
    Simply navigate to Orders -> Products and press the "New" button.

    Add new product in Stripe

    I've created 1 fruit and 3 vegetables.
    This is how it should look like after you're done.

    List of products in Stripe



    We also need to store more data for a product, such as category and price, so we can purchase a product. For each product add a metadata key called: "category" and SKU.
    Below a sample product with "category" as Metadata and SKU added:

    Sample product in Stripe with Metadata

    And the list of all the products with SKUs added:

    Stripe list of products with SKU

    Subscriptions in Stripe


    Now, it's time to add a service so we can order a catering. Stripe will automatically charge a customer in a specified period of time. For testing purposes, I'll create a catering service, billed monthly.
    It's pretty straightforward and very similar to creating standard products. Go to Billing -> Products and press the "New" button. Let's call it Catering and then click "Create product".

    Subscriptions in Stripe




    Then we need to create a plan (possible to add more than one, but for testing purposes, we'll create only one) so a customer can subscribe to a plan.
    Notice the ID field = "catering".
    This is the plan identifier as we'll refer to it when subscribing a customer.

    Plan in Stripe


    If you are interested how to integrate Symfony with Stripe Api, check our next article at: https://www.wiseweb.pl/blog-stripe-integration-in-php-tutorial-how-to-do-e-commerce-using-stripe/.