예제 #1
0
        public bool ProcessPayment(PaymentEditModel model)
        {
            var customer         = _customerRepository.GetCustomer(model.CustomerId);
            var eventCustomer    = _eventCustomerRepository.Get(model.EventId, model.CustomerId);
            var instruments      = new List <PaymentInstrumentEditModel>();
            var paymentEditModel = new PaymentModel();

            if (model.GcPayment != null && !string.IsNullOrEmpty(model.GcPayment.ClaimCode))
            {
                var giftCertificate = _giftCertificateService.GetGiftCertificatebyClaimCode(model.GcPayment.ClaimCode);

                instruments.Add(new PaymentInstrumentEditModel {
                    Amount = model.GcPayment.Amount, PaymentType = PaymentType.GiftCertificate.PersistenceLayerId, GiftCertificate = new GiftCertificatePaymentEditModel {
                        GiftCertificate = giftCertificate, GiftCertificatePayment = new GiftCertificatePayment {
                            GiftCertificateId = giftCertificate.Id, Amount = model.GcPayment.Amount
                        }
                    }
                });
            }
            if (model.Payments != null)
            {
                model.Payments.BillingAddress = model.BillingAddress;
                CreatePaymentModels(model);
                instruments.Add(model.Payments);
            }

            paymentEditModel.Amount                  = model.UnPaidAmount;
            paymentEditModel.IsModeMultiple          = false;
            paymentEditModel.PaymentFlow             = PaymentFlow.In;
            paymentEditModel.Payments                = instruments;
            paymentEditModel.ExistingBillingAddress  = model.BillingAddress;
            paymentEditModel.ExistingShippingAddress = model.BillingAddress;

            _eventSchedulerService.ProcessPayment(paymentEditModel, eventCustomer.Id, model.CustomerId, true);

            try
            {
                _order = _orderRepository.GetOrder(model.CustomerId, model.EventId);

                if (paymentEditModel.Payments != null && paymentEditModel.Payments.Any(p => p.ChargeCard != null || p.ECheck != null || p.GiftCertificate != null || p.Check != null || p.PaymentType == PaymentType.Cash.PersistenceLayerId))
                {
                    var paymentId = _paymentController.SavePayment(paymentEditModel, model.CustomerId);
                    _orderRepository.ApplyPaymentToOrder(_order.Id, paymentId);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("Some error occured while saving payment detail", exception);
            }



            return(true);
        }
예제 #2
0
        private void CreatePaymentModels(PaymentEditModel model)
        {
            if (model == null || model.Payments == null)
            {
                return;
            }

            if (model.Payments.ChargeCard != null && model.Payments.ChargeCard.ChargeCard != null)
            {
                model.Payments.ChargeCard.ChargeCardPayment = new ChargeCardPayment
                {
                    Amount               = model.Payments.Amount,
                    ChargeCardId         = 0,
                    PaymentId            = 0,
                    DataRecorderMetaData = new DataRecorderMetaData(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, DateTime.Now, DateTime.Now)
                };
            }
            if (model.Payments.Check != null && model.Payments.Check.Check != null)
            {
                model.Payments.Check.Check.PayableTo = _settings.CompanyName;
                model.Payments.Check.Check.CheckDate = DateTime.Today.Date;
                model.Payments.Check.CheckPayment    = new CheckPayment
                {
                    Amount               = model.Payments.Amount,
                    Check                = model.Payments.Check.Check,
                    CheckId              = model.Payments.Check.Check.Id,
                    CheckStatus          = CheckPaymentStatus.Recieved,
                    DataRecorderMetaData = new DataRecorderMetaData(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, DateTime.Now, DateTime.Now),
                    PaymentId            = 0
                };
            }

            if (model.Payments.ECheck != null && model.Payments.ECheck.ECheck != null)
            {
                model.Payments.ECheck.ECheck.PayableTo = _settings.CompanyName;
                model.Payments.ECheck.ECheck.CheckDate = DateTime.Today.Date;

                model.Payments.ECheck.ECheckPayment = new ECheckPayment
                {
                    Amount               = model.Payments.Amount,
                    ECheck               = model.Payments.ECheck.ECheck,
                    ECheckId             = model.Payments.ECheck.ECheck.Id,
                    DataRecorderMetaData = new DataRecorderMetaData(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, DateTime.Now, DateTime.Now),
                    PaymentId            = 0
                };
            }
        }