Skip to content

Instantly share code, notes, and snippets.

@bhatguru03
Last active April 3, 2019 20:07
Show Gist options
  • Save bhatguru03/10e67cec765b60b4f4448fd2f5f6507d to your computer and use it in GitHub Desktop.
Save bhatguru03/10e67cec765b60b4f4448fd2f5f6507d to your computer and use it in GitHub Desktop.
JusPay Payment Gateway Example
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Juspay.ExpressCheckout;
using Newtonsoft.Json.Linq;
using Juspay.ExpressCheckout.Base;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
/// <summary>
/// For JusPay Payment Gateway INTEGRATION
/// </summary>
/**
*Generated By: GSource
*/
public class JusPayPayment
{
private static string Merchant_ID = "My-Merchant-ID";
private static string API_KEY = "My-API-KEY";
static JusPayPayment()
{
Config.Configure(Config.Environment.PRODUCTION, Merchant_ID, API_KEY);
}
public void CreateOrder()
{
var OrderDetails = new Dictionary<string, string>();
var OrderId = RandomOrderId();
OrderDetails.Add("order_id", OrderId);
OrderDetails.Add("amount", "1.00");
OrderDetails.Add("currency", "INR");
OrderDetails.Add("customer_id", "guest_user_101");
OrderDetails.Add("customer_email", "customer@mail.com");
OrderDetails.Add("customer_phone", "123466789");
OrderDetails.Add("product_id", "prod-141833");
OrderDetails.Add("description", "TEST Description");
OrderDetails.Add("return_url", "http://www.gsource-knowledgebase.blogspot.com");
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 |
(SecurityProtocolType)768 | (SecurityProtocolType)3072;
dynamic OrderResponse = Orders.CreateOrder(OrderDetails);
try
{
OrderResponse = OrderResponse.Result.Response;
dynamic response = Newtonsoft.Json.JsonConvert.DeserializeObject(OrderResponse.ToString());
if (response["status_id"] == 1 && response["status"] == "CREATED")
{
if (IsMobile.fBrowserIsMobile())
{
HttpContext.Current.Response.Redirect(response["payment_links"]["mobile"].ToString(), false);
}
else
{
HttpContext.Current.Response.Redirect(response["payment_links"]["web"].ToString(), false);
}
}
}
catch (Exception e)
{
}
}
private static string RandomOrderId()
{
string allowedChars = "";
allowedChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
allowedChars += "1,2,3,4,5,6,7,8,9,0,";
allowedChars += "-";
char[] sep = { ',' };
string[] arr = allowedChars.Split(sep);
string passwordString = "";
string temp = "";
Random rand = new Random();
for (int i = 0; i < 20; i++)
{
temp = arr[rand.Next(0, arr.Length)];
passwordString += temp;
}
return passwordString;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment