Пример #1
0
        public BookingPayment GetPayment()
        {
            var payment = new BookingPayment();
            payment.BookingId = _booking.Id;
            payment.AssociationUserId = UsePrimaryPassenger && _booking.PrimaryPassengerId != null ? _booking.PrimaryPassengerId.Value : _booking.CreatorId.Value;

            if (SelectedTabIndex == 0) //by credit card
            {
                if (CreditCardSelectedProcessIndex == 0)
                {
                    var card = AddCreditCardViewModel.CreditCard;

                    card.Validate();
                    if (!AddCreditCardViewModel.SaveToMyBilling && !AddCreditCardViewModel.MakeDefaultBilling)
                        card.RemoveErrors("Nickname");

                    if (card.HasErrors)
                    {
                        ShowErrors(card.Errors);
                        return null;
                    }

                    payment.CreditCard = new BookingPaymentCreditCard()
                    {
                        TypeId = card.TypeId,
                        Holder = card.Holder,
                        ExpiryMonth = card.ExpiryMonth,
                        ExpiryYear = card.ExpiryYear,
                        Number = card.Number,
                        CVC = card.CVC,
                        SavedCreditCardNickname = (AddCreditCardViewModel.SaveToMyBilling || AddCreditCardViewModel.MakeDefaultBilling) ? card.Nickname : null,
                        SavedCrediCardIsDefaultBilling = AddCreditCardViewModel.MakeDefaultBilling
                    };
                }
                else if (CreditCardSelectedProcessIndex == 1)
                {
                    SelectCreditCardViewModel.RemoveErrors("SelectedCreditCard");
                    if (SelectCreditCardViewModel.SelectedCreditCard == null)
                    {
                        SelectCreditCardViewModel.AddError("SelectedCreditCard", "Select card.");
                        return null;
                    }

                    payment.CreditCard = new BookingPaymentCreditCard()
                    {
                        SavedCreditCardId = SelectCreditCardViewModel.SelectedCreditCard.Id,
                        SavedCrediCardIsDefaultBilling = SelectCreditCardViewModel.MakeDefaultBilling
                    };
                }
            }
            else if (SelectedTabIndex == 1) //by billing account
            {
                if (BillingAccountSelectedProcessIndex == 0)
                {
                    var billingAccount = AddBillingAccountViewModel.SavedBillingAccount;

                    billingAccount.Validate();
                    if (!AddCreditCardViewModel.SaveToMyBilling && !AddCreditCardViewModel.MakeDefaultBilling)
                        billingAccount.RemoveErrors("Name");

                    if (billingAccount.HasErrors)
                    {
                        ShowErrors(billingAccount.Errors);
                        return null;
                    }

                    payment.BillingAccount = new BookingPaymentBillingAccount()
                    {
                        ChargeBackId = billingAccount.BillingAccountId,
                        BillingCode = billingAccount.BillingCode,
                        Email = billingAccount.Email,
                        ContactPerson = billingAccount.ContactPerson,
                        ContactNumber = billingAccount.ContactNumber,
                        SavedBillingAccountNickname = (AddCreditCardViewModel.SaveToMyBilling || AddCreditCardViewModel.MakeDefaultBilling) ? billingAccount.Name : null,
                        SavedBillingAccountIsDefaultBilling = AddCreditCardViewModel.MakeDefaultBilling
                    };
                }
                else if (BillingAccountSelectedProcessIndex == 1)
                {
                    SelectBillingAccountViewModel.RemoveErrors("SelectedBillingAccount");
                    if (SelectBillingAccountViewModel.SelectedBillingAccount == null)
                    {
                        SelectBillingAccountViewModel.AddError("SelectedBillingAccount", "Select billing account.");
                        return null;
                    }

                    payment.BillingAccount = new BookingPaymentBillingAccount()
                    {
                        SavedBillingAccountId = SelectBillingAccountViewModel.SelectedBillingAccount.Id,
                        SavedBillingAccountIsDefaultBilling = SelectBillingAccountViewModel.MakeDefaultBilling
                    };
                }
            }

            return payment;
        }
