public IHdfcEnrollmentResponse HdfcEnrollmentVerification(IHdfcCharge hdfcCharge) { try { IHdfcEnrolledCharge hdfcEnrolledCharge = new HdfcEnrolledCharge(); string response = HdfcChargerHelper.HttpWebRequestHandler(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.EnrollmentVerificationUrl), HdfcChargerHelper.GetHdfcChargeRequest(hdfcCharge, _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.TranportalId), _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.TranportalPassword))); string result = HdfcChargerHelper.GetResultField(response, "result"); string error = HdfcChargerHelper.GetResultField(response, "error_text"); bool errorStatus = string.IsNullOrWhiteSpace(error) ? true : false; if (errorStatus) { if (result.ToUpper().Equals("ENROLLED")) { hdfcEnrolledCharge.AcsUrl = HdfcChargerHelper.GetResultField(response, "url"); hdfcEnrolledCharge.PaymentAuthenticationRequest = HdfcChargerHelper.GetResultField(response, "PAReq"); hdfcEnrolledCharge.PaymentId = HdfcChargerHelper.GetResultField(response, "paymentid"); } hdfcEnrolledCharge.Result = HdfcChargerHelper.GetResultField(response, "result"); hdfcEnrolledCharge.Error = HdfcChargerHelper.GetResultField(response, "error_text"); hdfcEnrolledCharge.Eci = !string.IsNullOrWhiteSpace(HdfcChargerHelper.GetResultField(response, "eci")) ? HdfcChargerHelper.GetResultField(response, "eci") : "7"; hdfcEnrolledCharge.TransactionId = hdfcCharge.TransactionId; hdfcEnrolledCharge.Amount = hdfcCharge.Amount; _transactionPaymentDetailRepository.Save(new TransactionPaymentDetail { TransactionId = Convert.ToInt64(hdfcCharge.TransactionId), PaymentOptionId = PaymentOptions.CreditCard, PaymentGatewayId = PaymentGateway.HDFC, UserCardDetailId = hdfcCharge.UserCardDetailId, RequestType = "Charge Resolver", Amount = hdfcCharge.Amount.ToString(), PayConfNumber = "", PaymentDetail = "{\"Response\":" + Newtonsoft.Json.JsonConvert.SerializeObject(hdfcEnrolledCharge) + "}", }); } return(GetHdfcEnrollmentResponse(errorStatus ? hdfcEnrolledCharge : null, errorStatus ? PaymentGatewayError.None : HdfcChargerHelper.GetPaymentGatewayErrorCode(string.IsNullOrWhiteSpace(error) ? "Transaction declined" : error))); } catch (Exception ex) { _logger.Log(LogCategory.Error, new Exception("Failed to verify enrollment", ex)); return(GetHdfcEnrollmentResponse(null, HdfcChargerHelper.GetPaymentGatewayErrorCode(ex.Message))); } }
public IPaymentResponse HdfcResponseHandler(IGatewayCharge gatewayResponse) { NameValueCollection nvcResponseQueryString = HttpUtility.ParseQueryString(gatewayResponse.QueryString); var paymentId = nvcResponseQueryString["MD"]; var paymentAuthenticationResponse = nvcResponseQueryString["PaRes"]; try { string response = gatewayResponse.Response;//HdfcChargerHelper.HttpWebRequestHandler(_settings.GetConfigSetting<string>(SettingKeys.PaymentGateway.Hdfc.PayerAuthenticationUrl), GetHdfcEnrolledRequest(paymentId, paymentAuthenticationResponse)); string result = HdfcChargerHelper.GetResultField(response, "result"); string error = HdfcChargerHelper.GetResultField(response, "error_text"); var amount = HdfcChargerHelper.GetResultField(response, "amt"); paymentId = HdfcChargerHelper.GetResultField(response, "paymentid"); string paymentConfirmationNumber = HdfcChargerHelper.GetResultField(response, "tranid"); var transactionId = HdfcChargerHelper.GetResultField(response, "trackid"); bool payStatus = result.ToUpper().Equals("CAPTURED") ? true : false; if (payStatus) { if (transactionId != null) { _transactionStatusUpdater.UpdateTranscationStatus(Convert.ToInt64(transactionId)); _transactionPaymentDetailRepository.Save(new TransactionPaymentDetail { TransactionId = Convert.ToInt64(transactionId), PaymentOptionId = PaymentOptions.CreditCard, PaymentGatewayId = PaymentGateway.HDFC, RequestType = "Enrolled Recieved", Amount = amount.ToString(), PayConfNumber = paymentConfirmationNumber, PaymentDetail = "{\"QueryString\":" + JsonConvert.SerializeObject(nvcResponseQueryString.AllKeys.ToDictionary(k => k, k => nvcResponseQueryString[k])) + ",\"Response\":{\"Result\":\"" + result + "\",\"Error\":\"" + error + "\",\"Amount\":\"" + amount + "\",\"PaymentConfirmationNumber\":\"" + paymentConfirmationNumber + "\",\"PaymentId\":\"" + paymentId + "\",\"TrackId\":\"" + transactionId + "\"}}" }); } } return(GetPaymentResponse(payStatus ? true : false, payStatus ? PaymentGatewayError.None : HdfcChargerHelper.GetPaymentGatewayErrorCode(string.IsNullOrWhiteSpace(error) ? "Transaction declined" : error))); } catch (Exception ex) { _logger.Log(LogCategory.Error, new Exception("Failed to process transaction", ex)); return(GetPaymentResponse(false, HdfcChargerHelper.GetPaymentGatewayErrorCode(ex.Message))); } }
protected override async Task <IPaymentResponse> CreateCharge(IHdfcCharge hdfcCharge) { try { string response = HdfcChargerHelper.HttpWebRequestHandler(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.TransactionPortalUrl), HdfcChargerHelper.GetHdfcChargeRequest(hdfcCharge, _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.TranportalId), _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.TranportalPassword))); string result = HdfcChargerHelper.GetResultField(response, "result"); string error = HdfcChargerHelper.GetResultField(response, "error_text"); string amount = HdfcChargerHelper.GetResultField(response, "amt"); string paymentId = HdfcChargerHelper.GetResultField(response, "payid"); string transactionId = HdfcChargerHelper.GetResultField(response, "trackid"); string paymentConfirmationNumber = HdfcChargerHelper.GetResultField(response, "tranid"); bool payStatus = result.ToUpper().Equals("CAPTURED") ? true : false; if (payStatus) { if (transactionId != null) { _transactionStatusUpdater.UpdateTranscationStatus(Convert.ToInt64(transactionId)); } } _transactionPaymentDetailRepository.Save(new TransactionPaymentDetail { TransactionId = Convert.ToInt64(hdfcCharge.TransactionId), PaymentOptionId = PaymentOptions.CreditCard, PaymentGatewayId = PaymentGateway.HDFC, RequestType = "Not Enrolled Recieved", Amount = hdfcCharge.Amount.ToString(), PayConfNumber = paymentConfirmationNumber, PaymentDetail = "{\"Response\":{\"Result\":\"" + result + "\",\"Error\":\"" + error + "\",\"Amount\":\"" + amount + "\",\"PaymentConfirmationNumber\":\"" + paymentConfirmationNumber + "\",\"PaymentId\":\"" + paymentId + "\",\"TrackId\":\"" + transactionId + "\"}", }); return(GetPaymentResponse(payStatus ? true : false, payStatus ? PaymentGatewayError.None : HdfcChargerHelper.GetPaymentGatewayErrorCode(string.IsNullOrWhiteSpace(error) ? "Transaction declined" : error))); } catch (Exception ex) { _logger.Log(LogCategory.Error, new Exception("Failed to create charge", ex)); return(GetPaymentResponse(false, HdfcChargerHelper.GetPaymentGatewayErrorCode(ex.Message))); } }
public TransactionProvider Get(string queryString) { TransactionProvider transactionProvider = new TransactionProvider(); try { var nvcResponseQueryString = HttpUtility.ParseQueryString(queryString); // Custom redirects if (nvcResponseQueryString.AllKeys.Contains("gateway")) { var isValid = Enum.TryParse <PaymentGateway>(nvcResponseQueryString["gateway"], out PaymentGateway gateway); if (isValid) { if (gateway == PaymentGateway.Stripe) { var orderId = nvcResponseQueryString["orderId"]; transactionProvider.TransactionId = !string.IsNullOrWhiteSpace(orderId) ? Convert.ToInt64(orderId) : 0; transactionProvider.PaymentGateway = PaymentGateway.Stripe; transactionProvider.Token = nvcResponseQueryString["source"]; return(transactionProvider); } } } // NAB Transact if (nvcResponseQueryString.AllKeys.Contains("refid")) { string orderId = nvcResponseQueryString["refid"]; transactionProvider.TransactionId = !string.IsNullOrWhiteSpace(orderId) ? Convert.ToInt64(orderId) : 0; transactionProvider.PaymentGateway = PaymentGateway.NabTransact; return(transactionProvider); } // CCAvenue if (nvcResponseQueryString.AllKeys.Contains("encResp")) { CCACrypto ccaCrypto = new CCACrypto(); var encResponseValue = nvcResponseQueryString["encResp"]; string encResponse = ccaCrypto.Decrypt(encResponseValue, _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Ccavenue.WorkingKey)); NameValueCollection nvcQueryString = new NameValueCollection(); string[] segments = encResponse.Split('&'); foreach (string seg in segments) { string[] parts = seg.Split('='); if (parts.Length > 0) { string Key = parts[0].Trim(); string Value = parts[1].Trim(); nvcQueryString.Add(Key, Value); } } string orderId = nvcQueryString["order_id"]; transactionProvider.TransactionId = !string.IsNullOrWhiteSpace(orderId) ? Convert.ToInt64(orderId) : 0; transactionProvider.PaymentGateway = PaymentGateway.CCAvenue; return(transactionProvider); } // HDFC if (nvcResponseQueryString.AllKeys.Contains("PaRes")) { var paymentId = nvcResponseQueryString["MD"]; var paymentAuthenticationResponse = nvcResponseQueryString["PaRes"]; var response = HdfcChargerHelper.HttpWebRequestHandler(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Hdfc.PayerAuthenticationUrl), GetHdfcEnrolledRequest(paymentId, paymentAuthenticationResponse)); var orderId = HdfcChargerHelper.GetResultField(response, "trackid"); return(new TransactionProvider { TransactionId = !string.IsNullOrWhiteSpace(orderId) ? Convert.ToInt64(orderId) : 0, Response = response, PaymentGateway = PaymentGateway.HDFC }); } if (transactionProvider.TransactionId == 0) { _logger.Log(Logging.Enums.LogCategory.Warn, "Payment method not found.", new Dictionary <string, object> { ["QueryString"] = queryString }); } } catch (Exception ex) { _logger.Log(Logging.Enums.LogCategory.Error, ex); } return(new TransactionProvider()); }