Exemple #1
0
        private async Task <bool> PayCreditCardAsync(decimal price, params string[] paymentParameters)
        {
            if (paymentParameters == null)
            {
                throw new ArgumentNullException(nameof(paymentParameters));
            }
            if (price <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(price));
            }

            try
            {
                var ccNumber       = new CreditCardNumber(paymentParameters[2]);
                var expDate        = new ExpirationDate(int.Parse(paymentParameters[3]), int.Parse(paymentParameters[4]));
                var validationCode = new CardValidationCode(paymentParameters[5]);

                var creditCard = new CreditCard(paymentParameters[1] + " " + paymentParameters[0],
                                                ccNumber,
                                                expDate,
                                                validationCode);

                var paymentApi = new PaymentApi(paymentParameters[6]);

                var result = await paymentApi.CreateTransactionAsync(price, creditCard, paymentParameters[0]);

                if (result.Equals(PaymentResult.PaymentSuccessful))
                {
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(false);
        }
Exemple #2
0
 public async Task <PaymentResult> TransactionAsync(decimal amount, string description, CreditCard creditCard)
 {
     return(await _api.CreateTransactionAsync(amount, creditCard, description));
 }