Giter Club home page Giter Club logo

instamojo-php's Introduction

Instamojo PHP API Latest Stable Version License

Assists you to programmatically create, edit and delete Links on Instamojo in PHP.

Note: If you're using this wrapper with our sandbox environment https://test.instamojo.com/ then you should pass true as third argument to the Instamojo class while initializing it. client_id and client_secret token for the same can be obtained from https://test.instamojo.com/developers/ (Details: Test Or Sandbox Account).

$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**/

Installing via Composer

php composer.phar require instamojo/instamojo-php

Note: If you're not using Composer then directly include the contents of src directory in your project.

Usage

$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**/

    ]);

Documentation

See the Documentation for datailed instructions

Table of Content

Create a new Payment Request

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

This will give you JSON object containing details of the Payment Request that was just created with longurl key provide you instamojo-payment-url.

Recommended seamless checkout Option

You can render your Instamojo checkout form and collect payments on your webpage with just the instamojo-payment-url obtained in createPaymentRequest() using JS based seamless checkout library. To know more how its work Click here.

Payment Request Creation Parameters

Required

  • purpose: Purpose of the payment request.
  • amount: The amount for the request. The minimum amount is 9. And the maximum is 200000.

Optional

  • buyer_name: Name of the payer.
  • email: Email of the payer.
  • phone: Phone number of the payer.
  • send_email: Set this to true if you want to send email to the payer if email is specified. If email is not specified then an error is raised. (default value: false)
  • send_sms: Set this to true if you want to send SMS to the payer if phone is specified. If phone is not specified then an error is raised. (default value: false)
  • redirect_url: set this to a thank-you page on your site. Buyers will be redirected here after successful payment.
  • webhook: set this to a URL that can accept POST requests made by Instamojo server after successful payment.
  • allow_repeated_payments: To disallow multiple successful payments on a Payment Request pass false for this field. If this is set to false then the link is not accessible publicly after first successful payment, though you can still access it using API(default value: true).
  • partner_fee_type : Allows you to receive a cut from from payments you facilitate. For fixed fee set this to fixed, or for percentage fee set it to percent.
  • partner_fee : This describes the fee that you would collect. It can be either a fixed amount, or a percentage of the original amount, depending on the value of partner_fee_type.
  • mark_fulfilled : Flag to determine if you want to put the payment on hold until you explicitly fulfil it. If mark_fulfilled is True the payment will be paid out to the merchant. If mark_fulfilled is False, then the payment will be put on hold until you explicitly fulfil the payment. See Fulfil a Payment below on how to fulfil a payment.
  • expires_at : Time after which the payment request will be expired in UTC timestamp. Max value is 600 seconds. Default is Null.

Get the status or details of a Payment Request

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

This will give you JSON object containing details of the Payment Request and the payments related to it. Key for payments is 'payments'.

Here ['PAYMENT REQUEST ID'] is the value of 'id' key returned by the createPaymentRequest() query.

Get a list of all Payment Requests

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

This will give you an array containing Payment Requests created so far. Note that the payments related to individual Payment Request are not returned with this query.

getPaymentRequests() also accepts optional parameters for pagination.

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

For example:

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

This will give you an array containing Payments details so far.

getPayments() also accepts optional parameters for pagination.

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

For example:

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

This will give you JSON object containing details of the Payment.

Here ['PAYMENT ID'] is the value of 'id' key returned by the getPayments() query.

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

This will give you JSON object containing details of the order in order key and payments options in payment_options key.

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

$payment_request_id id the id key obtained in createPaymentRequest() method.

This will give you JSON object containing with created order_id key.

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

This will give you JSON object containing details of the Gateway Order.

Here ['ORDER ID'] is the value of 'id' key returned by the createGatewayOrder() query.

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

This will give you an array containing Gateway Orders details so far.

getGatewayOrders() also accepts optional parameters for pagination.

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

For example:

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

This will give you JSON object containing refund details in refund key.

Required Parameters

  • type: Three letter short-code identifying the reason for refund, string type.
  • body: Additonal text explaining the refund, string type.
  • refund_amount: This field can be used to specify the refund amount, string type.
  • transaction_id: To Prevent duplicate case creations due to replay of APIs, string type.

Valid values for type parameter:

  • RFD: Duplicate/delayed payment.
  • TNR: Product/service no longer available.
  • QFL: Customer not satisfied.
  • QNR: Product lost/damaged.
  • EWN: Digital download issue.
  • TAN: Event was canceled/changed.
  • PTH: Problem not described above.
