Пример #1
0
        private void AddPaymentToOrder(ICart cart, Guid selectedPaymentGuid)
        {
            if (cart.GetFirstForm().Payments.Any())
            {
                // should maybe clean up in the cart here
            }

            var selectedPaymentMethod =
                PaymentManager.GetPaymentMethod(selectedPaymentGuid).PaymentMethod.First();

            var payment = _orderGroupFactory.CreatePayment(cart);

            // check if str "soliciting" still works
            payment.PaymentMethodId = selectedPaymentMethod.PaymentMethodId;
            //payment.PaymentType = PaymentType.Other;
            payment.PaymentMethodName = selectedPaymentMethod.Name;

            // check this thing with "classname"/PaymentType as string

            // usless - crash, doesn't support "Serializable"
            //var type = PaymentTransactionTypeManager.GetPaymentTransactionType((Payment)payment);

            // this one... but not really useful
            var className = selectedPaymentMethod.ClassName;

            // it's a string (as we see it in "Adv" when creating options & methods)

            // ...we also have - cart.GetTotal(_orderGroupCalculator)
            payment.Amount = _orderGroupCalculator.GetTotal(cart).Amount; // need a debug here

            cart.AddPayment(payment);
            // could add payment.BillingAddress = theAddress ... if we had it here
        }
Пример #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);
        }
Пример #3
0
        private OrderSearchBlockViewModel CreateViewModel(OrderSearchBlock currentBlock, OrderFilter filter)
        {
            var purchaseOrders = OrderContext.Current.LoadByCustomerId <PurchaseOrder>(PrincipalInfo.CurrentPrincipal.GetContactId())
                                 .OrderByDescending(x => x.Created)
                                 .ToList();

            var viewModel = new OrderSearchBlockViewModel(currentBlock)
            {
                CurrentCustomer = _customerService.GetCurrentContact(),
                Filter          = filter
            };

            foreach (var purchaseOrder in purchaseOrders)
            {
                //Assume there is only one form per purchase.
                var form           = purchaseOrder.GetFirstForm();
                var billingAddress = form.Payments.FirstOrDefault() != null?form.Payments.First().BillingAddress : new OrderAddress();

                var orderViewModel = new OrderViewModel
                {
                    PurchaseOrder = purchaseOrder,
                    Items         = form.GetAllLineItems().Select(lineItem => new OrderHistoryItemViewModel
                    {
                        LineItem = lineItem,
                    }).GroupBy(x => x.LineItem.Code).Select(group => group.First()),
                    BillingAddress    = _addressBookService.ConvertToModel(billingAddress),
                    ShippingAddresses = new List <AddressModel>()
                };

                foreach (var orderAddress in form.Shipments.Select(s => s.ShippingAddress))
                {
                    var shippingAddress = _addressBookService.ConvertToModel(orderAddress);
                    orderViewModel.ShippingAddresses.Add(shippingAddress);
                    orderViewModel.OrderGroupId = purchaseOrder.OrderGroupId;
                }

                orderViewModel.OrderTotal    = _orderGroupCalculator.GetTotal(purchaseOrder);
                orderViewModel.OrderPayments = form.Payments.ToList();

                if (FilterOrder(filter, orderViewModel))
                {
                    viewModel.Orders.Add(orderViewModel);
                }
            }

            return(viewModel);
        }
Пример #4
0
        public ActionResult SimulatePurchase(PaymentDemoViewModel viewModel)
        {
            var cart = _orderRepository.LoadOrCreateCart <ICart>(CustomerContext.Current.CurrentContactId, "Default");

            cart.GetFirstShipment().ShippingMethodId = viewModel.SelectedShippingMethodId;

            var primaryPayment = _orderGroupFactory.CreatePayment(cart);

            primaryPayment.PaymentMethodId   = viewModel.SelectedPaymentId;
            primaryPayment.Amount            = _orderGroupCalculator.GetTotal(cart).Amount;
            primaryPayment.PaymentMethodName = PaymentManager.GetPaymentMethod(viewModel.SelectedPaymentId).PaymentMethod[0].Name;

            if (viewModel.UseGiftCard)
            {
                var giftMethod  = PaymentManager.GetPaymentMethodBySystemName("GiftCard", ContentLanguage.PreferredCulture.Name);
                var giftPayment = _orderGroupFactory.CreatePayment(cart);
                giftPayment.PaymentMethodId   = giftMethod.PaymentMethod[0].PaymentMethodId;
                giftPayment.Amount            = viewModel.GiftCardDebitAmt;
                giftPayment.ValidationCode    = viewModel.RedemtionCode;
                giftPayment.PaymentMethodName = giftMethod.PaymentMethod[0].Name;

                PaymentProcessingResult giftPayResult = _paymentProcessor.ProcessPayment(cart, giftPayment, cart.GetFirstShipment());
                if (giftPayResult.IsSuccessful)
                {
                    primaryPayment.Amount -= giftPayment.Amount;
                    cart.AddPayment(giftPayment);
                }
                viewModel.GiftInfoMessage = giftPayResult.Message;
            }

            PaymentProcessingResult payResult = _paymentProcessor.ProcessPayment(cart, primaryPayment, cart.GetFirstShipment());

            if (payResult.IsSuccessful)
            {
                cart.AddPayment(primaryPayment);
                _orderRepository.SaveAsPurchaseOrder(cart);
                _orderRepository.Delete(cart.OrderLink);
            }
            viewModel.MessageOutput = payResult.Message;

            InitializeModel(viewModel);

            return(View("Index", viewModel));
        }
