Integrate API

Integrate API - Header

Sunday, August 24, 2014

how to use google distance matrix api

you need to calculate distance between couple of points/address? you need to set a shortest path route of your travelling? you need to deliver your goods to customer as soon as possible with lowest cost? google distance matrix api is a good solution for you. here i am going to show how to use google distance matrix api for any of your above purpose.
first of all you need to enable distance matrix in google. as your know, in order to use google service you must need a valid gmail id. let me consider you already have one.

  1. now open to https://code.google.com/apis/console and log in your gmail account. 
  2. from the left menu click service link and activate Distance Matrix API
  3. Once you have activated, your API key is available from the API Access page, section: Simple API Access . And Distance Matrix API applications use the "Key for server apps" for me it looks like: 

 Key for server apps (with IP locking)
API key:
AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo
IPs:
Any IP allowed
Activated on: Dec 15, 2013 6:39 AM
  • mode — when calculating directions which mode of transport will consider? . Valid values are:
    • driving (default) indicates standard driving directions using the road network.
    • walking 
    • bicycling only available in the US and some cities in Canadia
  • You can receive two different types of output of distance:
    1. JSON Output
    2. XML Output
    All parameters are remain same except json/xml in request url.

    A simple distance matrix example(JSON Output): 
    https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo

    https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=driving&language=fr-EN&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo

    A simple distance matrix example(XML Output): 
    https://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=driving&language=fr-EN&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo

    You can also get direction request:
    https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo&avoid=highways&mode=bicycling

    More documentation of Google Distance Matrix API is here.
    Similar to Google Matrix API mapquest documentation is here.

    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();

      }