public IActionResult PaymentGatewayCallback(SSLCommerzValidatorResponse response) { if (!string.IsNullOrEmpty(response.status) && response.status == "VALID") { var userId = _userManager.GetUserId(User); SSLCommerz sslcz = new SSLCommerz(storeID, storePassword, true); if (sslcz.OrderValidate(response.tran_id, response.amount, response.currency, Request)) { return(View("Success")); } } if (!string.IsNullOrEmpty(response.status) && response.status == "FAILED") { return(View("Fail")); } if (!string.IsNullOrEmpty(response.status) && response.status == "CANCELLED") { return(View("Cancel")); } return(View("Error")); }
private bool ReadSSLCommerzValidatorResponse(string json, string merchantTrxID, string merchantTrxAmount, string merchantTrxCurrency) { try { if (json != "") { SSLCommerzValidatorResponse resp = JsonConvert.DeserializeObject <SSLCommerzValidatorResponse>(json); if (resp != null && (resp.status == "VALID" || resp.status == "VALIDATED")) { if (merchantTrxCurrency == "BDT") { if (merchantTrxID == resp.tran_id && (Math.Abs(Convert.ToDecimal(merchantTrxAmount) - Convert.ToDecimal(resp.amount)) < 1) && merchantTrxCurrency == "BDT") { return(true); } else { string error = "Amount not matching"; logger.LogError(error); return(false); } } else { if (merchantTrxID == resp.tran_id && (Math.Abs(Convert.ToDecimal(merchantTrxAmount) - Convert.ToDecimal(resp.currency_amount)) < 1) && merchantTrxCurrency == resp.currency_type ) { return(true); } else { string error = "Currency Amount not matching"; logger.LogError(error); return(false); } } } else { string error = "This transaction is either expired or fails"; logger.LogError(error); return(false); } } else { string error = "Unable to get Transaction JSON status"; logger.LogError(error); return(false); } } catch (Exception ex) { logger.LogError(ex, $"ReadSSLCommerzValidatorResponse {ex.Message}"); } return(false); }
public IActionResult PaymentGatewayCallback(SSLCommerzValidatorResponse response) { if (!string.IsNullOrEmpty(response.status) && response.status == "VALID") { SSLCommerz sslcz = new SSLCommerz(storeID, storePassword, true); if (sslcz.OrderValidate(response.tran_id, totalAmount, "BDT", Request)) { return(View("Success", GetProperties(response))); } } if (!string.IsNullOrEmpty(response.status) && response.status == "FAILED") { return(View("Fail", GetProperties(response))); } if (!string.IsNullOrEmpty(response.status) && response.status == "CANCELLED") { return(View("Cancel", GetProperties(response))); } return(View("Error", GetProperties(response))); }
public bool OrderValidate(string MerchantTrxID, string MerchantTrxAmount, string MerchantTrxCurrency, HttpRequest req) { bool hash_verified = this.ipn_hash_verify(req); if (hash_verified) { string json = string.Empty; string EncodedValID = System.Web.HttpUtility.UrlEncode(req.Form["val_id"]); string EncodedStoreID = System.Web.HttpUtility.UrlEncode(this.Store_ID); string EncodedStorePassword = System.Web.HttpUtility.UrlEncode(this.Store_Pass); string validate_url = this.SSLCz_URL + this.Validation_URL + "?val_id=" + EncodedValID + "&store_id=" + EncodedStoreID + "&store_passwd=" + EncodedStorePassword + "&v=1&format=json"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(validate_url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream resStream = response.GetResponseStream(); using (StreamReader reader = new StreamReader(resStream)) { json = reader.ReadToEnd(); } if (json != "") { SSLCommerzValidatorResponse resp = JsonConvert.DeserializeObject <SSLCommerzValidatorResponse>(json); if (resp.status == "VALID" || resp.status == "VALIDATED") { if (MerchantTrxCurrency == "BDT") { if (MerchantTrxID == resp.tran_id && (Math.Abs(Convert.ToDecimal(MerchantTrxAmount) - Convert.ToDecimal(resp.amount)) < 1) && MerchantTrxCurrency == "BDT") { return(true); } else { this.error = "Amount not matching"; return(false); } } else { if (MerchantTrxID == resp.tran_id && (Math.Abs(Convert.ToDecimal(MerchantTrxAmount) - Convert.ToDecimal(resp.currency_amount)) < 1) && MerchantTrxCurrency == resp.currency_type) { return(true); } else { this.error = "Currency Amount not matching"; return(false); } } } else { this.error = "This transaction is either expired or fails"; return(false); } } else { this.error = "Unable to get Transaction JSON status"; return(false); } } else { this.error = "Unable to verify hash"; return(false); } }