private long?CreateRequest(BankRequestDTO request) { try { Payment payment = new Payment() { amount = request.amount, additionalData = request.additionalData, RequestDatetime = DateTime.Now, StatusID = (int)RequestStatus.OnGoing, UserName = request.UserName, TerminalID = Configuration.GetGatewayInfo("Merchant"), callBackUrl = Configuration.GetGatewayInfo("CallBack") }; _context.Payments.Add(payment); _context.SaveChanges(); return(payment.PaymentID); } catch { return(null); } }
private long?CreateRequest(BankRequestDTO request) { try { //Payment payment = new Payment() //{ // amount = request.amount, // additionalData = request.additionalData, // RequestDatetime = DateTime.Now, // StatusID = (int)RequestStatus.OnGoing, // UserName = request.UserName, // TerminalID = Configuration.GetGatewayInfo("Merchant"), // callBackUrl = Configuration.GetGatewayInfo("CallBack") //}; //_context.Payments.Add(payment); //_context.SaveChanges(); //return payment.PaymentID; return(1); } catch { return(null); } }
public IActionResult Verify([FromBody] BankRequestDTO model) { TerminalResponseDTO response = _zarinPalPayment.Verify(model); if (response.Success) { return(Ok(response)); } return(BadRequest(response)); }
public TerminalResponseDTO Verify(BankRequestDTO model) { TerminalResponseDTO terminalResponse = new TerminalResponseDTO() { Success = false, Message = "unhandled exception occurred" }; try { VerifyRequestVm request = new VerifyRequestVm() { amount = model.amount, authority = model.TerminalReference, merchant_id = model.TerminalID }; var jsonBody = JsonConvert.SerializeObject(request); var content = new StringContent(jsonBody, Encoding.UTF8, "application/json"); var response = _client.PostAsync(Configuration.GetGatewayInfo("Verify_Url"), content).Result; var responseContent = response.Content.ReadAsStringAsync().Result; try { VerifyResponse res = JsonConvert.DeserializeObject <VerifyResponse> (responseContent); if (res.data.code == 100 || res.data.code == 101) { if (VerifyRequest(res, request.authority)) { terminalResponse.Message = res.data.message; terminalResponse.Url = response.RequestMessage.RequestUri.AbsoluteUri; terminalResponse.Reference = res.data.ref_id.ToString(); terminalResponse.StatusID = res.data.code; terminalResponse.Success = true; } } } catch { VerifyErrorResponse err = JsonConvert.DeserializeObject <VerifyErrorResponse> (responseContent); terminalResponse.Success = false; terminalResponse.Message = err.errors.message; terminalResponse.Url = response.RequestMessage.RequestUri.AbsoluteUri; terminalResponse.StatusID = err.errors.code; } return(terminalResponse); } catch { return(terminalResponse); } }
public TerminalResponseDTO Pay(BankRequestDTO model) { TerminalResponseDTO terminalResponse = new TerminalResponseDTO() { Success = false, Message = "unhandled exception occurred" }; try { long?id = CreateRequest(model); if (id.HasValue) { PaymentRequestVm request = new PaymentRequestVm() { amount = model.amount, callback_url = model.callBackUrl, description = model.additionalData, email = "", mobile = "", merchant_id = model.TerminalID }; var jsonBody = JsonConvert.SerializeObject(request); var content = new StringContent(jsonBody, Encoding.UTF8, "application/json"); var response = _client.PostAsync(Configuration.GetGatewayInfo("Request_Url"), content).Result; var responseContent = response.Content.ReadAsStringAsync().Result; try { if (response.IsSuccessStatusCode) { PaymentResponseVm res = JsonConvert.DeserializeObject <PaymentResponseVm> (responseContent); if (res.data.code == 100) { if (AddPaymentAuthority(res, id.Value)) { terminalResponse.Message = res.data.message; terminalResponse.Url = Configuration.GetGatewayInfo("StartPayment_Url") + res.data.authority; terminalResponse.Reference = res.data.authority; terminalResponse.StatusID = res.data.code; terminalResponse.Success = true; } } } } catch { PaymentErrorResponse err = JsonConvert.DeserializeObject <PaymentErrorResponse> (responseContent); terminalResponse.Success = false; terminalResponse.Message = err.errors.message; terminalResponse.Url = response.RequestMessage.RequestUri.AbsoluteUri; terminalResponse.StatusID = err.errors.code; } return(terminalResponse); } return(terminalResponse); } catch { return(terminalResponse); } }