GithubHelp home page GithubHelp logo

instamojo-csharp's Introduction

C# wrapper for Instamojo API

Table of Contents

Preface

Instamojo DotNet wrapper for the Instamojo API assists you to programmatically create and list payment orders and refunds on Instamojo.

Requirements

DotNet Version: 4.0+

Integration

To integrate the Instamojo API into your application, download the source zip from the latest release and add it your project.

Authentication Keys

Generate CLIENT_ID and CLIENT_SECRET for specific environments from the following links.

Related support article: How Do I Get My Client ID And Client Secret?

Multitenancy

As of now, MULTITENANCY IS NOT SUPPORTED by this wrapper which means you will not be able to use this wrapper in a single application with multiple Instamojo accounts. The call to InstamojoImplementation.getApi() returns a singleton object of class Instamojo with the given CLIENT_ID and CLIENT_SECRET, and will always return the same object even when called multiple times (even with a different CLIENT_ID and CLIENT_SECRET).

End Points

Test URLs

auth_endpoint : https://test.instamojo.com/oauth2/token/

endpoint: https://test.instamojo.com/v2/

Production URLs

auth endpoint : https://www.instamojo.com/oauth2/token/

endpoint: https://api.instamojo.com/v2/

Payments API

Create new Payment Order

/***** Create a new payment order *******/

Instamojo objClass = InstamojoImplementation.getApi([client_id],[client_secret],[endpoint],[auth_endpoint]);


 PaymentOrder objPaymentRequest = new PaymentOrder();
  //Required POST parameters
  objPaymentRequest.name = "ABCD";
  objPaymentRequest.email = "[email protected]";
  objPaymentRequest.phone = "0123456789";
  objPaymentRequest.amount = 9;
  objPaymentRequest.transaction_id = "test"; // Unique Id to be provided

  objPaymentRequest.redirect_url =redirect_url;
  
  //webhook is optional.
  objPaymentRequest.webhook_url = "https://your.server.com/webhook";
  
  if (objPaymentRequest.validate())
  {
               if (objPaymentRequest.emailInvalid)
               {
                   MessageBox.Show("Email is not valid");
               }
               if (objPaymentRequest.nameInvalid)
               {
                   MessageBox.Show("Name is not valid");
               }
               if (objPaymentRequest.phoneInvalid)
               {
                   MessageBox.Show("Phone is not valid");
               }
               if (objPaymentRequest.amountInvalid)
               {
                   MessageBox.Show("Amount is not valid");
               }
               if (objPaymentRequest.currencyInvalid)
               {
                   MessageBox.Show("Currency is not valid");
               }
               if (objPaymentRequest.transactionIdInvalid)
               {
                   MessageBox.Show("Transaction Id is not valid");
               }
               if (objPaymentRequest.redirectUrlInvalid)
               {
                   MessageBox.Show("Redirect Url Id is not valid");
               }
               if (objPaymentRequest.webhookUrlInvalid)
               {
					MessageBox.Show("Webhook URL is not valid");
               }

}else
{
               try
               {
                   CreatePaymentOrderResponse objPaymentResponse = objClass.createNewPaymentRequest(objPaymentRequest);
                   MessageBox.Show("Payment URL = " + objPaymentResponse.payment_options.payment_url);
                   
               }
               catch (ArgumentNullException ex)
               {
                   MessageBox.Show(ex.Message);
               }
               catch (WebException ex)
               {
                   MessageBox.Show(ex.Message);
               }
               catch (IOException ex)
               {
                   MessageBox.Show(ex.Message);
               }
               catch (InvalidPaymentOrderException ex)
               {
                   if (!ex.IsWebhookValid())
					{
						MessageBox.Show("Webhook is invalid");
					}

					if (!ex.IsCurrencyValid())
					{
						MessageBox.Show("Currency is Invalid");
					}

					if (!ex.IsTransactionIDValid())
					{
						MessageBox.Show("Transaction ID is Inavlid");
					}
               }
               catch (ConnectionException ex)
               {
                   MessageBox.Show(ex.Message);
               }
               catch (BaseException ex)
               {
                   MessageBox.Show(ex.Message);
               }
               catch (Exception ex)
               {
                   MessageBox.Show("Error:" + ex.Message);
               }
}

Payment Order Creation Parameters

Required
  1. Name: Name of the customer (max 100 characters).
  2. Email: Email address of the customer (max 75 characters).
  3. Phone: Phone number of the customer. At this point, the wrapper only supports 10 digit indian phone number with out country code.
  4. Currency: String identifier for the currency. Currently, only INR (for Indian Rupee) is supported.
  5. Amount: Amount the customer has to pay. Numbers upto 2 decimal places are supported.
  6. Transaction_id: Unique identifier for the order (max 64 characters). Identifier can contain alphanumeric characters, hyphens and underscores only. This is generally the unique order id (or primary key) in your system.
  7. Redirect_url: Full URL to which the customer is redirected after payment. Redirection happens even if payment wasn't successful. This URL shouldn't contain any query parameters.
Optional
  1. Description: Short description of the order (max 255 characters). If provided, this information is sent to backend gateways, wherever possible.

Get list of a Payment order

/***** Get list of a payment order *******/

Instamojo objClass = InstamojoImplementation.getApi([client_id],[client_secret],[endpoint],[auth_endpoint]);

