Integrate Stripe API using php

Integrate Stripe API using php

Integrate Stripe API using php

If you need to integrate the Stripe API into your PHP project, then follow this tutorial, which can create/edit/update/delete charges, customers, subscriptions, plans, payments, cards, and many more. Just simply follow this step, and you can get your API working.

Step 1)

NOTE* : For this API integration, you need to enable the below modules in your Apache or live server.

  • curl, although you can use your own non-cURL client if you prefer
  • json
  • mbstring (Multibyte String)

Download the library from the official Stripe website and upload this Stripe demo library to your project.

Step 2)

Now make one test.php file to create a customer in Stripe using the API in PHP and include the below code in that file and save the file.

require_once('strip-demo/vendor/autoload.php');
$stripe = new \Stripe\StripeClient(<ENTER STRIPE KEY HERE>);
$customer = $stripe->customers->create('description' => '<CUSTOMER DESCRIPTION>','email' => "<CUSTOMER EMAIL ADDRESS>",'name' => "<CUSTOMER NAME>",
]);
$id=$customer->id;
print_r($customer); //get response from stripe when customer created in stripe
            
    $stripe = new \Stripe\StripeClient(<ENTER STRIPE KEY HERE>);
    $option = array("object" => 'card', "number" => "<CUSTOMER CARD NUMBER>","exp_month" => "CUSTOMER CARD MONTH","exp_year" => "<CUSTOMER CARD YEAR>","cvc" => "<CUSTOMER CARD CVV>");
    $card = $stripe->customers->createSource(
        $id,['source' => $option]);
        print_r($card_id); //get response from stripe when card created in stripe for specific user

    $data = $stripe->charges->create([
               'amount' => "1.00",
               'customer' => $id,
               'currency' => 'usd',
               'description' => 'Total Subscription Charges',
   ]);

print_r($data); //get response from stripe when charges created in stripe for specific user

Step 3)

Finally, run this test.php file in your system; it will send the data to your Stripe. For more API, visit this link: https://stripe.com/docs/api

11 responses

11 thoughts on “Integrate Stripe API using php

  1. cialis low dose review

    What’s Happening i’m new to this, I stumbled upon this I have discovered It absolutely useful and it has helped me out loads. I’m hoping to contribute & help different users like its aided me. Great job.

  2. sildenafil side effects

    I will immediately clutch your rss feed as I can not to find your email subscription hyperlink or e-newsletter service. Do you have any? Please allow me recognise so that I may just subscribe. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *