コード例 #1
0
        private void OnSendFastPaymentUrlBySmsClicked(object btn, EventArgs args)
        {
            if (_order.Id == 0)
            {
                _interactiveService.ShowMessage(ImportanceLevel.Error, "Перед отправкой QR необходимо сохранить заказ",
                                                "Не удалось отправить QR по SMS");
                return;
            }
            if (string.IsNullOrWhiteSpace(validatedPhoneEntry.Text))
            {
                _interactiveService.ShowMessage(ImportanceLevel.Error, "Вы забыли выбрать номер.", "Не удалось отправить QR по SMS");
                return;
            }

            if (!InstantSmsServiceSetting.SendingAllowed)
            {
                return;
            }

            var lastProccessingPayment = _fastPaymentRepository.GetProcessingPaymentForOrder(InfoProvider.UoW, _order.Id);

            if (lastProccessingPayment != null)
            {
                if (!_interactiveService.Question(
                        "Будет отменена текущая действующая сессия оплаты и сформирована новая ссылка на оплату. Продолжить?",
                        "Вы уверены что хотите отправить новую ссылку на оплату по SMS?"))
                {
                    return;
                }
            }

            btnSendFastPaymentPayByQrUrlBySms.Sensitive = btnSendFastPaymentPayByCardUrlBySms.Sensitive = ySendSmsButton.Sensitive = false;
            GLib.Timeout.Add(10000, () =>
            {
                if (!_isPaidOrder)
                {
                    btnSendFastPaymentPayByQrUrlBySms.Sensitive   = true;
                    btnSendFastPaymentPayByCardUrlBySms.Sensitive = _canSendSmsForPayFromSbpByCard;
                    ySendSmsButton.Sensitive = _canSendSmsForPayFromYookassa;
                }

                return(false);
            });

            var isQr       = (btn as yButton)?.Name == nameof(btnSendFastPaymentPayByQrUrlBySms);
            var smsSender  = new SmsSender(_fastPaymentParametersProvider, InstantSmsServiceSetting.GetInstantSmsService());
            var resultTask = smsSender.SendFastPaymentUrlAsync(_order, validatedPhoneEntry.Text, isQr);

            resultTask.Wait();
            var result = resultTask.Result;

            switch (result.MessageStatus)
            {
            case SmsMessageStatus.Ok:
                _interactiveService.ShowMessage(ImportanceLevel.Info, "SMS отправлена успешно");
                break;

            case SmsMessageStatus.Error:
                if (result.IsPaidStatus)
                {
                    _isPaidOrder             = true;
                    ySendSmsButton.Sensitive = false;
                }
                _interactiveService.ShowMessage(ImportanceLevel.Error, result.ErrorDescription, "Не удалось отправить SMS");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }