public async Task <PaymentInfoResponse> DoTransaction(string baseUrl, PaymentInfoRequest paymentInfoRequest) { paymentInfoRequest.SystemTraceNr = RandomNumber(1000, 10000); paymentInfoRequest.ProcessingCode = RandomNumber(999, 9999).ToString(); PaymentInfoCommand paymentInfoCommand = new PaymentInfoCommand(); using (var httpClient = new HttpClient()) { using (var keyResponse = await httpClient.GetAsync(baseUrl + "/GetKey")) { string apiGetKeyResponse = await keyResponse.Content.ReadAsStringAsync(); string key = JObject.Parse(apiGetKeyResponse)["GetKeyResult"].ToString(); paymentInfoCommand.Key = key; paymentInfoCommand.EncyptedBody = _encryptionService.Encrypt(JsonConvert.SerializeObject(paymentInfoRequest), key); StringContent content = new StringContent(JsonConvert.SerializeObject(paymentInfoCommand), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync(baseUrl + "/Pay", content)) { string apiResponse = await response.Content.ReadAsStringAsync(); PaymentInfoResponse paymentInfoResponse = JsonConvert.DeserializeObject <PaymentInfoResponse>(apiResponse); return(paymentInfoResponse); } } } }
public PaymentInfoResponse Pay(PaymentInfoCommand paymentInfoCommand) { var decryptedPaymentInfo = new AesService().Decrypt(paymentInfoCommand.EncyptedBody, paymentInfoCommand.Key); PaymentInfo paymentInfo = JsonConvert.DeserializeObject <PaymentInfo>(decryptedPaymentInfo); string approvalCode = createApprovalCode(paymentInfo); var response = new PaymentInfoResponse() { ApprovalCode = approvalCode, DateTime = DateTime.Now, Message = "SUCCESS", ResponseCode = ResponseCode.SUCCESS.ToString() }; return(response); }
public PaymentInfoResponse Pay(PaymentInfoCommand paymentInfoCommand) { TransactionsService transactionsService = new TransactionsService(); return(transactionsService.Pay(paymentInfoCommand)); }