public async Task<AddTriggeredPaymentResponse> AddTriggeredPaymentAsync(AddTriggeredPaymentRequest request) { var requestMessage = new PeriodicRequestMessage(); var periodicItem = requestMessage.Periodic.PeriodicList.PeriodicItem; periodicItem.ActionType = "add"; periodicItem.ClientId = request.ClientId; periodicItem.CreditCardInfo = new CreditCardInfo { CardNumber = request.CreditCard.CardNumber, Cvv = request.CreditCard.Cvv, ExpiryDate = request.CreditCard.Expires.ToSecurePayString() }; periodicItem.Amount = request.Amount; periodicItem.PeriodicType = 4; var responseMessage = await PostAsync<PeriodicRequestMessage, PeriodicResponseMessage>(requestMessage); periodicItem = responseMessage.Periodic.PeriodicList.PeriodicItem; var response = new AddTriggeredPaymentResponse { Successful = periodicItem.Successful == "yes", ResponseCode = periodicItem.ResponseCode, ResponseText = periodicItem.ResponseText, Amount = periodicItem.Amount ?? 0, }; if (periodicItem.CreditCardInfo != null) { response.CreditCard = new CreditCardResponse { Expires = new YearMonth(periodicItem.CreditCardInfo.ExpiryDate), TruncatedCardNumber = periodicItem.CreditCardInfo.TruncatedCreditCardNumber, CardDescription = periodicItem.CreditCardInfo.CardDescription, }; } return response; }
private async Task<AddTriggeredPaymentResponse> AddTriggeredPayment(bool expectSuccess = true) { var addRequest = new AddTriggeredPaymentRequest { Amount = PaymentAmount, ClientId = ClientId, CreditCard = new CreditCardRequest { CardNumber = CardNumber, Expires = Expires, Cvv = Ccv, } }; try { var addResponse = await Client.AddTriggeredPaymentAsync(addRequest); if (!addResponse.Successful && addResponse.ResponseCode == "346") { await DeleteTriggeredPayment(); addResponse = await Client.AddTriggeredPaymentAsync(addRequest); } Assert.AreEqual(expectSuccess, addResponse.Successful); return addResponse; } catch { LogMessages(); throw; } }