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

0 Comment

Leave a Reply

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