Ejemplo n.º 1
0
        public static IPayment CreateVippsPayment(ICart cart, decimal amount, Guid vippsPaymentMethodId)
        {
            var payment = cart.CreatePayment(_orderGroupFactory.Service);

            payment.PaymentType       = PaymentType.Other;
            payment.PaymentMethodId   = vippsPaymentMethodId;
            payment.PaymentMethodName = VippsConstants.VippsSystemKeyword;
            payment.Amount            = amount;
            payment.Status            = PaymentStatus.Pending.ToString();
            payment.TransactionType   = TransactionType.Authorization.ToString();

            return(payment);
        }
Ejemplo n.º 2
0
        public void ApplyPayment()
        {
            var paymentMethod = PaymentManager.GetPaymentMethod(Constants.PaymentMethodId).PaymentMethod.Single();
            var payment       = _cart.CreatePayment(_orderGroupFactory);

            payment.Amount            = _orderGroupCalculator.GetTotal(_cart).Amount;
            payment.PaymentMethodId   = paymentMethod.PaymentMethodId;
            payment.PaymentMethodName = paymentMethod.Name;
            payment.PaymentType       = PaymentType.Other;
            _cart.AddPayment(payment, _orderGroupFactory);
            _cart.ProcessPayments(_paymentProcessor, _orderGroupCalculator);
            _orderRepository.Save(_cart);
        }
Ejemplo n.º 3
0
        public IPurchaseOrder CreatePurchaseOrderForKlarna(string klarnaOrderId, CheckoutOrderData order, ICart cart)
        {
            var paymentRow = PaymentManager.GetPaymentMethodBySystemName(Constants.KlarnaCheckoutSystemKeyword, ContentLanguage.PreferredCulture.Name).PaymentMethod.FirstOrDefault();

            var payment = cart.CreatePayment(_orderGroupFactory);

            payment.PaymentType       = PaymentType.Other;
            payment.PaymentMethodId   = paymentRow.PaymentMethodId;
            payment.PaymentMethodName = Constants.KlarnaCheckoutSystemKeyword;
            payment.Amount            = cart.GetTotal(_orderGroupCalculator).Amount;
            payment.Status            = PaymentStatus.Pending.ToString();
            payment.TransactionType   = TransactionType.Authorization.ToString();

            cart.AddPayment(payment, _orderGroupFactory);

            var billingAddress = new AddressModel
            {
                Name               = $"{order.BillingAddress.StreetAddress}{order.BillingAddress.StreetAddress2}{order.BillingAddress.City}",
                FirstName          = order.BillingAddress.GivenName,
                LastName           = order.BillingAddress.FamilyName,
                Email              = order.BillingAddress.Email,
                DaytimePhoneNumber = order.BillingAddress.Phone,
                Line1              = order.BillingAddress.StreetAddress,
                Line2              = order.BillingAddress.StreetAddress2,
                PostalCode         = order.BillingAddress.PostalCode,
                City               = order.BillingAddress.City,
                CountryName        = order.BillingAddress.Country
            };

            payment.BillingAddress = _addressBookService.ConvertToAddress(billingAddress, cart);

            cart.ProcessPayments(_paymentProcessor, _orderGroupCalculator);

            var totalProcessedAmount = cart.GetFirstForm().Payments.Where(x => x.Status.Equals(PaymentStatus.Processed.ToString())).Sum(x => x.Amount);

            if (totalProcessedAmount != cart.GetTotal(_orderGroupCalculator).Amount)
            {
                throw new InvalidOperationException("Wrong amount");
            }

            if (payment.HasFraudStatus(FraudStatus.PENDING))
            {
                payment.Status = PaymentStatus.Pending.ToString();
            }

            var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
            var purchaseOrder  = _orderRepository.Load <IPurchaseOrder>(orderReference.OrderGroupId);

            _orderRepository.Delete(cart.OrderLink);

            if (purchaseOrder == null)
            {
                _klarnaCheckoutService.CancelOrder(cart);

                return(null);
            }
            else
            {
                _klarnaCheckoutService.Complete(purchaseOrder);
                purchaseOrder.Properties[Klarna.Common.Constants.KlarnaOrderIdField] = klarnaOrderId;

                _orderRepository.Save(purchaseOrder);
                return(purchaseOrder);
            }
        }