예제 #1
0
        // Shopkeeper to Customer Transaction
        public string ShopkeepertoCustomerTransaction(string ChangerQS)
        {
            _shopkeeperToCustomer     = ChangerUtils.URLSplitter <ShopKeeperToCustomerTransaction>(ChangerQS, out IsRequestDTOSuccess);
            _crossTransactionResponse = new CrossTransactionResponse();

            try {
                if (IsRequestDTOSuccess)
                {
                    _crossTransactionResponse = _terminalService.ShopkeeperToCustomerTransaction(_shopkeeperToCustomer);
                }
                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));
        }
예제 #2
0
        // Shopkeeper to Customer Transaction Service
        public CrossTransactionResponse ShopkeeperToCustomerTransaction(ShopKeeperToCustomerTransaction ShopkeeperToCustomer)
        {
            _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(
                                                                                          ShopkeeperToCustomer.ShopKeeperAccountNumber), 1101),
                    // Check if the Customer Account is of Valid length
                    new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsCustomerNFCTagIDValid(
                                                                                          ShopkeeperToCustomer.NFCTagID), 1202),
                    // Check if the Amount is of >0
                    new ModelResponses <CrossTransactionResponse, ChangerValidations>(model => model.IsAmountValid(
                                                                                          ShopkeeperToCustomer.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 ==
                                                                                                           ShopkeeperToCustomer.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);
                }

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

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

                    return(_crossTransactionResponse);
                }

                // Retrieve particulars from the database for given Shopkeeper and Customer
                var currentShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             ShopkeeperToCustomer.ShopKeeperAccountNumber).Get().FirstOrDefault();
                var currentCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber ==
                                                                                                                         currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault();

                // Verify if the Shopkeeper is registered to our system.
                if (currentShopkeeperAccountDetails == null)
                {
                    //Transaction Fail
                    _crossTransactionResponse.ErrorNumber  = 1107;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];

                    return(_crossTransactionResponse);
                }

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

                    return(_crossTransactionResponse);
                }

                // If the balance is greater than the transferable amount, start the transaction
                if (currentShopkeeperAccountDetails.SenderBalance > ShopkeeperToCustomer.Amount &&
                    currentShopkeeperAccountDetails.SenderBalance > 0)
                {
                    // Start the transaction
                    currentShopkeeperAccountDetails.SenderBalance -= ShopkeeperToCustomer.Amount;
                    currentCustomerAccountDetails.Balance         += ShopkeeperToCustomer.Amount;
                    _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Update(currentShopkeeperAccountDetails);
                    _changerMintsUOW.Repository <CustomerAccountDetail>().Update(currentCustomerAccountDetails);
                    _changerMintsUOW.Save();

                    // Update Shopkeeper & Customer Transaction Details
                    var getShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             ShopkeeperToCustomer.ShopKeeperAccountNumber).Get().FirstOrDefault();
                    var getCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber ==
                                                                                                                         currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault();

                    var query1 = from s in _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                  ShopkeeperToCustomer.ShopKeeperAccountNumber).Get()
                                 select new CrossTransactionResponse {
                        ShopKeeperSenderBalance   = s.SenderBalance,
                        ShopKeeperReceiverBalance = s.ReceiverBalance
                    };

                    UpdateTransactionDetails <ShopKeeperToCustomerTransaction>(ShopkeeperToCustomer);

                    // Fill the Response DTO & send back to the controller
                    _crossTransactionResponse.ErrorNumber               = 1302;
                    _crossTransactionResponse.ErrorMessage              = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];
                    _crossTransactionResponse.ShopKeeperSenderBalance   = Convert.ToDecimal(getShopkeeperAccountDetails.SenderBalance);
                    _crossTransactionResponse.ShopKeeperReceiverBalance = Convert.ToDecimal(getShopkeeperAccountDetails.ReceiverBalance);
                }
                else
                {
                    _crossTransactionResponse.ErrorNumber  = 1301;
                    _crossTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_crossTransactionResponse.ErrorNumber.ToString()];
                }
            } catch (Exception e) {
                throw e;
            }
            return(_crossTransactionResponse);
        }
예제 #3
0
 public TerminalController()
 {
     _terminalResponse = new CrossTransactionResponse();
     _terminalService  = new TerminalServices();
     _logerr           = new LogFiles();
 }
예제 #4
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);
        }