Example #1
0
        public virtual async Task <CartAggregate> AddPaymentAsync(Payment payment, IEnumerable <PaymentMethod> availPaymentMethods)
        {
            EnsureCartExists();
            var validationContext = new PaymentValidationContext
            {
                Payment             = payment,
                AvailPaymentMethods = availPaymentMethods
            };
            await AbstractTypeFactory <CartPaymentValidator> .TryCreateInstance().ValidateAsync(validationContext, options => options.IncludeRuleSets(ValidationRuleSet).ThrowOnFailures());

            if (payment.Currency == null)
            {
                payment.Currency = Cart.Currency;
            }
            await RemoveExistingPaymentAsync(payment);

            if (payment.BillingAddress != null)
            {
                //Reset address key because it can equal a customer address from profile and if not do that it may cause
                //address primary key duplication error for multiple carts with the same address
                payment.BillingAddress.Key = null;
            }

            Cart.Payments.Add(payment);

            return(this);
        }
        private PaymentValidationContext BuildContext(ShopifyTransaction currentTransaction)
        {
            var output = new PaymentValidationContext();

            output.CurrentTransaction  = currentTransaction;
            output.ValidPaymentGateway = _settingsRepository.GatewayExistsInConfig(currentTransaction.ShopifyGateway);
            return(output);
        }