예제 #1
0
        public void Handle(ReleaseRemainingEvent ev)
        {
            _order     = ev.PurchaseOrder;
            _orderForm = _order.GetFirstForm();
            var market = _marketService.GetMarket(_order.MarketId);

            var previousPayment =
                _orderForm.Payments.FirstOrDefault(x => x.IsKlarnaPayment());

            if (previousPayment == null)
            {
                return;
            }

            var payment = _order.CreatePayment(_orderGroupFactory);

            payment.PaymentType       = previousPayment.PaymentType;
            payment.PaymentMethodId   = previousPayment.PaymentMethodId;
            payment.PaymentMethodName = previousPayment.PaymentMethodName;

            var remainingAmount = _orderForm
                                  .Shipments
                                  .Where(s => s.OrderShipmentStatus != OrderShipmentStatus.Shipped)
                                  .Sum(x => x.GetShippingItemsTotal(_order.Currency).Amount + x.GetShippingCost(market, _order.Currency).Amount);

            payment.Amount          = remainingAmount;
            payment.Status          = PaymentStatus.Pending.ToString();
            payment.TransactionType = KlarnaAdditionalTransactionType.ReleaseRemainingAuthorization.ToString();

            _order.AddPayment(payment);

            _paymentProcessor.ProcessPayment(_order, payment, _order.GetFirstShipment());
        }
예제 #2
0
        public void Handle(OrderCancelledEvent ev)
        {
            _order     = ev.PurchaseOrder;
            _orderForm = _order.GetFirstForm();

            if (AlreadyVoided())
            {
                return;
            }

            var previousPayment = _orderForm.Payments.FirstOrDefault(x => x.IsKlarnaPayment());

            if (previousPayment == null)
            {
                return;
            }

            var voidPayment = _order.CreatePayment(_orderGroupFactory);

            voidPayment.PaymentType       = previousPayment.PaymentType;
            voidPayment.PaymentMethodId   = previousPayment.PaymentMethodId;
            voidPayment.PaymentMethodName = previousPayment.PaymentMethodName;
            voidPayment.Amount            = previousPayment.Amount;
            voidPayment.Status            = PaymentStatus.Pending.ToString();
            voidPayment.TransactionType   = TransactionType.Void.ToString();

            _order.AddPayment(voidPayment);

            _paymentProcessor.ProcessPayment(_order, voidPayment, _order.GetFirstShipment());
        }