Site Admin
Site Admin Founder of MeaningArticles

PHP Stripe Payment Gateway integration example

Hello Dev.

in this article, you'll learn how to integrate stripe payment gateway in core php. This article additionally provides you complete source code of stripe payment gateway integration in php with example.

This educational has the cause to reveal you a simple and easy way to integrate stripe payment gateway with example.

Follow the below steps and simply integrate stripe or card payment gateway in PHP:

Step 1: Create Stripe Account Get Secret Key

to start with, we want to secret publisher key and secret key from the stripe. so we want to log in or sign in from the stripe after which we got the secret publisher and secret key from the stripe.

If you don’t have secret publisher key. So, first of all, you need to REGISTER and get secret publisher key and secret key.

If you have already registered with stripe, so click this link and login on stripe and get the secret publisher key and the secret key LOGIN.

Get secret publisher and key on stripe dashboard looks like:

Step 2: Install Stripe Package

In the second step, we need to install or download a stripe PHP package in our project. So go to command prompt follow the below commands:


Than Run the below command to install or download the stripe package for PHP.

composer require stripe/stripe-php

Step 3: Create Display Product file

Next step, we need to create one view file name index.php, Where we show the products.

After that you need to update the below code into your index.php file.

<!DOCTYPE html>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>PHP Stripe Payment Gateway Integration -</title>
        <link rel="stylesheet" href="" />
        <script src=""></script>
            padding: 0.5%;
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <pre id="token_response"></pre>
            <div class="row">
                <div class="col-md-4">
                    <button class="btn btn-primary btn-block" onclick="pay(100)">Pay $100</button>
                <div class="col-md-4">
                    <button class="btn btn-success btn-block" onclick="pay(500)">Pay $500</button>
                <div class="col-md-4">
                    <button class="btn btn-info btn-block" onclick="pay(1000)">Pay $10000</button>
        <script src=""></script>
        <script src=""></script>
        <script src=""></script>
        <script type = "text/javascript" >
            function pay(amount) {
                var handler = StripeCheckout.configure({
                    key: 'pk_test_5f6jfFP2ZV5U9TXQYG0vtqFJ00eFVWNoRX', // your publisher key id
                    locale: 'auto',
                    token: function (token) {
                        // You can access the token ID with ``.
                        // Get the token ID to your server-side code for use.
                        console.log('Token Created!!');
                            url: "payment.php",
                            method: 'post',
                            data: {
                                amount: amount
                            dataType: "json",
                            success: function (response) {
                                $('#token_response').append('<br />' + JSON.stringify(;
                    name: 'Stripe Payment Gateway Integration -',
                    description: '2 widgets',
                    amount: amount * 100

Step 4: Create Payment Process file

Final step, in this step we need to create a new PHP file name payment.php. In this file we will use the stripe package and do further payment process in this file.

Now, you need to update the below code into your file.

if ($_POST['tokenId'])
    require_once ('vendor/autoload.php');
    //stripe secret key or revoke key
    $stripeSecret = 'sk_test_j5k0976GOLSOtiRzbDLpKqat00og5iM3cY';
    // See your keys here:
    // Get the payment token ID submitted by the form:
    $token = $_POST['tokenId'];
    // Charge the user's card:
    $charge = \Stripe\Charge::create(array(
        "amount" => $_POST['amount'],
        "currency" => "usd",
        "description" => "stripe integration in PHP with source code -",
        "source" => $token,
    // after successfull payment, you can store payment related information into your database
    $data = array(
        'success' => true,
        'data' => $charge
    echo json_encode($data);

i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.