Пример #1
0
        public void Approve(ApproveOnlineDepositRequest request)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                //lock data to prevent deposit multi times
                _repository.LockOnlineDeposit(request.Id);

                var onlineDeposit = _repository.OnlineDeposits.First(x => x.Id == request.Id);

                if (onlineDeposit == null)
                {
                    throw new RegoException(DepositErrors.NotFound.ToString());
                }

                if (onlineDeposit.Status != OnlineDepositStatus.Verified)
                {
                    throw new RegoException(string.Format("The deposit has '{0}' status, so it can't be Approved", onlineDeposit.Status));
                }

                var onlineDepositEntity = new Entities.OnlineDeposit(onlineDeposit);
                var now = _paymentQueries.GetBrandDateTimeOffset(onlineDeposit.BrandId);

                var depositCommand = onlineDepositEntity.Approve(_actorInfoProvider.Actor.UserName, request.Remarks, now);
                _repository.SaveChanges();

                _serviceBus.PublishMessage(depositCommand);

                scope.Complete();
            }
        }
Пример #2
0
        public string PayNotify(OnlineDepositPayNotifyRequest request)
        {
            var transNo  = request.OrderIdOfMerchant;
            var response = "Failed";

            var hashKey = GetDepositHashKey();

            //validation
            var validationResult = new OnlineDepositPayNotifyRequestValidator(_repository, hashKey).Validate(request);

            if (!validationResult.IsValid)
            {
                throw new RegoValidationException(validationResult);
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _repository.LockOnlineDeposit(transNo);//lock data to prevent deposit multi times

                var onlineDeposit = _repository.OnlineDeposits.First(x => x.TransactionNumber == transNo);

                var onlineDepositEntity = new Entities.OnlineDeposit(onlineDeposit);

                if (onlineDepositEntity.IsApproved() == false) //prevent approve again
                {
                    var now            = _paymentQueries.GetBrandDateTimeOffset(onlineDeposit.BrandId);
                    var depositCommand = onlineDepositEntity.Approve(request, now);

                    _repository.SaveChanges();

                    _serviceBus.PublishMessage(depositCommand);
                    scope.Complete();
                }

                response = Acknowledge;
            }

            return(response);
        }