try
{
  PaymentOrderListRequest objPaymentOrderListRequest = new PaymentOrderListRequest();
  //Optional Parameters
  objPaymentOrderListRequest.limit = 20;
  objPaymentOrderListRequest.page = 3;

  PaymentOrderListResponse objPaymentRequestStatusResponse =  objClass.getPaymentOrderList(objPaymentOrderListRequest);
  MessageBox.Show("Order Count = " + objPaymentRequestStatusResponse.orders.Count());
}
catch (Exception ex)
{
  MessageBox.Show("Error:" + ex.Message);
}

Payment Order List Parameters

Optional
  1. Id: Search for payment orders by id.
  2. Transaction_id: Search for payment orders by your transaction_id.
  3. Page: Page number of the results to retrieve from.
  4. Limit: Limit the number of results returned per page. Defaults to 50 results per page. Max limit allowed is 500.

Details of Payment order using OrderId

/***** Get Details of Payment order using OrderId. *******/
Instamojo objClass = InstamojoImplementation.getApi([client_id],[client_secret],[endpoint],[auth_endpoint]);

try
{
 PaymentOrderDetailsResponse objPaymentRequestDetailsResponse = objClass.getPaymentOrderDetails("[Order_Id]");
  MessageBox.Show("Transaction Id = " + objPaymentRequestDetailsResponse.transaction_id);
}
catch (Exception ex) 
{
   MessageBox.Show("Error:" + ex.Message);
}

Details of Payment order using TransactionId

/***** Details of Payment order using TransactionId. *******/
Instamojo objClass = InstamojoImplementation.getApi([client_id],[client_secret],[endpoint],[euth_endpoint]);

try
{
  PaymentOrderDetailsResponse objPaymentRequestDetailsResponse = objClass.getPaymentOrderDetailsByTransactionId("[Transaction_Id]");
  MessageBox.Show("Transaction Id = " + objPaymentRequestDetailsResponse.transaction_id);
}
catch (Exception ex) 
{
   MessageBox.Show("Error:" + ex.Message);
}

Refund API

Create a refund

Refund objRefundRequest = new Refund();

objRefundRequest.payment_id = "MOJO6701005J41260385";
objRefundRequest.type = "TNR";
objRefundRequest.body = "abcd";
objRefundRequest.refund_amount = 9;

if (objRefundRequest.validate())
{
  if (objRefundRequest.payment_idInvalid)
  {
      MessageBox.Show("payment_id is not valid");
  }
}
else
{
  try
  {
         CreateRefundResponce objRefundResponse = objClass.createNewRefundRequest(objRefundRequest);
         MessageBox.Show("Refund Id = " + objRefundResponse.refund.id);
  }
  catch (ArgumentNullException ex)
  {
         MessageBox.Show(ex.Message);
  }
  catch (WebException ex)
  {
         MessageBox.Show(ex.Message);
  }
  catch (IOException ex)
  {
         MessageBox.Show(ex.Message);
  }
  catch (InvalidPaymentOrderException ex)
  {
         MessageBox.Show(ex.Message);
  }
  catch (ConnectionException ex)
  {
         MessageBox.Show(ex.Message);
  }
  catch (BaseException ex)
  {
         MessageBox.Show(ex.Message);
  }
  catch (Exception ex)
  {
         MessageBox.Show("Error:" + ex.Message);
  }
  catch (BaseException ex)
  {
         MessageBox.Show("CustomException" + ex.Message);
  }
  catch (Exception ex)
  {
  MessageBox.Show("Exception" + ex.Message);
  }
}

Refund Creation Parameters

Required
  1. payment_id: Id of the payment.
  2. type: A three letter short-code identifying the reason for this case.
  3. body: payment_idAdditional text explaining the refund.
  4. refund_amount: This field can be used to specify the refund amount. For instance, you may want to issue a refund for an amount lesser than what was paid.

instamojo-csharp's People

Contributors

ashwch avatar saich avatar vedhavyas avatar vijithv avatar

Stargazers

 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

instamojo-csharp's Issues

Forbidden 403 error

Used the same code completely and registered in test.instamojo.com copied the api-key and auth-token from there but not showing the payment gateway, getting error

Pull Request

I have migrated instamojo-csharp to latest .NET Core 2.0 Framework
Where to send pull request?
or submit the code

How to get Payment Transaction Details in InstaMojo

Instamojo objClass = InstamojoImplementation.getApi("XXXXXX", "YYYYY", "https://test.instamojo.com/v2/", "https://test.instamojo.com/oauth2/token/");

protected void GetAllPaymentOrdersList(Instamojo objClass)
{
try
{
PaymentOrderListRequest objPaymentOrderListRequest = new PaymentOrderListRequest();
//Optional Parameters
objPaymentOrderListRequest.limit = 21;
objPaymentOrderListRequest.page = 3;

            PaymentOrderListResponse objPaymentRequestStatusResponse = objClass.getPaymentOrderList(objPaymentOrderListRequest);
            foreach (var item in objPaymentRequestStatusResponse.orders)
            {
                Console.WriteLine(item.email + item.description + item.amount);
            }
            MessageBox("Order List = " + objPaymentRequestStatusResponse.orders.Count());
        }
        catch (ArgumentNullException ex)
        {
            MessageBox(ex.Message);
        }
        catch (WebException ex)
        {
            MessageBox(ex.Message);
        }
        catch (Exception ex)
        {
            MessageBox("Error:" + ex.Message);
        }
    }

Output :

Error In : catch (WebException ex)
{
MessageBox(ex.Message);
}
Message :
Not Found {
"success": false,
"message": "Invalid page."
}

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.