Integrate API

Integrate API - Header

Saturday, August 2, 2014

How to integrate stripe payment gateway in php

Download all working example created by me: download

Here are the way of use stripe serves quickly.

An overview of how stripe coding works can be found at here

All from A-Z technical with good details  is here

Download couple of the best examples/souse code from here

Step 01:
Create developer Sendbox account in stripe.com https://manage.stripe.com/register

Step 02:
Stripe.com will send you a link to verify your email address and once your email address is verified you are ready to use stripe.com. Log in https://dashboard.stripe.com/login. after successful log in you will be redirected to an url like: https://dashboard.stripe.com/test/dashboard. right under the logo you will get a switching button to switch from Text to Live and vice versa. we will later discuss about it.

Step 03:
From left menu. General->Payments. Click "Create your first payment". In test mode, you can't enter any credit card number you wish. instead you have to use credit cards mentioned https://stripe.com/docs/testing. (For example, 4242424242424242 is a VISA Card)You can put blank CVC field and card expiration date can be any future date.

Step 04:
From left menu. General->Customer, Transfer, Recipient. you can create these from here.

Step 05:
From top right corner, beside your picture click on the down arrow. Click "Account Settings" click API Keys and collect secret and publishable keys from here.

Step 06:
Now download php library from https://github.com/stripe/stripe-php

Step 07:
Download very good 07 examples from https://github.com/stripe/wilde-things. i really appreciate their effort.

Recurring Payment:
Subscription -> Plans -> Create New Plan. Enter the following details:
ID: DAILY_PLAN_ID_420
Name: DAILY PAY ONE DOLLER
Amount: 1
Currency: USD
Interval: daily (daily/monthly/yearly/etc...)
Trial period days: 0
Statement Description: DAILY PAYMENT 1 USD

Download all working example created by me: download

Error & Solution:
Error: failed to call pay.php to process the transaction.
Solution: when i upload all files in server i don't get this error message.

Pause/Cancel Subscription Code:
  Stripe::setApiKey("sk_test_LteiEDqVirhMuUt3IzzxUHkU");
  //Create Customer
  try {
        $customer_id=$_POST['customer_id'];
        $customer_info = Stripe_Customer::retrieve($customer_id);
        //print_r($customer_info);
        echo $subscription_id=$customer_info->subscriptions->data[0]['id'];
        if($customer_info->subscriptions->retrieve($subscription_id)->cancel())
          echo "Subscription canceled successfully.";
        else
          echo "Error while cancel subscription";
  }
  catch (Exception $e) {
    $error = $e->getMessage();
  }
 
Subscription for an Existing Customer(using customer id):
  Stripe::setApiKey("sk_test_LteiEDqVirhMuUt3IzzxUHkU");
  //Create Customer
  try {
        $customer_id=$_POST['customer_id'];
        $plan_id="DAILY_PLAN_ID_420";
        $customer_info = Stripe_Customer::retrieve($customer_id);
        //print_r($customer_info);
       
        if($customer_info->subscriptions->create(array("plan" => $plan_id)))
          echo "Subscription to $plan_id for customer id $customer_id is successfully.";
        else
          echo "Error while subscribe for customer id $customer_id.";
  }
  catch (Exception $e) {
    $error = $e->getMessage();

  }

5 comments:

  1. Right under the logo you will get a switching button to switch from Text to Live and vice versa. we will later discuss about it.
    My Big Coin

    ReplyDelete
  2. excellent posting brother,it help me a lot in my project, this blog made my work a lot ease, i love it bro, it brought alot respect on u sir, knowledge should be share,i believed that

    ReplyDelete
  3. Nice post and very informative! it will help for us. Definetly,I will follow your steps in my project.
    Payment gateway integration

    ReplyDelete
  4. Thanks for sharing this information. We provide free and easy to integrate Bulk SMS API PHP which is additional support for our customers.

    ReplyDelete
  5. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly..
    payment gateway in qatar

    ReplyDelete