コード例 #1
0
 public IEnumerable <PaymentTransaction> AllWithdrawalPaymentTransactions()
 {
     return(PaymentTransactions.Where(PaymentTransaction =>
                                      PaymentTransaction.Type == PaymentTransactionType.WITHDRAWAL ||
                                      PaymentTransaction.Type == PaymentTransactionType.INTERNAL_TRANSFER_WITHDRAWAL
                                      ).ToList());
 }
コード例 #2
0
        private bool FinallAddToJournal(PaymentTransactions paymentResponse)
        {
            //successfull Transaction now insert to main DB
            var    claims = (ClaimsIdentity)HttpContext.Current.User.Identity;
            var    sid    = claims.FindFirst(ClaimTypes.Sid);
            string title  = "افزایش اعتبار از طریق پنل مشتریان ";

            title += "با رسید دیجیتال ";
            title += paymentResponse.DigitalReceipt;

            StringBuilder details = new StringBuilder();

            details.Append("<ROOT>");
            details.AppendFormat("<JournalDetail AccountID=\"{0}\" TransactionAmount=\"{1}\"></JournalDetail>", "9", paymentResponse.Amount);
            long tt;

            long.TryParse("-" + paymentResponse.Amount.ToString(), out tt);
            details.AppendFormat("<JournalDetail AccountID=\"{0}\" TransactionAmount=\"{1}\"></JournalDetail></ROOT>", "7", tt);
            try
            {
                var finalInsert = new ReportBlo().JournalInsert(title, details.ToString());
                if (finalInsert > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #3
0
 public IEnumerable <PaymentTransaction> AllDepositPaymentTransactions()
 {
     return(PaymentTransactions.Where(PaymentTransaction =>
                                      PaymentTransaction.Type == PaymentTransactionType.DEPOSIT ||
                                      PaymentTransaction.Type == PaymentTransactionType.INTERNAL_TRANSFER_DEPOSIT
                                      ).ToList());
 }
コード例 #4
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,Amount,CreatedDate,PaymentDate,Explanation,Explanation2,Explanation3,ContractId,Customer,Cash,CostTypDefenition,IncomeTypeDefenition,TransactionTypDefenition,SupportTypDefenition,Number,CustDocno,SignTypeId,SignTypeDefenition,CashId,TransactionTypeId,CustomersId,CostTypeId,SupportTypeId,ObjectsId,PaymentsId,IncomeTypeId")] PaymentTransactions paymentTransactions)
        {
            if (id != paymentTransactions.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(paymentTransactions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentTransactionsExists(paymentTransactions.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(paymentTransactions));
        }
コード例 #5
0
        public PaymentTransactions AddPaymentTransactions(PaymentTransactions transactions)
        {
            _paymentTransactions.Add(transactions.TransactionId, transactions);

            //Here we should connect to the Bank and authenticate card number, expiry date and so on before proceeding.

            return(transactions);
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Amount,CreatedDate,PaymentDate,Explanation,Explanation2,Explanation3,ContractId,Customer,Cash,CostTypDefenition,IncomeTypeDefenition,TransactionTypDefenition,SupportTypDefenition,Number,CustDocno,SignTypeId,SignTypeDefenition,CashId,TransactionTypeId,CustomersId,CostTypeId,SupportTypeId,ObjectsId,PaymentsId,IncomeTypeId")] PaymentTransactions paymentTransactions)
        {
            if (ModelState.IsValid)
            {
                _context.Add(paymentTransactions);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(paymentTransactions));
        }
コード例 #7
0
        public ActionResult <PaymentTransactions> AddPaymentTransactions(PaymentTransactions transactions)
        {
            var paymentTransactions = _services.AddPaymentTransactions(transactions);

            if (paymentTransactions == null)
            {
                return(NotFound());
            }

            return(paymentTransactions);
        }
コード例 #8
0
        public DepositPaymentTransaction MakeDepositTransaction(decimal depositAmount)
        {
            CheckIfWalletIsBlocked();
            bool isLimitExceeded = LimitPaymentTransactionCalculator.IsDepositLimitExceed(this, depositAmount);

            if (isLimitExceeded)
            {
                throw new LimitExceededException();
            }
            var depositPaymentTransaction = new DepositPaymentTransaction(this, depositAmount);

            PaymentTransactions.Add(depositPaymentTransaction);
            CurrentAmount += depositAmount;
            return(depositPaymentTransaction);
        }
コード例 #9
0
        private bool RollBackPayment(ref PaymentTransactions paymentResponse, HttpClient client, ApprovalRequest requestApprove)
        {
            try
            {
                var resRollBack = client.PostAsJsonAsync("/v1/PeymentApi/RollBack ", requestApprove).GetAwaiter().GetResult();
                resRollBack.EnsureSuccessStatusCode();
                var RollBackResponse = resRollBack.Content.ReadAsAsync <ApprovalResponse>().GetAwaiter().GetResult();
                paymentResponse.RollBackReturnId = RollBackResponse.ReturnId;
                paymentResponse.RollBackStatus   = RollBackResponse.Status;

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #10
0
        public HttpResponseMessage testaddjournal()
        {
            PaymentTransactions paymentResponse = new PaymentTransactions();

            paymentResponse.Amount         = 2000;
            paymentResponse.DigitalReceipt = "12344566789";



            if (FinallAddToJournal(paymentResponse))
            {
                return(new HttpResponseMessage(HttpStatusCode.Accepted));
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.ExpectationFailed));
            }
        }
コード例 #11
0
        public WithdrawalPaymentTransaction MakeWithdrawalTransaction(decimal withdrawalAmount)
        {
            CheckIfWalletIsBlocked();
            bool isLimitExceeded = LimitPaymentTransactionCalculator.IsWithdrawalLimitExceed(this, withdrawalAmount);

            if (isLimitExceeded)
            {
                throw new LimitExceededException();
            }
            if (CurrentAmount < withdrawalAmount)
            {
                throw new NotEnoughAmountException();
            }
            CurrentAmount -= withdrawalAmount;
            var withdrawalPaymentTransaction = new WithdrawalPaymentTransaction(this, withdrawalAmount);

            PaymentTransactions.Add(withdrawalPaymentTransaction);
            return(withdrawalPaymentTransaction);
        }
コード例 #12
0
        public InternalTransferPaymentTransactions MakeInternalTransfer(Wallet toWallet, decimal amount)
        {
            CheckIfWalletIsBlocked();
            toWallet.CheckIfWalletIsBlocked();
            decimal feeAmount = FeeCalculator.CalculateFee(this, amount);
            bool    isWithdrawalLimitExceeded = LimitPaymentTransactionCalculator.IsWithdrawalLimitExceed(this, amount);

            if (isWithdrawalLimitExceeded)
            {
                throw new LimitExceededException();
            }
            bool isDepositLimitExceeded = LimitPaymentTransactionCalculator.IsDepositLimitExceed(toWallet, amount);

            if (isDepositLimitExceeded)
            {
                throw new LimitExceededException();
            }
            if (CurrentAmount < amount + feeAmount)
            {
                throw new NotEnoughAmountException();
            }
            string internalTransferId = Guid.NewGuid().ToString();
            var    deposit            = new DepositInternalTransferPaymentTransaction(toWallet, this, amount, internalTransferId);
            var    withdrawal         = new WithdrawalInternalTransferPaymentTransaction(this, toWallet, amount, internalTransferId);
            FeeInternalTransferPaymentTransaction feePaymentTransaction = new FeeInternalTransferPaymentTransaction(this, toWallet, feeAmount, internalTransferId);

            this.CurrentAmount     -= amount;
            toWallet.CurrentAmount += amount;
            PaymentTransactions.Add(withdrawal);
            toWallet.PaymentTransactions.Add(deposit);
            var internalTransferPaymentTransactions = new InternalTransferPaymentTransactions(deposit, withdrawal, feePaymentTransaction);

            if (internalTransferPaymentTransactions.HasFee())
            {
                this.CurrentAmount -= feeAmount;
                PaymentTransactions.Add(feePaymentTransaction);
            }
            return(internalTransferPaymentTransactions);
        }
コード例 #13
0
        public OperationResult WithdrawRequest(WalletWithdrawRequestModel request, Guid userId)
        {
            return(InvokeOperations.InvokeOperation(() =>
            {
                var wallet = context.Wallets.First(w => w.UserId == userId && w.Currency == request.Currency);
                if (wallet.Amount < request.Amount)
                {
                    throw new ApplicationException("Not enough funds");
                }

                // TODO wallet relation
                var transaction = new PaymentTransactions
                {
                    Id = Guid.NewGuid(),
                    Amount = request.Amount,
                    Type = PaymentTransactionType.Withdrawn,
                    DateCreated = DateTime.UtcNow,
                    DestAddress = request.BlockchainAddress,
                    Status = PaymentTransactionStatus.New
                };

                context.Add(transaction);
            }));
        }
コード例 #14
0
 public IEnumerable <InternalTransferPaymentTransaction> InternalTransferPaymentTransactions()
 {
     return(PaymentTransactions.Where(PaymentTransaction => PaymentTransaction is InternalTransferPaymentTransaction)
            .Select(PaymentTransaction => (InternalTransferPaymentTransaction)PaymentTransaction)
            .ToList());
 }
コード例 #15
0
        public async Task <PaymentTransactionInfo> ProcessCallback(ProcessPaymentTransaction request)
        {
            var blockchainAddress = context.BlockchainAddresses.FirstOrDefault(addr => addr.Address == request.Address);

            if (blockchainAddress == null)
            {
                var msg = $"Eth address not found - {request.Address}";
                logger.LogError(msg);
                throw new ApplicationException(msg);
            }

            if (request.Currency != blockchainAddress.Currency)
            {
                var msg = $"Wallet and Transaction currency should be the same {blockchainAddress.Id}";
                logger.LogError(msg);
                throw new ApplicationException(msg);
            }

            var wallet = context.Wallets.First(w => w.UserId == blockchainAddress.UserId && w.Currency == blockchainAddress.Currency);

            PaymentTransactionInfo paymentTransactionInfo;

            using (var transaction = await context.Database.BeginTransactionAsync())
            {
                var paymentTransaction = context.PaymentTransactions
                                         .FirstOrDefault(t => t.Hash == request.TransactionHash &&
                                                         t.BlockchainAddressId == blockchainAddress.Id);

                if (paymentTransaction != null)
                {
                    if (paymentTransaction.Status == PaymentTransactionStatus.Pending ||
                        paymentTransaction.Status == PaymentTransactionStatus.New)
                    {
                        paymentTransaction.Status      = request.Status;
                        paymentTransaction.LastUpdated = DateTime.UtcNow;
                        context.Update(paymentTransaction);
                        await context.SaveChangesAsync();
                    }
                    else
                    {
                        logger.LogError($"Can not override status from {paymentTransaction.Status} to {request.Status}");
                    }
                }
                else
                {
                    var walletTransactions = new WalletTransactions()
                    {
                        Id       = Guid.NewGuid(),
                        WalletId = wallet.Id,
                        Type     = WalletTransactionsType.Deposit,
                        Date     = DateTime.UtcNow,
                        Amount   = request.Amount
                    };

                    context.WalletTransactions.Add(walletTransactions);
                    await context.SaveChangesAsync();

                    paymentTransaction = new PaymentTransactions
                    {
                        Id   = Guid.NewGuid(),
                        Hash = request.TransactionHash,
                        Type = PaymentTransactionType.Deposit,
                        BlockchainAddressId = blockchainAddress.Id,
                        Amount            = request.Amount,
                        Fee               = request.Fee,
                        DateCreated       = DateTime.UtcNow,
                        Status            = request.Status,
                        PayoutTxHash      = request.PayoutTxHash,
                        PayoutServiceFee  = request.PayoutServiceFee,
                        PayoutMinerFee    = request.PayoutMinerFee,
                        WalletTransaction = walletTransactions
                    };

                    context.PaymentTransactions.Add(paymentTransaction);

                    if (paymentTransaction.Status == PaymentTransactionStatus.ConfirmedAndValidated)
                    {
                        wallet.Amount += paymentTransaction.Amount;

                        await context.SaveChangesAsync();
                    }
                }

                transaction.Commit();

                paymentTransactionInfo = new PaymentTransactionInfo
                {
                    TransactionId   = paymentTransaction.Id,
                    TransactionHash = paymentTransaction.Hash,
                    Amount          = paymentTransaction.Amount,
                    Currency        = request.Currency.ToString(),
                    GatewayCode     = request.GatewayCode,
                    Status          = paymentTransaction.Status,
                    IsValid         = true
                };
            }

            return(paymentTransactionInfo);
        }
コード例 #16
0
        public HttpResponseMessage ManageCallback(PaymentResponseDTO paymentResponse)
        {
            var test = HttpContext.Current.Request.UserHostAddress;

            if (paymentResponse == null)
            {
                return(RedirectUIToDefaultPage(5));
            }
            else
            {
                PaymentTransactions paymentTrans = new PaymentTransactions
                {
                    Amount         = paymentResponse.amount,
                    DatePaid       = paymentResponse.datepaid,
                    DigitalReceipt = paymentResponse.digitalreceipt,
                    InvoiceId      = paymentResponse.invoiceid,
                    IssuerBank     = paymentResponse.issuerbank,
                    Payload        = paymentResponse.payload,
                    RespCode       = paymentResponse.respcode,
                    RRN            = paymentResponse.rrn,
                    TerminalID     = paymentResponse.terminalid,
                    TraceNumber    = paymentResponse.tracenumber
                };
                using (var unitOfWOrk = new UnitOfWork())
                {
                    unitOfWOrk.TransRepository.Add(paymentTrans);
                    unitOfWOrk.SaveChanges();
                    if (paymentResponse.respcode < 0)
                    {
                        return(RedirectUIToDefaultPage(1));
                    }

                    var duplicateDigitalReciept = unitOfWOrk.TransRepository.Get
                                                      (x => x.DigitalReceipt == paymentResponse.digitalreceipt);
                    if (duplicateDigitalReciept.Count() > 1)
                    {
                        return(RedirectUIToDefaultPage(2));
                    }

                    if (paymentResponse.respcode == 0)
                    {
                        HttpClient client = new HttpClient();
                        client.BaseAddress = new Uri("https://mabna.shaparak.ir:8081");
                        var requestApprove = new ApprovalRequest
                        {
                            TnxId = paymentTrans.DigitalReceipt,
                            Tid   = paymentTrans.TerminalID
                        };
                        var res = client.PostAsJsonAsync("/v1/PeymentApi/Advice", requestApprove).GetAwaiter().GetResult();
                        res.EnsureSuccessStatusCode();
                        var approvResponse = res.Content.ReadAsAsync <ApprovalResponse>().GetAwaiter().GetResult();
                        if (approvResponse != null)
                        {
                            paymentTrans.AdviceReturnId = approvResponse.ReturnId;
                            paymentTrans.AdviceStatus   = approvResponse.Status;
                            unitOfWOrk.TransRepository.Edit(paymentTrans);
                            unitOfWOrk.SaveChanges();
                            if (approvResponse.ReturnId >= 0)
                            {
                                if (paymentTrans.Amount != approvResponse.Amount)
                                {
                                    if (RollBackPayment(ref paymentTrans, client, requestApprove))
                                    {
                                        unitOfWOrk.TransRepository.Edit(paymentTrans);
                                        unitOfWOrk.SaveChanges();
                                    }
                                    return(RedirectUIToDefaultPage(3));
                                }
                                else
                                {
                                    if (!FinallAddToJournal(paymentTrans))
                                    {
                                        RollBackPayment(ref paymentTrans, client, requestApprove);
                                        return(RedirectUIToDefaultPage(6));
                                    }
                                }
                            }
                            else
                            {
                                return(RedirectUIToDefaultPage(4));
                            }
                        }
                        else
                        {
                            return(RedirectUIToDefaultPage(5));
                        }
                    }
                }

                return(RedirectUIToDefaultPage(0));
            }


            //return Request.CreateResponse(HttpStatusCode.OK);
        }