public IActionResult GenerateTopup(GenerateTopupCommand command)
        {
            if (int.Parse(command.Account.Substring(0, 2)) != (int)EW_Enumerations.EW_UserTypeEnum.Admin)
            {
                return(BadRequest());
            }

            bool isExist = _userService.ExistAccountNo(command.Account);

            if (!isExist)
            {
                return(BadRequest());
            }

            TopupResultDTO result = _transactionService.GenerateTopUp(command.Account, command.Amount);

            if (result == null)
            {
                return(BadRequest());
            }

            GenerateTopupViewModel viewModel = new GenerateTopupViewModel()
            {
                ReferenceNumber = result.ReferenceNumber,
                ExpireDate      = result.ExpireDate
            };

            return(Ok(viewModel));
        }
Ejemplo n.º 2
0
        public QRcodePage(GenerateTopupViewModel topupData)
        {
            InitializeComponent();
            (BindingContext as GenerateQRcodeViewModel).DisplayData = topupData;
            var topupJson = JsonConvert.SerializeObject(topupData);

            (BindingContext as GenerateQRcodeViewModel).QrcodeData = topupJson;
        }
Ejemplo n.º 3
0
        public static string CheckSumTopupCreate(GenerateTopupViewModel viewModel)
        {
            string sumString = "";

            sumString = viewModel.AccountNumber + viewModel.Amount + viewModel.ExpireDate + viewModel.FirstName + viewModel.ReferenceNumber;
            string hashedSum = SHA256Hash(sumString);

            return(hashedSum);
        }
Ejemplo n.º 4
0
        public static bool CheckSumTopup(GenerateTopupViewModel viewModel)
        {
            string sumString = "";

            sumString = viewModel.AccountNumber + viewModel.Amount + viewModel.ExpireDate + viewModel.FirstName + viewModel.ReferenceNumber;
            string hashedSum = SHA256Hash(sumString);

            if (hashedSum == viewModel.CheckSum)
            {
                return(true);
            }
            return(false);
        }
        private async void GenerateQrcode()
        {
            IsProgress = true;
            if (Amount < 1)
            {
                ErrorViewModel errorView = new ErrorViewModel("จำนวนเงินไม่สามารถติดลบ หรือ เท่ากับ 0 ได้", (int)EWalletV2.Api.ViewModels.EW_Enumerations.EW_ErrorTypeEnum.Warning);
                await PopupNavigation.Instance.PushAsync(new Error(errorView));

                IsProgress = false;
            }
            else
            {
                var accountNumber = App.Account;
                var callData      = await _transactionService.GenerateTopup(accountNumber, Amount);

                var refNumber  = callData.Model.ReferenceNumber;
                var expireTime = callData.Model.ExpireDate.AddHours(7);
                GenerateTopupViewModel resultData = new GenerateTopupViewModel()
                {
                    Amount          = Amount,
                    AccountNumber   = App.Account,
                    FirstName       = App.AdminName,
                    ReferenceNumber = refNumber,
                    ExpireDate      = expireTime,
                    CheckSum        = "",
                    LastName        = ""
                };
                resultData.CheckSum = Helper.CheckSumTopupCreate(resultData);
                if (callData.IsError == true)
                {
                    IsProgress = false;
                    ErrorViewModel errorView = new ErrorViewModel();
                    await PopupNavigation.Instance.PushAsync(new Error(errorView));
                }
                else
                {
                    await Application.Current.MainPage.Navigation.PushAsync(new QRcodePage(resultData));

                    IsProgress = false;
                }
            }
        }
Ejemplo n.º 6
0
        private async void ScanToTopup()
        {
            //เปิดกล้อง อ่าน qrcode
            try
            {
                var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync <CameraPermission>();

                if (cameraStatus != PermissionStatus.Granted)
                {
                    cameraStatus = await CrossPermissions.Current.RequestPermissionAsync <CameraPermission>();
                }

                if (cameraStatus == PermissionStatus.Granted)
                {
                    var scanner = DependencyService.Get <IQrScanningService>();
                    var result  = await scanner.ScanAsync();

                    if (result != null)
                    {
                        GenerateTopupViewModel QrCodeInfomation = JsonConvert.DeserializeObject <GenerateTopupViewModel>(result);
                        if (CheckSum(QrCodeInfomation))
                        {
                            decimal Amount          = QrCodeInfomation.Amount;
                            string  AdminName       = QrCodeInfomation.FirstName + " " + QrCodeInfomation.LastName;
                            string  AccountNumber   = QrCodeInfomation.AccountNumber;
                            string  qrcodeReference = QrCodeInfomation.ReferenceNumber;
                            await PopupNavigation.PushAsync(new Views.ScanToTopupTwo(Amount, AdminName, AccountNumber, qrcodeReference));
                        }
                        //Wrong QRCode or QRCode expired
                    }
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Sorry", "Can not use QR Scanner with out Camera Permission", "Ok");
                }
            }
            catch (Exception ex)
            {
                ErrorViewModel errorViewModel = new ErrorViewModel("QR Code ไม่ถูกต้อง", (int)EW_Enumerations.EW_ErrorTypeEnum.Warning);
                PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
            }
        }