Esempio n. 1
0
        /// <summary>
        /// Creates a payment by first processing payment through the acquiring bank and then storing the
        /// output result for the payment in the payments database.
        /// </summary>
        /// <param name="payment">The payment.</param>
        /// <returns></returns>
        public async Task <Payment> CreatePayment(Payment payment)
        {
            //get bank to process payment
            PaymentProcessResult bankProcessedResult = await bankRepository.ProcessPayment(payment);

            //we should store succesfull and failed payments in the database for auditing purposes
            Payment paymentResult = await paymentRepository.AddPaymentToDatabase(bankProcessedResult.Payment);

            //if successful bank process store all details for payment in database
            if (bankProcessedResult.PaymentStatus == PaymentStatus.Success)
            {
                //can manipulate result here if we want before sending back to the controller
                return(paymentResult);
            }
            //if we could not process the payment we return null
            return(null);
        }