public async Task <IActionResult> GetData(TransactionModel model) { TempData["APIKey"] = model.APIKey; List <PaymentResponse> paymentResponses = new List <PaymentResponse>(); var token = ""; using (var httpClient = new HttpClient()) { var tokenRequest = new APIModeModel() { apiKey = model.APIKey }; StringContent content = new StringContent(JsonConvert.SerializeObject(tokenRequest), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/Token", content)) { token = await response.Content.ReadAsStringAsync(); } } using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); using (var response = await httpClient.GetAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/CardTransaction/GetPayments/20")) { string apiResponse = await response.Content.ReadAsStringAsync(); paymentResponses = JsonConvert.DeserializeObject <List <PaymentResponse> >(apiResponse); } } if (paymentResponses != null) { model.Transactions = paymentResponses; } return(View("Index", model)); }
public async Task <IActionResult> Detail(string id) { var APIKey = Convert.ToString(TempData["APIKey"]); var token = ""; using (var httpClient = new HttpClient()) { var tokenRequest = new APIModeModel() { apiKey = APIKey }; StringContent content = new StringContent(JsonConvert.SerializeObject(tokenRequest), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/Token", content)) { token = await response.Content.ReadAsStringAsync(); } } CardTransactionResponse cardTransactionResponse = null; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); using (var response = await httpClient.GetAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/CardTransaction/Detail/{id}")) { string apiResponse = await response.Content.ReadAsStringAsync(); cardTransactionResponse = JsonConvert.DeserializeObject <CardTransactionResponse>(apiResponse); } } return(View("detail", cardTransactionResponse)); }
public async Task <IActionResult> Index(PaymentModel paymentModel) { if (!this.ModelState.IsValid || paymentModel == null) { return(this.View()); } var token = ""; using (var httpClient = new HttpClient()) { var tokenRequest = new APIModeModel() { apiKey = paymentModel.APIKey }; StringContent content = new StringContent(JsonConvert.SerializeObject(tokenRequest), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/Token", content)) { token = await response.Content.ReadAsStringAsync(); } } var request = new PaymentRequest() { amount = new Amount() { currency = paymentModel.Currency, value = paymentModel.Amount.ToString() }, description = paymentModel.Description, locale = "DE", redirectUrl = $"{_httpContextAccessor.HttpContext.Request.Scheme}://{_httpContextAccessor.HttpContext.Request.Host.Value}/home/Success", sequenceType = 1, webhookUrl = $"{_httpContextAccessor.HttpContext.Request.Scheme}://{_httpContextAccessor.HttpContext.Request.Host.Value}/home/Success", method = 1 }; PaymentResponseMessage paymentResponseMessage = null; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); StringContent content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/CreatePaymentAPI", content)) { string apiResponse = await response.Content.ReadAsStringAsync(); paymentResponseMessage = JsonConvert.DeserializeObject <PaymentResponseMessage>(apiResponse); } } if (paymentResponseMessage != null) { if (paymentResponseMessage.ErrorCode == string.Empty) { return(this.Redirect(paymentResponseMessage.PaymentResponse.CheckoutUrl)); } else { _logger.LogError(paymentResponseMessage.ErrorMessage); // Show Error return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } } return(View()); }