public async Task <IEvent> Execute(CreateTransactionAuthorize order) { using (var client = new HttpClient()) { //TODO: MOCK CIELO var input = new CreateTransactionInput(); if (order.TransactionAuthorize.Gateway.Payment.Amount.Equals("99")) { return(new PaymentDenied("99")); } string json = JsonConvert.SerializeObject(input); var requestData = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(String.Format("http://gateway.stone.com.br"), requestData); // CreateTransactionResult result = null; // if (response.IsSuccessStatusCode) // result = await response.Content.ReadAsAsync<CreateTransactionResult>(); if (order.TransactionAuthorize.Gateway.Payment.Amount.Equals("99")) { return(new PaymentDenied("1")); } return(new PaymentSuccess(Guid.NewGuid().ToString())); } }
public async Task <IEvent> Execute(CreateTransactionAuthorize order) { using (var client = new HttpClient()) { //TODO: MOCK CIELO var input = new CreateTransactionInput(); input.Customer.Name = order.TransactionAuthorize.Gateway.Billing.Name; input.MerchantOrderId = order.TransactionAuthorize.Verification.MerchantId; input.Payment.Amount = Convert.ToInt32(order.TransactionAuthorize.Gateway.Payment.Amount); input.Payment.CreditCard.CardNumber = order.TransactionAuthorize.Gateway.Payment.CardNumber; if (order.TransactionAuthorize.Gateway.Payment.Amount.Equals("99")) { return(new PaymentDenied("99")); } string json = JsonConvert.SerializeObject(input); var requestData = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(String.Format("https://developercielo.github.io/manual/cielo-ecommerce#requisi%C3%A7%C3%A3o"), requestData); // CreateTransactionResult result = null; // if (response.IsSuccessStatusCode) // result = await response.Content.ReadAsAsync<CreateTransactionResult>(); return(new PaymentSuccess(Guid.NewGuid().ToString())); } }
public IGateway Execute(CreateTransactionAuthorize order) { switch (order.TransactionAuthorize.Gateway.Payment.Acquirer.ToLower()) { case "cielo": return(new CieloService()); case "stone": return(new StoneService()); default: throw new ApplicationException(string.Format("Gateway '{0}' não pode ser criado", order.TransactionAuthorize.Gateway.Payment.Acquirer)); } }
public async Task <TransactionResult> Execute(CreateTransactionAuthorize command) { var result = new TransactionResult(); var selectedGateway = gatewayFactory.Execute(command); var response = await selectedGateway.Execute(command); var transaction = new Transaction(); transaction.Gateway = command.TransactionAuthorize.Gateway; transaction.Verification = command.TransactionAuthorize.Verification; if (response is PaymentSuccess) { var success = response as PaymentSuccess; transaction.Message = success.Message; transaction.TID = success.Code; } else { var denied = response as PaymentDenied; transaction.Message = denied.Message; } result.TransactionResponse = new TransactionResponse(); result.TransactionResponse.Order = new Order(); result.TransactionResponse.Message = transaction.Message; result.TransactionResponse.Order.TID = transaction.TID; result.TransactionResponse.Order.DateTime = transaction.CreatedAt; result.TransactionResponse.Order.TotalAmount = transaction.Gateway.Payment.Amount; transactionRepository.Save(transaction); return(result); }
public async Task <IActionResult> Post([FromBody] CreateTransactionAuthorize command) { var response = await service.Execute(command); return(await Response(response)); }
public abstract IGateway Execute(CreateTransactionAuthorize Transaction);