try {
    $response = $api->getRefundDetails(['REFUND ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

This will give you JSON object containing details of the Refund.

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

This will give you an array containing Refunds details so far.

getRefunds() also accepts optional parameters for pagination.

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

For example:

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

instamojo-php's People

Contributors

ashwch avatar chaudhariamolsopan avatar deepanshsachdeva avatar hiway avatar indradhanush avatar mojodhanesh avatar nikhilsquareboat avatar rishimukherjee avatar saich avatar sarthakk97 avatar sb-vinayak avatar ved-squareboat avatar vijithv avatar yashgoenka-im avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

instamojo-php's Issues

Issue with exception handling

I am trying to call the createPaymentRequest function with an amount less than 9 INR, instead of giving a proper error message, it's giving an arbitrary error message "Invalid request" Kindly fix it. getting the same issue with other errors like invalid phone, invalid email, etc.
On the below line of code, we are getting the correct error message in $response_obj variable but in the exception which we are getting in the try/catch block, it's a wrong error message.

$message = isset($response_obj['reason']) ? $response_obj['reason'] :$message;

Array to String conversion - Instamojo.php line no. 298

Hello, I am using it with Laravel and while running the code. Create payment request is successful but when i check the payment status, it returns

Array to String Conversion

Debugging more , I found it is line no. 298 in instamojo.php

Could you please check, what am i doing wrong.

Raise an exception for cURL error.

Lots of people face cURL connection error (60) and are not able to figure it out why the API is not working, we need to raise this explicitly.

PHP 8 issues

The Library is not working with latest PHP. It returns multiple errors due to the compatibilty.
First I faced init function arguments with default param retunred errror. Then wakeup function public error. If we make this code compatible with PHP 8 this all errors will go i guess

Rename the class file name

It's not working on the linux server. Case sensitivity issue.
Rename the file instamojo-php/src/instamojo.php to instamojo-php/src/Instamojo.php

object(Instamojo\Instamojo)#3 (0) { }

$api = Instamojo\Instamojo::init('app',[
"client_id" => 'XXX',
"client_secret" => 'XXX',
],true);

why is $api is empty, can someone help 

i have removed the client_id and client_secret for security pupose

The magic method Instamojo\Instamojo::__wakeup() must have public visibility

i am trying to integrate in laravel 9 ,php version 8.1.0.
i have installed the wrapper through composer require instamojo/instamojo-php
then in controller
public function pay(Request $request){

 $api = new \Instamojo\Instamojo(
        config('services.instamojo.api_key'),
        config('services.instamojo.auth_token'),
        config('services.instamojo.url')
    );

try {
    $response = $api->paymentRequestCreate(array(
        "purpose" => "FIFA 16",
        "amount" => $request->amount,
        "buyer_name" => "$request->name",
        "send_email" => true,
        "email" => "$request->email",
        "phone" => "$request->mobile_number",
        "redirect_url" => "http://127.0.0.1:8000/pay-success"
        ));
        
        header('Location: ' . $response['longurl']);
        exit();
}catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

}

after the running the project getting error : The magic method Instamojo\Instamojo::__wakeup() must have public visibility
Screenshot_1

http_build_query is buggy in php 5.3.1

The http_build_query used to generate URL-encoded query string in instamojo/instamojo-php/src/instamojo.php does not use default separator ('&').

$options[CURLOPT_POSTFIELDS] = http_build_query($data);
This causes problem while sending post data request.

Replacing the above line with the following solves the problem temporarily

$options[CURLOPT_POSTFIELDS] = http_build_query($data, "", "&");
Reference

Multiple SDK which supports PHP 5.3.0 or later, pass the other 2 parameters as well.

404 Not Found

I am calling getPaymentDetails api for which the payment id not exists.
$response = $api->getPaymentDetails([payment id]);
Instead of giving error in response it is giving laravel error.
instamojo

So, I am not able to handle this error. How can I handle this error and continue to execute next code script.

getGatewayOrder error = no Route matched with those values

Hello

I am receiving the error in getGatewayOrder(orderid) method.

"Error: no Route matched with those values"

here is my code
try {
$response = $api->getGatewayOrder($order_id);
print_r(json_encode($response));
}
catch (Exception $e) {
print('Error: ' . $e->getMessage());
}

Composer support

Problem Definition:

  1. Could not use the package manager composer for installing dependencies.

Solution:

  1. It will greatly help to have a support for composer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.