public ActionResult Edit(long?id)
        {
            if (!WalletProvider.WalletsAreEnabled())
            {
                NoticeProvider.PushNotice(
                    message: AppLogic.GetString("checkout.wallet.disabled"),
                    type: NoticeType.Warning);

                return(RedirectToAction(ActionNames.Index, ControllerNames.Account));
            }

            var customer = HttpContext.GetCustomer();

            if (!CustomerHasAvailableAddresses(customer))
            {
                NoticeProvider.PushNotice(
                    message: AppLogic.GetString("account.aspx.92"),
                    type: NoticeType.Warning);

                return(RedirectToAction(ActionNames.Index, ControllerNames.Account));
            }

            var profileId = WalletProvider.GetProfileId(customer);

            if (profileId <= 0)
            {
                return(View(BuildWalletEditViewModel(customer)));
            }

            if (!id.HasValue)
            {
                return(View(BuildWalletEditViewModel(customer)));
            }

            var paymentProfile = WalletProvider.GetPaymentProfile(customer, id.Value);

            if (paymentProfile == null)
            {
                return(View(BuildWalletEditViewModel(customer)));
            }

            return(View(BuildWalletEditViewModel(customer, new WalletPaymentType
            {
                PaymentProfileId = id.Value,
                BillingAddressId = paymentProfile.AddressId,
                CardNumber = paymentProfile.CreditCardNumberMasked,
                ExpirationMonth = paymentProfile.ExpirationMonth,
                ExpirationYear = paymentProfile.ExpirationYear
            })));
        }
Exemple #2
0
        public ActionResult Edit(long?id)
        {
            if (!WalletProvider.WalletsAreEnabled())
            {
                NoticeProvider.PushNotice(
                    message: "Wallets are not enabled.",
                    type: NoticeType.Warning);

                return(RedirectToAction(ActionNames.Index, ControllerNames.Account));
            }

            var customer = HttpContext.GetCustomer();

            if (!CustomerHasAvailableAddresses(customer))
            {
                NoticeProvider.PushNotice(
                    message: "You must have a billing address configured before you can add a credit card to your account.",
                    type: NoticeType.Warning);

                return(RedirectToAction(ActionNames.Index, ControllerNames.Account));
            }

            var profileId = WalletProvider.GetProfileId(customer);

            if (profileId <= 0)
            {
                return(View(BuildWalletEditViewModel(customer)));
            }

            if (!id.HasValue)
            {
                return(View(BuildWalletEditViewModel(customer)));
            }

            var paymentProfile = WalletProvider.GetPaymentProfile(customer, id.Value);

            if (paymentProfile == null)
            {
                return(View(BuildWalletEditViewModel(customer)));
            }

            return(View(BuildWalletEditViewModel(customer, new WalletPaymentType
            {
                PaymentProfileId = id.Value,
                BillingAddressId = paymentProfile.AddressId,
                CardNumber = paymentProfile.CreditCardNumberMasked,
                ExpirationMonth = paymentProfile.ExpirationMonth,
                ExpirationYear = paymentProfile.ExpirationYear
            })));
        }