public TransactionStatusRes GetTransactionStatus(string reqId) { string EndPoint = "https://api.paykun.com/v1/merchant/transaction/"; if (this.IsLive == false) { EndPoint = "https://sandbox.paykun.com/api/v1/merchant/transaction/"; } // Post JSON using (var httpClientHandler = new HttpClientHandler()) { //httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; using (var client = new HttpClient(httpClientHandler)) { client.DefaultRequestHeaders.Add("MerchantId", this.MerchantId); client.DefaultRequestHeaders.Add("AccessToken", this.AccessToken); var result = client.GetAsync(EndPoint + reqId).Result; string resultContent = result.Content.ReadAsStringAsync().Result; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; TransactionStatusRes _res = Newtonsoft.Json.JsonConvert.DeserializeObject <TransactionStatusRes>(resultContent, settings); return(_res); } } }
public TransactionStatusRes GetTransactionStatus(string reqId) { string EndPoint = "https://api.paykun.com/v1/merchant/transaction/"; // Post JSON using (var httpClientHandler = new HttpClientHandler()) { //httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls; using (var client = new HttpClient(httpClientHandler)) { client.DefaultRequestHeaders.Add("MerchantId", this.MerchantId); client.DefaultRequestHeaders.Add("AccessToken", this.AccessToken); var result = client.GetAsync(EndPoint + reqId).Result; string resultContent = result.Content.ReadAsStringAsync().Result; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; try { TransactionStatusRes _res = Newtonsoft.Json.JsonConvert.DeserializeObject <TransactionStatusRes>(resultContent, settings); return(_res); } catch (Exception ae) { return(null); } } } }
protected void Page_Load(object sender, EventArgs e) { string _reqId = this.Request.Params.Get("payment-id"); //string controlId = this.FindControl(this.Request.Params.Get("__EVENTTARGET")).ID //string _reqId = HttpContext.Request.Query["payment-id"].ToString(); PaykunPayment _payment = new PaykunPayment("<merchantId>", "<accessToken>", "<encKey>", _isLive: false); // Change _isLive to false for sandbox mode, While using sandbox mode you will need to provide credintials for sandbox and not of live environment TransactionStatusRes transRes = _payment.GetTransactionStatus(_reqId); payment_failed_detail.Text = "<table>" + "<thead>" + "<tr>" + "<th>Transaction Id</th>" + "<th>Amount</th>" + "<th>OrderId</th>" + "<th>Customer Name</th>" + "<th>Customer Email</th>" + "<th>Mobile</th>" + "<th>Product Name</th>" + "</tr>" + "</thead>" + "<tbody>" + "<tr>" + "<td>" + transRes.data.transaction.payment_id + "</td>" + "<td>" + transRes.data.transaction.order.gross_amount + "</td>" + "<td>" + transRes.data.transaction.order.order_id + "</td>" + "<td>" + transRes.data.transaction.customer.name + "</td>" + "<td>" + transRes.data.transaction.customer.email_id + "</td>" + "<td>" + transRes.data.transaction.customer.mobile_no + "</td>" + "<td>" + transRes.data.transaction.order.product_name + "</td>" + "</tr>" + "</tbody>" + "</table>" + "<style>table {font-family: arial, sans-serif;border-collapse: collapse;width: 100%;}td, th {border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even) {background-color: #dddddd;}</style>"; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { string _reqId = HttpContext.Current.Request.Params.Get("payment-id").ToString(); //Get this params from paykun return url //string _reqId = "05745-64541-69405-82270"; PaykunPayment _payment = new Paykun.PaykunPayment("060806219399378", "C019A43EB7B95D4D7FA51D148DFE9B3D", "9DFD9CE5071C0413AB33028FEA4EC781", _isLive: true); // Change _isLive to false for sandbox mode, While using sandbox mode you will need to provide credintials for sandbox and not of live environment TransactionStatusRes transRes = _payment.GetTransactionStatus(_reqId); if (transRes.status == true) { //Request status //handle your response here if (transRes.data.transaction.status == "Failed") { //Failed transaction } else if (transRes.data.transaction.status == "Initialized") { //Initialized transaction } else if (transRes.data.transaction.status == "Success") { //Success transaction Response.Redirect("payment_success.aspx?Payment_Id=" + _reqId + ""); } } else { //Request error get here your error description string error = transRes.errors.errorMessage; // Response.Redirect("patient/payment_success.aspx?Payment_Id=" + _reqId + ""); } } catch (Exception ex) { ex.ToString(); } } }