Exemple #1
0
        private async Task ConfirmOrderAndGoToBookingStatus()
        {
            using (this.Services().Message.ShowProgress())
            {
                var result = await _orderWorkflowService.ConfirmOrder();

                this.Services().Analytics.LogEvent("Book");
                ParentViewModel.GotoBookingStatus(result.Order, result.OrderStatus);
            }
        }
Exemple #2
0
        private async Task ConfirmOrder()
        {
            try
            {
                var chargeTypeValidated = await _orderWorkflowService.ValidateChargeType();

                if (!chargeTypeValidated)
                {
                    this.Services().Message.ShowMessage(
                        this.Services().Localize["InvalidChargeTypeTitle"],
                        this.Services().Localize["InvalidChargeType"]);

                    return;
                }

                var canBeConfirmed = await _orderWorkflowService.GetAndObserveOrderCanBeConfirmed().Take(1).ToTask();

                if (!canBeConfirmed)
                {
                    return;
                }

                var promoConditionsValidated = await _orderWorkflowService.ValidatePromotionUseConditions();

                if (!promoConditionsValidated)
                {
                    this.Services().Message.ShowMessage(
                        this.Services().Localize["ErrorCreatingOrderTitle"],
                        this.Services().Localize["PromoMustUseCardOnFileMessage"]);

                    return;
                }

                var cardValidated = await _orderWorkflowService.ValidateCardOnFile();

                if (!cardValidated)
                {
                    PromptToAddCreditCard(false);
                    return;
                }

                var cardExpirationValidated = await _orderWorkflowService.ValidateCardExpiration();

                if (!cardExpirationValidated)
                {
                    this.Services().Message.ShowMessage(
                        this.Services().Localize["ErrorCreatingOrderTitle"],
                        this.Services().Localize["CardExpiredMessage"]);

                    return;
                }

                if (await _orderWorkflowService.ShouldWarnAboutPromoCode())
                {
                    var acceptedConditions = false;
                    await this.Services().Message.ShowMessage(
                        this.Services().Localize["WarningTitle"],
                        this.Services().Localize["PromoMustUseCardOnFileWarningMessage"],
                        this.Services().Localize["OkButtonText"],
                        () => {
                        acceptedConditions = true;
                    },
                        this.Services().Localize["Cancel"],
                        () => { },
                        this.Services().Localize["WarningPromoCodeDontShow"],
                        () => {
                        this.Services().Cache.Set("WarningPromoCodeDontShow", "yes");
                        acceptedConditions = true;
                    });

                    if (!acceptedConditions)
                    {
                        return;
                    }
                }

                _orderWorkflowService.BeginCreateOrder();

                if (await _orderWorkflowService.ShouldPromptForCreditCardConfirm())
                {
                    var localize   = this.Services().Localize;
                    var creditCard = _accountService.CurrentAccount.DefaultCreditCard;

                    var message = creditCard.Label.HasValueTrimmed()
                        ? string.Format(localize["ConfirmCreditCardOfOrder_withNickname_Message"], creditCard.Label)
                        : string.Format(localize["ConfirmCreditCardOfOrder_Message"], creditCard.CreditCardCompany, creditCard.Last4Digits, creditCard.ExpirationMonth, creditCard.ExpirationYear);

                    var isConfirm = false;
                    await this.Services().Message.ShowMessage(
                        localize["ConfirmCreditCardOfOrder_Title"],
                        message,
                        localize["YesButton"],
                        () => { isConfirm = true; },
                        localize["ConfirmCreditCardOfOrder_ChangeCreditCard"],
                        () => { isConfirm = false; });


                    if (!isConfirm)
                    {
                        ShowViewModel <CreditCardMultipleViewModel>();
                        return;
                    }
                }


                if (await _orderWorkflowService.ShouldPromptForCvv())
                {
                    var cvv = await this.Services().Message.ShowPromptDialog(
                        this.Services().Localize["CvvRequiredTitle"],
                        string.Format(this.Services().Localize["CvvRequiredMessage"], _accountService.CurrentAccount.DefaultCreditCard.Last4Digits),
                        () => { return; },
                        true);

                    // validate that it's a numeric value with 3 or 4 digits
                    var cvvSetCorrectly = _orderWorkflowService.ValidateAndSetCvv(cvv);
                    if (!cvvSetCorrectly)
                    {
                        await this.Services().Message.ShowMessage(
                            this.Services().Localize["Error_InvalidCvvTitle"],
                            this.Services().Localize["Error_InvalidCvvMessage"]);

                        return;
                    }
                }

                if (await _orderWorkflowService.ShouldGoToAccountNumberFlow())
                {
                    var hasValidAccountNumber = await _orderWorkflowService.ValidateAccountNumberAndPrepareQuestions();

                    if (!hasValidAccountNumber)
                    {
                        var accountNumber = await this.Services().Message.ShowPromptDialog(
                            this.Services().Localize["AccountPaymentNumberRequiredTitle"],
                            this.Services().Localize["AccountPaymentNumberRequiredMessage"],
                            () => { return; });

                        var customerNumber = await this.Services().Message.ShowPromptDialog(
                            this.Services().Localize["AccountPaymentCustomerNumberRequiredTitle"],
                            this.Services().Localize["AccountPaymentCustomerNumberRequiredMessage"],
                            () => { return; });

                        hasValidAccountNumber = await _orderWorkflowService.ValidateAccountNumberAndPrepareQuestions(accountNumber, customerNumber);

                        if (!hasValidAccountNumber)
                        {
                            await this.Services().Message.ShowMessage(
                                this.Services().Localize["Error_AccountPaymentTitle"],
                                this.Services().Localize["Error_AccountPaymentMessage"]);

                            return;
                        }

                        await _orderWorkflowService.SetAccountNumber(accountNumber, customerNumber);
                    }

                    var questions = await _orderWorkflowService.GetAccountPaymentQuestions();

                    if (questions != null &&
                        questions.Length > 0 &&
                        questions[0].Question.HasValue())
                    {
                        ParentViewModel.CurrentViewState = HomeViewModelState.Initial;

                        // Navigate to Q&A page
                        ShowSubViewModel <InitializeOrderForAccountPaymentViewModel, OrderRepresentation>(
                            null,
                            result => ParentViewModel.GotoBookingStatus(result.Order, result.OrderStatus)
                            );
                    }
                    else
                    {
                        // Skip Q&A page and confirm order
                        await ConfirmOrderAndGoToBookingStatus();
                    }
                }
                else
                {
                    // Skip Q&A page and confirm order
                    await ConfirmOrderAndGoToBookingStatus();
                }
            }
            catch (InvalidCreditCardException e)
            {
                Logger.LogError(e);

                PromptToAddCreditCard(true);
                return;
            }
            catch (OrderCreationException e)
            {
                Logger.LogError(e);

                var title = this.Services().Localize["ErrorCreatingOrderTitle"];

                switch (e.Message)
                {
                case "CreateOrder_PendingOrder":
                {
                    Guid pendingOrderId;
                    Guid.TryParse(e.Parameter, out pendingOrderId);

                    this.Services().Message.ShowMessage(title, this.Services().Localize["Error" + e.Message],
                                                        this.Services().Localize["View"], async() =>
                        {
                            var orderInfos = await GetOrderInfos(pendingOrderId);

                            ParentViewModel.BookingStatus.StartBookingStatus(orderInfos.Order, orderInfos.OrderStatus);

                            ParentViewModel.CurrentViewState = HomeViewModelState.BookingStatus;
                            ParentViewModel.AutomaticLocateMeAtPickup.ExecuteIfPossible();
                        },
                                                        this.Services().Localize["Cancel"], () => {});
                }
                break;

                default:
                {
                    if (!Settings.HideCallDispatchButton)
                    {
                        this.Services().Message.ShowMessage(title, e.Message,
                                                            this.Services().Localize["CallButton"], () => _phone.MakePhoneCall(Settings.TaxiHail.ApplicationName, Settings.DefaultPhoneNumber),
                                                            this.Services().Localize["Cancel"], () => { });
                    }
                    else
                    {
                        this.Services().Message.ShowMessage(title, e.Message);
                    }
                }
                break;
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
            finally
            {
                _orderWorkflowService.EndCreateOrder();
            }
        }