PHP code example of instamojo / instamojo-php

1. Go to this page and download the library: Download instamojo/instamojo-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

instamojo / instamojo-php example snippets


$authType = "app/user" /**Depend on app or user based authentication**/

$api = Instamojo\Instamojo::init($authType,[
        "client_id" =>  'XXXXXQAZ',
        "client_secret" => 'XXXXQWE',
        "username" => 'FOO', /** In case of user based authentication**/
        "password" => 'XXXXXXXX' /** In case of user based authentication**/

    ],true); /** true for sandbox enviorment**/


$api = Instamojo\Instamojo::init($authType,[
        "client_id" =>  'XXXXXQAZ',
        "client_secret" => 'XXXXQWE',
        "username" => 'FOO', /** In case of user based authentication**/
        "password" => 'XXXXXXXX' /** In case of user based authentication**/

    ]);

try {
    $response = $api->createPaymentRequest(array(
        "purpose" => "FIFA 16",
        "amount" => "3499",
        "send_email" => true,
        "email" => "[email protected]",
        "redirect_url" => "http://www.example.com/handle_redirect.php"
        ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->getPaymentRequestDetails(['PAYMENT REQUEST ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->getPaymentRequests();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

getPaymentRequests($limit=null, $page=null)

$response = $api->getPaymentRequests(50, 1);

try {
    $response = $api->getPayments();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

getPayments($limit=null, $page=null)

$response = $api->getPayments(50, 1);

try {
    $response = $api->getPaymentDetails(['PAYMENT ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->createGatewayOrder(array(
      "name" => "XYZ",
      "email" => "[email protected]",
      "phone" => "99XXXXXXXX",
      "amount" => "200",
      "transaction_id" => 'TXN_ID', /**transaction_id is unique Id**/
      "currency" => "INR"
    ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->createGatewayOrderForPaymentRequest($payment_request_id, array(
      "name" => "XYZ",
      "email" => "[email protected]",
      "phone" => "99XXXXXXXX",
    ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->getGatewayOrder(['ORDER ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->getGatewayOrders();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

getGatewayOrders($limit=null, $page=null)

$response = $api->getGatewayOrders(50, 1);

try {
    $response = $api->createRefundForPayment($payment_id, array(
      "type" => "RFD",
      "body" => "XYZ reason of refund",
      "refund_amount" => "10",
      "transaction_id" => "TNX_XYZ"
    ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->getRefundDetails(['REFUND ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

try {
    $response = $api->getRefunds();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

getRefunds($limit=null, $page=null)

$response = $api->getRefunds(50, 1);
bash
php composer.phar