Ejemplo n.º 1
0
        public async Task <InternalTransferPaymentTransactionsDTO> MakeInternalTransferPaymentTransaction(string fromUniqueMasterCitizenNumber,
                                                                                                          string password,
                                                                                                          string toUniqueMasterCitizenNumber,
                                                                                                          decimal amount)
        {
            Wallet fromWallet = await CheckForWallet(fromUniqueMasterCitizenNumber, password);

            Wallet toWallet = await _unitOfWork.WalletRepository
                              .GetFirstWithIncludes(Wallet =>
                                                    Wallet.UniqueMasterCitizenNumber.Value == toUniqueMasterCitizenNumber,
                                                    Wallet => Wallet.PaymentTransactions
                                                    );

            if (toWallet == null)
            {
                throw new ArgumentException($"Wallet with unique master citizen number {toUniqueMasterCitizenNumber} doesn't exist");
            }
            IBankAPI bankAPI       = _bankAPIDeterminator.DeterminateBankAPI(fromWallet.SupportedBank);
            IBankAPI secondBankAPI = _bankAPIDeterminator.DeterminateBankAPI(toWallet.SupportedBank);

            InternalTransferPaymentTransactions paymentTransactions = fromWallet.MakeInternalTransfer(toWallet, amount);

            bool successWithdrawal = await bankAPI.Withdraw(fromUniqueMasterCitizenNumber, fromWallet.PostalIndexNumber, amount);

            if (!successWithdrawal)
            {
                CleanupWallets(fromWallet, toWallet, paymentTransactions);
                throw new BankAPIException("Bank api - failed to withdrawal");
            }
            bool successDeposit = await secondBankAPI.Withdraw(toUniqueMasterCitizenNumber, toWallet.PostalIndexNumber, amount);

            if (!successDeposit)
            {
                CleanupWallets(fromWallet, toWallet, paymentTransactions);
                throw new BankAPIException("Bank api - failed to deposit");
            }
            await _unitOfWork.PaymentTransactionRepository.Insert(paymentTransactions.Deposit);

            await _unitOfWork.PaymentTransactionRepository.Insert(paymentTransactions.Withdrawal);

            if (paymentTransactions.HasFee())
            {
                await _unitOfWork.PaymentTransactionRepository.Insert(paymentTransactions.Fee);
            }
            await _unitOfWork.SaveChangesAsync();

            return(new InternalTransferPaymentTransactionsDTO(paymentTransactions));
        }
Ejemplo n.º 2
0
        public async Task <WithdrawalPaymentTransactionDTO> MakeWithdrawalPaymentTransaction(string uniqueMasterCitizenNumberValue,
                                                                                             string password,
                                                                                             decimal amount)
        {
            Wallet wallet = await CheckForWallet(uniqueMasterCitizenNumberValue, password);

            IBankAPI bankAPI = _bankAPIDeterminator.DeterminateBankAPI(wallet.SupportedBank);
            WithdrawalPaymentTransaction withdrawalPaymentTransaction = wallet.MakeWithdrawalTransaction(amount);
            bool successDeposit = await bankAPI.Deposit(uniqueMasterCitizenNumberValue, wallet.PostalIndexNumber, amount);

            if (!successDeposit)
            {
                throw new BankAPIException("Bank api - failed to deposit");
            }
            await _unitOfWork.PaymentTransactionRepository.Insert(withdrawalPaymentTransaction);

            await _unitOfWork.SaveChangesAsync();

            return(new WithdrawalPaymentTransactionDTO(withdrawalPaymentTransaction));
        }
Ejemplo n.º 3
0
        public async Task <WalletDTO> CreateNewWallet(string uniqueMasterCitizenNumberValue,
                                                      string postalIndexNumber,
                                                      int supportedBankId,
                                                      string firstName,
                                                      string lastName)
        {
            SupportedBank supportedBank = await _unitOfWork.SupportedBankRepository.GetById(supportedBankId);

            if (supportedBank == null)
            {
                throw new ArgumentException($"Supported bank with id {supportedBankId} does not exist");
            }
            IBankAPI bankAPI     = _bankAPIDeterminator.DeterminateBankAPI(supportedBank);
            bool     validStatus = await bankAPI.CheckStatus(uniqueMasterCitizenNumberValue, postalIndexNumber);

            if (!validStatus)
            {
                throw new BankAPIException("Bank api - invalid status");
            }
            Wallet existingWallet = await _unitOfWork.WalletRepository.GetFirstOrDefault(Wallet =>
                                                                                         Wallet.UniqueMasterCitizenNumber.Value == uniqueMasterCitizenNumberValue
                                                                                         );

            if (existingWallet != null)
            {
                throw new ExistingWalletException("Wallet already exist with same UMCN");
            }
            UniqueMasterCitizenNumber uniqueMasterCitizenNumber = new UniqueMasterCitizenNumber(uniqueMasterCitizenNumberValue);

            if (!uniqueMasterCitizenNumber.ValidForPlatform())
            {
                throw new NotValidUniqueMasterCitizenNumberException("Unique master citizen number not valid for platform");
            }
            string walletPassword = PasswordGenerator.WalletPassword();
            Wallet wallet         = new Wallet(uniqueMasterCitizenNumberValue, supportedBank, firstName, lastName, walletPassword, postalIndexNumber);
            await _unitOfWork.WalletRepository.Insert(wallet);

            await _unitOfWork.SaveChangesAsync();

            return(new WalletDTO(wallet));
        }
Ejemplo n.º 4
0
 public GetPaymentHandler(IBankAPI bankApi)
 {
     _bankApi = bankApi;
 }
Ejemplo n.º 5
0
 public ProcessPaymentHandlerTests()
 {
     _paymentHistoryRepo = Substitute.For <IPaymentHistoryRepo>();
     _bankApi            = Substitute.For <IBankAPI>();
 }
 public ProcessPaymentHandler(IPaymentHistoryRepo paymentHistoryRepo, IBankAPI bankApi)
 {
     _paymentHistoryRepo = paymentHistoryRepo;
     _bankApi            = bankApi;
 }
Ejemplo n.º 7
0
 public GetPaymentHandlerTests()
 {
     _bankApi = Substitute.For <IBankAPI>();
 }