Пример #5
0
        public DoCaptureResponseType CapturePayment(IPayment payment, IOrderGroup orderGroup, out string errorMessage)
        {
            var po            = (IPurchaseOrder)orderGroup;
            var captureAmount = payment.Amount;
            var currency      = _countryService.GetCurrencyCode(payment, orderGroup.Currency);

            var captureRequest = new DoCaptureRequestType
            {
                AuthorizationID = payment.TransactionID,
                Amount          = captureAmount.ToPayPalAmount(currency)
            };

            // original transactionID (which PayPal gave us when DoExpressCheckoutPayment, DoDirectPayment, or CheckOut)
            // if refund with Partial, we have to set the Amount

            captureRequest.CompleteType = payment.Amount >= _orderGroupCalculator.GetTotal(po).Amount
                ? CompleteCodeType.COMPLETE
                : CompleteCodeType.NOTCOMPLETE;

            captureRequest.InvoiceID = po.OrderNumber;

            captureRequest.Note = string.Format("[{2}-{3}] captured {0}{1} for [PurchaseOrder-{4}]",
                                                captureAmount, currency,
                                                payment.PaymentMethodName, payment.TransactionID,
                                                po.OrderNumber
                                                );

            var caller       = GetPayPalAPICallerServices();
            var doCaptureReq = new DoCaptureReq
            {
                DoCaptureRequest = captureRequest
            };

            var captureResponse = caller.DoCapture(doCaptureReq);

            errorMessage = captureResponse.CheckErrors();

            return(captureResponse);
        }
Пример #6
0
        private void AddPaymentToOrder(ICart cart, Guid selectedPaymentGuid)
        {
            if (cart.GetFirstForm().Payments.Any())
            {
                // should maybe clean up in the cart here
            }

            var selectedPaymentMethod =
                PaymentManager.GetPaymentMethod(selectedPaymentGuid).PaymentMethod.First();

            var payment = _orderGroupFactory.CreatePayment(cart);

            payment.PaymentMethodId   = selectedPaymentMethod.PaymentMethodId;
            payment.PaymentType       = PaymentType.Other;
            payment.PaymentMethodName = selectedPaymentMethod.Name; // check if str "soliciting" still works

            // ...we also have - cart.GetTotal(_orderGroupCalculator)
            payment.Amount = _orderGroupCalculator.GetTotal(cart).Amount; // need a debug here

            cart.AddPayment(payment);
            // could add payment.BillingAddress = theAddress ... if we had it here
        }
Пример #7
0
        private IHttpActionResult Finalize(ICart cart)
        {
            cart.ApplyDiscounts();
            var total = _orderGroupCalculator.GetTotal(cart);
            var vippsPaymentMethodDto = PaymentHelper.GetVippsPaymentMethodDto().PaymentMethod.FirstOrDefault();

            if (vippsPaymentMethodDto == null)
            {
                _logger.Warning("No payment method is setup for vipps");
                return(GetUnsuccessfulResult("No payment method is setup for vipps"));
            }

            cart.GetFirstForm().Payments.Clear();
            var payment = PaymentHelper.CreateVippsPayment(cart, total, vippsPaymentMethodDto.PaymentMethodId);

            cart.AddPayment(payment);

            _orderRepository.Save(cart);

            try
            {
                var paymentProcessingResults = cart.ProcessPayments().ToArray();
                var successfulResult         = paymentProcessingResults.FirstOrDefault(x => x.IsSuccessful && !string.IsNullOrEmpty(x.RedirectUrl));

                if (successfulResult != null)
                {
                    return(GetSuccessfulResult(paymentProcessingResults.FirstOrDefault(x => x.IsSuccessful) ?? paymentProcessingResults.FirstOrDefault()));
                }

                return(GetUnsuccessfulResult(paymentProcessingResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message))?.Message));
            }

            catch (Exception ex)
            {
                _logger.Error($"{ex.Message} {ex.StackTrace}");
                return(GetUnsuccessfulResult(ex.Message));
            }
        }