public void Test_SubmitRequest_Payment_serialization() { // Prepare SubmitRequestPayment payment = new SubmitRequestPayment { PaymentMethodName = "CARD", PaymentMethodId = "3", PaymentAmount = 10m, Date = DateTime.UtcNow, Paycode = "CARD", PaymentType = "SALE", CurrencyCode = "TWD", AppliedDate = DateTime.UtcNow, ApprovalNumber = "070070", PaymentReceived = 10m, CreditCard = new OrderSubmitPaymentCreditCard { CardExpiryDate = DateTime.UtcNow.AddYears(1), CardHolderName = "CARD HOLDER", CardNumber = "4A37991092121000", CardType = "VI", TrxApprovalNumber = "59b2996d9f20435a9773aadfbda868" // 30 digits } }; // Perform string result = JsonConvert.SerializeObject(payment); // Post-validate Assert.Equal("{\"PaymentMethodName\":\"CARD\",\"PaymentMethodId\":\"3\",\"PaymentAmount\":\"10\",\"PaymentDate\":\"2020-11-30T10:12:56\",\"Paycode\":\"CARD\",\"PaymentType\":\"SALE\",\"CurrencyCode\":\"TWD\",\"AppliedDate\":\"2020-11-30T10:12:56\",\"ApprovalNumber\":\"070070\",\"PaymentReceived\":\"10\",\"CreditCard\":{\"CardNumber\":\"4A37991092121000\",\"TrxApprovalNumber\":\"59b2996d9f20435a9773aadfbda868\",\"CardType\":\"VI\",\"CardExpiryDate\":\"2021-11-30T10:12:56\",\"CardHolderName\":\"CARD HOLDER\"}}", result); }
public SubmitRequestBuilder AddPayment(Action <SubmitRequestPayment> setupPayment) { SubmitRequestPayment payment = setupPayment?.CreateTargetAndInvoke(); #region Validation StringBuilder issues = new StringBuilder(); if (string.IsNullOrWhiteSpace(payment.PaymentMethodName)) { issues.AppendLine($"Payment method name is mandatory"); } // payment.PaymentMethodId // is optional if (payment.PaymentAmount <= 0m) { issues.AppendLine($"Payment amount must be non-negative"); } if (payment.Date == DateTime.MinValue) { issues.AppendLine($"Payment date must be specified"); } if (string.IsNullOrWhiteSpace(payment.Paycode)) { issues.AppendLine($"Paycode is mandatory"); } if (string.IsNullOrWhiteSpace(payment.PaymentType)) { issues.AppendLine($"Payment type is mandatory"); } if (string.IsNullOrWhiteSpace(payment.CurrencyCode)) { issues.AppendLine($"Currency code is mandatory"); } if (payment.AppliedDate == DateTime.MinValue) { issues.AppendLine($"Applied date must be specified"); } // ApprovalNumber is optional (e.g. cash payment) if (payment.PaymentReceived <= 0m) { issues.AppendLine($"Payment received must be non-negative"); } if ((payment.PaymentMethodName ?? string.Empty).ToLower().Contains("card")) { if (payment.CreditCard == null) { issues.AppendLine($"Credit card block is mandatory"); } else { if (string.IsNullOrWhiteSpace(payment.CreditCard.CardNumber)) { issues.AppendLine($"Credit card number is mandatory"); } if (string.IsNullOrWhiteSpace(payment.CreditCard.CardHolderName)) { issues.AppendLine($"Card holder name is mandatory"); } if (string.IsNullOrWhiteSpace(payment.CreditCard.TrxApprovalNumber)) { issues.AppendLine($"Transaction approval number is mandatory"); } if (string.IsNullOrWhiteSpace(payment.CreditCard.CardType)) { issues.AppendLine($"Card type is mandatory"); } if (payment.CreditCard.CardExpiryDate <= DateTime.Now.AddDays(1)) { issues.AppendLine($"Invalid card expiration date"); } } } else { payment.CreditCard = null; } if (issues.Length > 0) { throw new ArgumentException(issues.ToString()); } #endregion _request.Payment = payment; return(this); }