Пример #2
0
     private void FixupPaymentInfo(BookingPayment previousValue)
     {
         // This is the principal end in an association that performs cascade deletes.
         // Update the event listener to refer to the new dependent.
         if (previousValue != null)
         {
             ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete;
         }
 
         if (PaymentInfo != null)
         {
             ChangeTracker.ObjectStateChanging += PaymentInfo.HandleCascadeDelete;
         }
 
         if (IsDeserializing)
         {
             return;
         }
 
         if (PaymentInfo != null)
         {
             PaymentInfo.BookingId = Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("PaymentInfo")
                 && (ChangeTracker.OriginalValues["PaymentInfo"] == PaymentInfo))
             {
                 ChangeTracker.OriginalValues.Remove("PaymentInfo");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("PaymentInfo", previousValue);
                 // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed.
                 // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted.
                 if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added)
                 {
                     previousValue.MarkAsDeleted();
                 }
             }
             if (PaymentInfo != null && !PaymentInfo.ChangeTracker.ChangeTrackingEnabled)
             {
                 PaymentInfo.StartTracking();
             }
         }
     }
Пример #3
0
        public SaveBookingPaymentInfoResponse SaveBookingPaymentInfo(int bookingId, BookingPayment info)
        {
            var response = new SaveBookingPaymentInfoResponse();

            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBookingWithChargeInfo(db, bookingId);
                    response.ChargeInfo = booking.ChargeInfo;

                    var payment = db.BookingPayments.IncludeAll("CreditCard", "CreditCard.Info", "CreditCard.Address", "BillingAccount", "Items").FirstOrDefault(b => b.BookingId == bookingId);
                    if (payment == null)
                        payment = new BookingPayment() { BookingId = bookingId };

                    payment.AssociationUserId = info.AssociationUserId;
                    db.BookingPayments.ApplyChanges(payment);
                    db.SaveChanges();

                    if (info.CreditCard != null)
                    {
                        if (payment.BillingAccount != null)
                            db.BookingPaymentBillingAccounts.DeleteObject(payment.BillingAccount);

                        if (payment.CreditCard == null)
                            payment.CreditCard = new BookingPaymentCreditCard() { CreditCardId = bookingId };

                        if (info.CreditCard.SavedCreditCardId != 0) //saved card
                        {
                            var savedCreditCard = db.AssociationUserCreditCards.IncludeAll("Info").FirstOrDefault(cc => cc.Id == info.CreditCard.SavedCreditCardId);

                            payment.CreditCard.TypeId = savedCreditCard.TypeId;
                            payment.CreditCard.Holder = savedCreditCard.Holder;
                            payment.CreditCard.ExpiryMonth = savedCreditCard.ExpiryMonth;
                            payment.CreditCard.ExpiryYear = savedCreditCard.ExpiryYear;
                            payment.CreditCard.SavedCreditCardId = info.CreditCard.SavedCreditCardId;
                            payment.CreditCard.SavedCreditCardNickname = null;
                            payment.CreditCard.SavedCrediCardIsDefaultBilling = info.CreditCard.SavedCrediCardIsDefaultBilling;

                            db.BookingPaymentCreditCards.ApplyChanges(payment.CreditCard);
                            db.SaveChanges();

                            if (payment.CreditCard.Info == null)
                                payment.CreditCard.Info = new BookingPaymentCreditCardInfo();

                            payment.CreditCard.Info.CardId = payment.CreditCard.CreditCardId;
                            payment.CreditCard.Info.Number = savedCreditCard.Info.Number;
                            payment.CreditCard.Info.CVC = savedCreditCard.Info.CVC;

                            db.BookingPaymentCreditCardInfoes.ApplyChanges(payment.CreditCard.Info);
                            db.SaveChanges();
                        }
                        else  //new credit card
                        {
                            payment.CreditCard.TypeId = info.CreditCard.TypeId;
                            payment.CreditCard.Holder = info.CreditCard.Holder;
                            payment.CreditCard.ExpiryMonth = info.CreditCard.ExpiryMonth;
                            payment.CreditCard.ExpiryYear = info.CreditCard.ExpiryYear;
                            payment.CreditCard.SavedCreditCardId = info.CreditCard.SavedCreditCardId;
                            payment.CreditCard.SavedCreditCardNickname = info.CreditCard.SavedCreditCardNickname;
                            payment.CreditCard.SavedCrediCardIsDefaultBilling = info.CreditCard.SavedCrediCardIsDefaultBilling;

                            db.BookingPaymentCreditCards.ApplyChanges(payment.CreditCard);
                            db.SaveChanges();

                            if (payment.CreditCard.Info == null)
                                payment.CreditCard.Info = new BookingPaymentCreditCardInfo();

                            payment.CreditCard.Info.CardId = payment.CreditCard.CreditCardId;
                            payment.CreditCard.Info.Number = info.CreditCard.Number;
                            payment.CreditCard.Info.CVC = info.CreditCard.CVC;

                            db.BookingPaymentCreditCardInfoes.ApplyChanges(payment.CreditCard.Info);
                            db.SaveChanges();
                        }

                        //remove old transactions
                        db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item));
                        db.BookingTransactionBillingAccounts.Where(p => p.BillingAccountId == bookingId).ForEach(item => db.BookingTransactionBillingAccounts.DeleteObject(item));

                        //create transaction
                        decimal amount = booking.ChargeInfo.Amount;
                        bool existedPaidTransactions = booking.TransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime != null).HasItems();
                        if (booking.OriginalId != 0 && existedPaidTransactions)
                        {
                            var originalBooking = GetBookingWithChargeInfo(db, booking.OriginalId);
                            amount = amount - originalBooking.ChargeInfo.Amount;
                        }

                        var transactionCreditCard = new BookingTransactionCreditCard();
                        transactionCreditCard.BookingId = booking.Id;
                        transactionCreditCard.TypeId = payment.CreditCard.TypeId;
                        transactionCreditCard.Holder = payment.CreditCard.Holder;
                        transactionCreditCard.ExpiryMonth = payment.CreditCard.ExpiryMonth;
                        transactionCreditCard.ExpiryYear = payment.CreditCard.ExpiryYear;
                        transactionCreditCard.PaymentApi = null;
                        transactionCreditCard.OrderType = OrderType.Capture;
                        transactionCreditCard.OrderNumber = null;
                        transactionCreditCard.OrderDateTime = null;
                        transactionCreditCard.OrderAmount = amount;
                        db.BookingTransactionCreditCards.ApplyChanges(transactionCreditCard);
                        db.SaveChanges();

                        var transactionCreditCardInfo = new BookingTransactionCreditCardInfo()
                        {
                            CreditCardId = transactionCreditCard.Id,
                            Number = payment.CreditCard.Info.Number,
                            CVC = payment.CreditCard.Info.CVC

                        };
                        db.BookingTransactionCreditCardInfoes.ApplyChanges(transactionCreditCardInfo);
                        db.SaveChanges();

                        transactionCreditCard.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(transactionCreditCardInfo.Number);
                        response.NewTransactionCreditCard = transactionCreditCard;
                    }
                    else if (info.BillingAccount != null)
                    {
                        if (payment.CreditCard != null)
                            db.BookingPaymentCreditCards.DeleteObject(payment.CreditCard);

                        if (payment.BillingAccount == null)
                            payment.BillingAccount = new BookingPaymentBillingAccount() { BillingAccountId = bookingId };

                        if (info.BillingAccount.SavedBillingAccountId != 0) //saved Billing Account
                        {
                            var savedBillingAccount = db.AssociationUserBillingAccounts.FirstOrDefault(cc => cc.Id == info.BillingAccount.SavedBillingAccountId);

                            payment.BillingAccount.ChargeBackId = savedBillingAccount.BillingAccountId;
                            payment.BillingAccount.BillingCode = savedBillingAccount.BillingCode;
                            payment.BillingAccount.Email = savedBillingAccount.Email;
                            payment.BillingAccount.ContactPerson = savedBillingAccount.ContactPerson;
                            payment.BillingAccount.ContactNumber = savedBillingAccount.ContactNumber;

                            payment.BillingAccount.SavedBillingAccountNickname = null;
                        }
                        else  //new Billing Account
                        {
                            payment.BillingAccount.ChargeBackId = info.BillingAccount.ChargeBackId;
                            payment.BillingAccount.BillingCode = info.BillingAccount.BillingCode;
                            payment.BillingAccount.Email = info.BillingAccount.Email;
                            payment.BillingAccount.ContactPerson = info.BillingAccount.ContactPerson;
                            payment.BillingAccount.ContactNumber = info.BillingAccount.ContactNumber;

                            payment.BillingAccount.SavedBillingAccountNickname = info.BillingAccount.SavedBillingAccountNickname;
                        }

                        payment.BillingAccount.SavedBillingAccountId = info.BillingAccount.SavedBillingAccountId;
                        payment.BillingAccount.SavedBillingAccountIsDefaultBilling = info.BillingAccount.SavedBillingAccountIsDefaultBilling;

                        db.BookingPaymentBillingAccounts.ApplyChanges(payment.BillingAccount);
                        db.SaveChanges();

                        //remove old transactions
                        db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item));

                        //create transaction
                        var transactionBillingAccount = db.BookingTransactionBillingAccounts.SingleOrDefault(t => t.BillingAccountId == bookingId);
                        if (transactionBillingAccount == null)
                            transactionBillingAccount = new BookingTransactionBillingAccount() { BillingAccountId = bookingId };
                        transactionBillingAccount.ChargeBackId = payment.BillingAccount.ChargeBackId;
                        transactionBillingAccount.BillingCode = payment.BillingAccount.BillingCode;
                        transactionBillingAccount.Email = payment.BillingAccount.Email;
                        transactionBillingAccount.ContactPerson = payment.BillingAccount.ContactPerson;
                        transactionBillingAccount.ContactNumber = payment.BillingAccount.ContactNumber;
                        db.BookingTransactionBillingAccounts.ApplyChanges(transactionBillingAccount);
                        db.SaveChanges();

                        response.NewTransactionBillingAccount = transactionBillingAccount;
                    }

                }
                using (var db = new LomsContext())
                {
                    response.PaymentInfo = db.BookingPayments.IncludeAll("CreditCard", "CreditCard.Info", "CreditCard.Address", "BillingAccount", "BillingAccount.ChargeBack", "BillingAccount.ChargeBack.Country", "Items").FirstOrDefault(b => b.BookingId == bookingId);
                    if (response.PaymentInfo.CreditCard != null)
                    {
                        if (response.PaymentInfo.CreditCard.Info == null)
                            response.PaymentInfo.CreditCard.Info = db.BookingPaymentCreditCardInfoes.SingleOrDefault(i => i.CardId == bookingId);

                        response.PaymentInfo.CreditCard.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(response.PaymentInfo.CreditCard.Info.Number);
                        response.PaymentInfo.CreditCard.Info = null;
                        response.PaymentInfo.CreditCard.AcceptChanges();
                    }

                    response.NewTransactionBillingAccount = db.BookingTransactionBillingAccounts.IncludeAll("ChargeBack", "ChargeBack.Country").SingleOrDefault(t => t.BillingAccountId == bookingId);

                    return response;
                }
            }
            catch (Exception ex)
            {
                response = new SaveBookingPaymentInfoResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Пример #4
0
     public bool Equals(BookingPayment other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.BookingId == 0 && BookingId == 0)
 			return false;
 		else
 			return other.BookingId == BookingId;
     }