Tag Archives: Stripe Using API

Integrate Stripe API using php

If you need to integrate stripe api to your php project then follow this tutorial which can create/edit/update/delete charges, customer, subscription, plan, payment,card 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 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)

Upload this stripe demo library to your project. click here for download library

Step 2)

Now make one test.php file for create customer to stripe using api in php and include 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 sent the data to your stripe. for more api visit this link https://stripe.com/docs/api