Example #1
0
        // Validate the OTP
        private bool ValidateOTP(CustomerToShopKeeperTransaction CtoS)
        {
            // Get current customer details
            var currentCustomerDetails = _changerMintsUOW.Repository <CustomerDetail>().Query().Filter(q => q.NFCTagID ==
                                                                                                       CtoS.NFCTagID).Get().FirstOrDefault();

            // Get the current customer entity from OTP records
            var currentCustomerOTPDetails = _changerMintsUOW.Repository <OTP>().Query().Filter(q => q.CustomerAccountnumber ==
                                                                                               currentCustomerDetails.CustomerAccountNumber && q.OTPNumber == CtoS.OTP).Get().FirstOrDefault();

            if (currentCustomerOTPDetails == null)
            {
                return(false);
            }

            // Check if the OTP duration is still valid
            bool IsOTPDurationValid = DateTime.Compare(currentCustomerOTPDetails.ValidTo, currentCustomerOTPDetails.ValidFrom) > 0 && currentCustomerOTPDetails.IsActive == true ? true : false;

            if (IsOTPDurationValid)
            {
                if (currentCustomerOTPDetails.Hits < int.Parse(ConfigurationManager.AppSettings["OTPExpireTime"]))
                {
                    // Add the hit counter to 1
                    currentCustomerOTPDetails.Hits++;
                    currentCustomerOTPDetails.IsActive = false;
                    _changerMintsUOW.Save();

                    // Check if the OTP PIN is valid
                    if (currentCustomerOTPDetails.OTPNumber == CtoS.OTP)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
        // Customer to Shopkeeper Transaction
        public string CustomerToShopkeeperTransaction(string ChangerQS)
        {
            _customerToShopkeeper     = ChangerUtils.URLSplitter <CustomerToShopKeeperTransaction>(ChangerQS, out IsRequestDTOSuccess);
            _crossTransactionResponse = new CrossTransactionResponse();

            try {
                if (IsRequestDTOSuccess)
                {
                    _crossTransactionResponse = _terminalService.CustomerToShopKeeperTransaction(_customerToShopkeeper);
                }
                else
                {
                    _crossTransactionResponse.ErrorNumber  = 1303;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];
                }
            } catch (ChangerMintsError Er) {
                _logerr.LogError(Er.Message, Er, LogType.Error);
                return(ChangerUtils.ResponseConcatenater <ChangerMintsError>(Er, true));
            } catch (Exception ex) {
                _crossTransactionResponse.ErrorNumber  = 2001;
                _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];
            }
            return(ChangerUtils.ResponseConcatenater <CrossTransactionResponse>(_crossTransactionResponse, true));
        }
Example #3
0
        // Customer to Shopkeeper Transaction Service
        public CrossTransactionResponse CustomerToShopKeeperTransaction(CustomerToShopKeeperTransaction CustomerToShopkeeper)
        {
            _crossTransactionResponse = new CrossTransactionResponse();

            try {
                var messageCreators = new List <ModelResponses <CrossTransactionResponse, ChangerValidations> > {
                    // Check if the Shopkeeper Account is of Valid length
                    new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsShopKeeperAccountValid(
                                                                                          CustomerToShopkeeper.ShopKeeperAccountNumber), 1101),
                    // Check if the Customer Account is of Valid length
                    new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsCustomerNFCTagIDValid(
                                                                                          CustomerToShopkeeper.NFCTagID), 1202),
                    // Check if the Amount is of >0
                    new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsAmountValid(
                                                                                          CustomerToShopkeeper.Amount), 1401),
                };

                ModelResponses <CrossTransactionResponse, ChangerValidations> errorCreator = null;
                if (!ChangerValidations.GetInputParametersStatus <CrossTransactionResponse, ChangerValidations>(messageCreators, out errorCreator))
                {
                    return(errorCreator.FillErrorDTO <CrossTransactionResponse>());
                }

                // Get current customer details
                var currentCustomerDetails = _changerMintsUOW.Repository <CustomerDetail>().Query().Filter(q => q.NFCTagID ==
                                                                                                           CustomerToShopkeeper.NFCTagID).Get().FirstOrDefault();

                // Verify if the customer is registered to the changer
                if (currentCustomerDetails == null)
                {
                    //Transaction Fail
                    _crossTransactionResponse.ErrorNumber  = 1208;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }

                // Verify if the password matches
                if (!(currentCustomerDetails.Password == CustomerToShopkeeper.Password))
                {
                    _crossTransactionResponse.ErrorNumber  = 1209;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }

                var currentCustomerNFCDetails = _changerMintsUOW.Repository <CustomerNFCTagDetail>().Query().Filter(q => q.NFCTagID ==
                                                                                                                    CustomerToShopkeeper.NFCTagID).Get().FirstOrDefault();

                if (currentCustomerNFCDetails.NFCTagUID != CustomerToShopkeeper.NFCTagUID)
                {
                    //Transaction Fail - NFCUID mis match
                    _crossTransactionResponse.ErrorNumber  = 1210;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }

                // Get current Customer Account Details
                var currentCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber ==
                                                                                                                         currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault();

                // Verify if the customer has account in our system
                if (currentCustomerAccountDetails == null)
                {
                    _crossTransactionResponse.ErrorNumber  = 1208;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }

                // Get current Shopkeeper Account Details
                var currentShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             CustomerToShopkeeper.ShopKeeperAccountNumber).Get().FirstOrDefault();

                // Verify if the Shopkeeper has account in our system
                if (currentShopkeeperAccountDetails == null)
                {
                    _crossTransactionResponse.ErrorNumber  = 1107;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }

                if (currentCustomerAccountDetails.Balance > 0 && currentCustomerAccountDetails.Balance > CustomerToShopkeeper.Amount)
                {
                    var  transactionID = GenerateTransactionID();
                    bool IsOTPRequired = (CustomerToShopkeeper.Amount >= MAXIMUM_TRANSACTION_LIMIT) ? true : false;

                    if (IsOTPRequired)
                    {
                        if (CustomerToShopkeeper.OTP > 0)
                        {
                            // OTP is already sent, please validate the records & continue the transaction
                            bool validateOTPStatus = ValidateOTP(CustomerToShopkeeper);
                            if (validateOTPStatus)
                            {
                                // Start Transaction
                                currentShopkeeperAccountDetails.ReceiverBalance += CustomerToShopkeeper.Amount;
                                currentCustomerAccountDetails.Balance           -= CustomerToShopkeeper.Amount;
                                _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Update(currentShopkeeperAccountDetails);
                                _changerMintsUOW.Repository <CustomerAccountDetail>().Update(currentCustomerAccountDetails);
                                _changerMintsUOW.Save();
                            }
                            else
                            {
                                _crossTransactionResponse.ErrorNumber  = 1500;
                                _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];
                                return(_crossTransactionResponse);
                            }
                        }
                        else
                        {
                            // Generate OTP and send it as SMS to customer
                            GenerateOTP(transactionID);

                            // Send the response for Terminal
                            _crossTransactionResponse.TransactionID = transactionID;
                            return(_crossTransactionResponse);
                        }
                    }
                    else
                    {
                        // Start Transaction
                        currentShopkeeperAccountDetails.ReceiverBalance += CustomerToShopkeeper.Amount;
                        currentCustomerAccountDetails.Balance           -= CustomerToShopkeeper.Amount;
                        _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Update(currentShopkeeperAccountDetails);
                        _changerMintsUOW.Repository <CustomerAccountDetail>().Update(currentCustomerAccountDetails);
                        _changerMintsUOW.Save();
                    }

                    // getting updated details after inserting values into database after transaction success
                    var getShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             CustomerToShopkeeper.ShopKeeperAccountNumber).Get().FirstOrDefault();
                    var getCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber ==
                                                                                                                         currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault();

                    //updating details in transaction table after transaction sucess
                    UpdateTransactionDetails <CustomerToShopKeeperTransaction>(CustomerToShopkeeper);

                    // Fill the Response DTO & send back to the controller
                    _crossTransactionResponse.ShopKeeperSenderBalance   = Convert.ToDecimal(getShopkeeperAccountDetails.SenderBalance);
                    _crossTransactionResponse.ShopKeeperReceiverBalance = Convert.ToDecimal(getShopkeeperAccountDetails.ReceiverBalance);
                    _crossTransactionResponse.ErrorNumber  = 1302;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];
                }
                else
                {
                    _crossTransactionResponse.ErrorNumber  = 1301;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }
            } catch (Exception e) {
                throw e;
            }
            return(_crossTransactionResponse);
        }