Exemplo n.º 1
0
        // Shopkeeper Receiver to Sender Transaction
        public string ShopkeeperToShopkeeperTransaction(string ChangerQS)
        {
            _shopkeeperToShopkeeper   = ChangerUtils.URLSplitter <ShopKeeperReceiverToSenderTransaction>(ChangerQS, out IsRequestDTOSuccess);
            _interTransactionResponse = new InterTransactionResponse();

            try {
                if (IsRequestDTOSuccess)
                {
                    _interTransactionResponse = _terminalService.ShopKeeperToShopKeeperTransaction(_shopkeeperToShopkeeper);
                }
                else
                {
                    _interTransactionResponse.ErrorNumber  = 1303;
                    _interTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];
                }
            } catch (ChangerMintsError Er) {
                _logerr.LogError(Er.Message, Er, LogType.Error);
                return(ChangerUtils.ResponseConcatenater <ChangerMintsError>(Er, true));
            } catch (Exception ex) {
                _interTransactionResponse.ErrorNumber  = 2001;
                _interTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];
            }
            return(ChangerUtils.ResponseConcatenater <InterTransactionResponse>(_interTransactionResponse, true));
        }
Exemplo n.º 2
0
        // Receiver balance to sender balance transaction service
        public InterTransactionResponse ShopKeeperToShopKeeperTransaction(ShopKeeperReceiverToSenderTransaction ShopkeeperToShopkeeper)
        {
            _interTransactionResponse = new InterTransactionResponse();

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

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

                // Get current shopkeeper account details
                var currentShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             ShopkeeperToShopkeeper.ShopKeeperAccountNumber).Get().FirstOrDefault();

                if (currentShopkeeperAccountDetails == null)
                {
                    _interTransactionResponse.ErrorNumber  = 1107;
                    _interTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];

                    return(_interTransactionResponse);
                }

                if (currentShopkeeperAccountDetails.ReceiverBalance > ShopkeeperToShopkeeper.Amount &&
                    currentShopkeeperAccountDetails.ReceiverBalance > 0)
                {
                    // Start Transaction
                    decimal TransferableAmountToShopkeeper = TRANSFERABLE_PERCENTAGE_AFTER_COMMISION * ShopkeeperToShopkeeper.Amount;
                    decimal TransferableAmountToChanger    = COMMISSION_TO_CHANGER * ShopkeeperToShopkeeper.Amount;

                    currentShopkeeperAccountDetails.ReceiverBalance -= ShopkeeperToShopkeeper.Amount;
                    currentShopkeeperAccountDetails.SenderBalance   += TransferableAmountToShopkeeper;
                    _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Update(currentShopkeeperAccountDetails);
                    _changerMintsUOW.Save();

                    // Update the Transaction details
                    var getShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             ShopkeeperToShopkeeper.ShopKeeperAccountNumber).Get().FirstOrDefault();

                    // Update the transaction table for Shopkeeper
                    var shopKeeperTransactionDetail = new ShopKeeperTransactionDetail()
                    {
                        ShopKeeperAccountNumber = getShopkeeperAccountDetails.ShopKeeperAccountNumber, SenderBalance = getShopkeeperAccountDetails.SenderBalance,
                        ReceiverBalance         = getShopkeeperAccountDetails.ReceiverBalance, ReceivedFrom = 0, PaidTo = getShopkeeperAccountDetails.ShopKeeperAccountNumber,
                        AmountTransfered        = ShopkeeperToShopkeeper.Amount, TransactionDate = DateTime.Now, TransactionStatus = 1001, TerminalIMEINumber = ShopkeeperToShopkeeper.TerminalIMEINumber,
                        TransactionID           = GenerateTransactionID()
                    };
                    _changerMintsUOW.Repository <ShopKeeperTransactionDetail>().Insert(shopKeeperTransactionDetail);
                    _changerMintsUOW.Save();

                    // success message
                    _interTransactionResponse.ErrorNumber     = 1302;
                    _interTransactionResponse.ErrorMessage    = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];
                    _interTransactionResponse.SenderBalance   = Convert.ToDecimal(currentShopkeeperAccountDetails.SenderBalance);
                    _interTransactionResponse.ReceiverBalance = Convert.ToDecimal(currentShopkeeperAccountDetails.ReceiverBalance);
                }
                else
                {
                    _interTransactionResponse.ErrorNumber = 1301;
                }
                _interTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];
            } catch (Exception e) {
                throw e;
            }
            return(_interTransactionResponse);
        }