Пример #1
0
        public void ModifyCellphone(Guid accountId, string cellphone)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            SecurityVerify.Verify <ModifyCellphoneVerify>(new CustomVerifier("ModifyCellphone"), SystemPlatform.FiiiPOS, account.Id.ToString(), (model) =>
            {
                return(model.PinVerified && model.NewCellphoneVerified && model.CombinedVerified);
            });

            if (account.Cellphone == cellphone)
            {
                throw new CommonException(10000, Resources.新手机号码不能与原来的一致);
            }

            //修改手机号
            dac.UpdateCellphone(accountId, cellphone);

            var agent   = new MerchantProfileAgent();
            var profile = new MerchantProfile
            {
                MerchantId = accountId,
                Cellphone  = cellphone,
                Country    = account.CountryId
            };

            agent.UpdateCellphone(profile);
        }
Пример #2
0
        public void SendUpdateNewEmailCode(Guid accountId, string emailAddress)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            if (account.Email == emailAddress)
            {
                throw new CommonException(ReasonCode.ORIGIN_NEW_EMAIL_SAME, Resources.新邮箱不能和原来的邮箱一致);
            }

            var accountByEmail = dac.GetByEmail(emailAddress);

            if (accountByEmail != null && accountByEmail.Id != accountId)
            {
                throw new CommonException(ReasonCode.EMAIL_BINDBYOTHER, Resources.此邮箱已经绑定到其他邮箱);
            }

            string subject = Resources.验证码邮箱标题;

            SecurityVerify.SendCode(new UpdateEmailNewVerifier(), SystemPlatform.FiiiPOS, accountId.ToString(), emailAddress, subject);
            var model = SecurityVerify.GetModel <FiiiPosUpdateEmailVerify>(new CustomVerifier("UpdateEmail"), SystemPlatform.FiiiPOS, accountId.ToString());

            model.NewEmail = emailAddress;
            SecurityVerify.SetModel(new CustomVerifier("UpdateEmail"), SystemPlatform.FiiiPOS, accountId.ToString(), model);
        }
Пример #3
0
        /// <summary>
        /// 发送原邮箱验证码 20180523
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="emailAddress"></param>
        public async Task SendVerifyOriginalEmail(Guid accountId, string emailAddress)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            var accountByEmail = dac.GetByEmail(emailAddress);

            if (accountByEmail != null && accountByEmail.Id != accountId)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.EMAIL_BINDED, "该邮箱已绑定到其他账户");
            }

            string key  = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";
            string code = RandomAlphaNumericGenerator.GenerateAllNumber(6);

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "AccountId", accountId.ToString() },
                { "EmailAddress", emailAddress },
                { "Code", code }
            };

            RedisHelper.Set(key, dic, new TimeSpan(0, Constant.EMAIL_EXPIRED_TIME, 0));

            string subject = Resources.验证码邮箱标题;
            string content = string.Format(Resources.验证码邮箱模版, code, Constant.EMAIL_EXPIRED_TIME);

            EmailAgent agent = new EmailAgent();
            await agent.SendAsync(emailAddress, subject, content, 5);
        }
Пример #4
0
        public void ModifyCellphone(Guid accountId, string cellphone, string smsToken, string token, string gToken)
        {
            //
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            if (account.Cellphone == cellphone)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.CELLPHONE_MUST_BE_DIFFERENT, "新手机号码不能与原来的一致");
            }

            //验证短信码
            SecurityVerification sv = new SecurityVerification(SystemPlatform.FiiiPOS);

            sv.VerifyToken(accountId, smsToken, SecurityMethod.CellphoneCode);

            //验证pin码
            sv.VerifyToken(accountId, token, SecurityMethod.Pin);

            //验证google token 20180521
            new SecurityVerification(SystemPlatform.FiiiPOS).VerifyToken(accountId, gToken, SecurityMethod.SecurityValidate);

            //修改手机号
            dac.UpdateCellphone(accountId, cellphone);
        }
Пример #5
0
        public void BindMerchantAccount(BindMerchantAuthIM im, Guid merchantId)
        {
            SecurityVerify.Verify <BindGoogleAuth>(new CustomVerifier("BindGoogleAuth"), SystemPlatform.FiiiPOS, merchantId.ToString(), (model) =>
            {
                return(model.PinVerified && model.GoogleVerified && model.CombinedVerified);
            });

            var mDAC     = new MerchantAccountDAC();
            var merchant = mDAC.GetById(merchantId);

            if (merchant == null)
            {
                throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, Resources.用户不存在);
            }

            if (string.IsNullOrEmpty(merchant.AuthSecretKey))
            {
                var oldFlag = merchant.ValidationFlag;
                var newFlag = ValidationFlagComponent.AddValidationFlag(oldFlag, ValidationFlag.GooogleAuthenticator);
                mDAC.UpdateGoogleAuthencator(merchant.Id, im.SecretKey, newFlag);
            }
            else
            {
                mDAC.SetAuthSecretById(merchant.Id, im.SecretKey);
            }
        }
        public MerchantAccount GetById(Guid accountId)
        {
            MerchantAccountDAC dac = new MerchantAccountDAC();

            MerchantAccount account = dac.GetById(accountId);

            return(account);
        }
Пример #7
0
        public void VerifyUpdateEmailPin(Guid accountId, string pin)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            SecurityVerify.Verify(new PinVerifier(), SystemPlatform.FiiiPOS, account.Id.ToString(), account.PIN, pin);
            var model = SecurityVerify.GetModel <FiiiPosUpdateEmailVerify>(new CustomVerifier("UpdateEmail"), SystemPlatform.FiiiPOS, account.Id.ToString());

            model.PinVerified = true;
            SecurityVerify.SetModel(new CustomVerifier("UpdateEmail"), SystemPlatform.FiiiPOS, account.Id.ToString(), model);
        }
Пример #8
0
        /// <summary>
        /// 发送验证原邮箱的验证码
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="emailAddress"></param>
        public void SendUpdateOriginalEmailCode(Guid accountId, string emailAddress)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            if (account.Email != emailAddress)
            {
                throw new CommonException(ReasonCode.EMAIL_NOT_MATCH, Resources.原邮箱地址不正确);
            }

            string subject = Resources.验证码邮箱标题;

            SecurityVerify.SendCode(new UpdateEmailOriginalVerifier(), SystemPlatform.FiiiPOS, accountId.ToString(), emailAddress, subject);
        }
        public void UnbindingAccount(Guid merchantAccountId)
        {
            SecurityVerify.Verify <UnBindAccountVerify>(new CustomVerifier("UnBindAccount"), SystemPlatform.FiiiPOS, merchantAccountId.ToString(), (model) =>
            {
                return(model.PinVerified && model.CombinedVerified);
            });

            var accountDAC = new MerchantAccountDAC();
            var account    = accountDAC.GetById(merchantAccountId);

            var posDAC    = new POSDAC();
            var pos       = posDAC.GetById(account.POSId.Value);
            var recordId  = new POSMerchantBindRecordDAC().GetByMerchantId(merchantAccountId).Id;
            var invitorId = new InviteRecordDAC().GetInvitorIdBySn(pos.Sn);

            account.POSId = null;
            bool bindingGoogleAuth = !string.IsNullOrEmpty(account.AuthSecretKey);
            bool openedGoogleAuth  =
                ValidationFlagComponent.CheckSecurityOpened(account.ValidationFlag, ValidationFlag.GooogleAuthenticator);

            if (bindingGoogleAuth && !openedGoogleAuth)
            {
                account.ValidationFlag =
                    ValidationFlagComponent.AddValidationFlag(account.ValidationFlag, ValidationFlag.GooogleAuthenticator);
            }

            using (var scope = new TransactionScope())
            {
                accountDAC.UnbindingAccount(account);
                new POSDAC().InactivePOS(pos);
                new POSMerchantBindRecordDAC().UnbindRecord(account.Id, pos.Id);
                if (!string.IsNullOrEmpty(account.InvitationCode))
                {
                    UnBindInviter(pos.Sn);
                }

                scope.Complete();
            }
            //Task.Run(() => RemoveRegInfoByUserId(merchantAccountId));
            if (!string.IsNullOrEmpty(account.InvitationCode))
            {
                RabbitMQSender.SendMessage("UnBindingAccount", new Tuple <Guid, long>(invitorId, recordId));
            }

            RemoveRegInfoByUserId(merchantAccountId);
        }
Пример #10
0
        /// <summary>
        /// 验证原邮箱验证码
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="emailAddress"></param>
        /// <param name="code"></param>
        public void VerifyOriginalEmail(Guid accountId, string emailAddress, string code)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            string key = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";
            Dictionary <string, string> dic = RedisHelper.Get <Dictionary <string, string> >(key);

            if (dic == null)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.EMAIL_CODE_EXPIRE, "验证码已过期");
            }
            if (dic["Code"] != code || dic["EmailAddress"] != emailAddress)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.WRONG_EMAIL_CODE_ENTERRED, "验证码有误");
            }
        }
Пример #11
0
        public void VerifyUpdateOriginalEmail(Guid accountId, string emailAddress, string code)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            if (account.Email != emailAddress)
            {
                throw new CommonException(ReasonCode.EMAIL_NOT_MATCH, Resources.原邮箱地址不正确);
            }

            SecurityVerify.Verify(new UpdateEmailOriginalVerifier(), SystemPlatform.FiiiPOS, accountId.ToString(), code);
            var model = new FiiiPosUpdateEmailVerify
            {
                OriginalEmailVerified = true
            };

            SecurityVerify.SetModel(new CustomVerifier("UpdateEmail"), SystemPlatform.FiiiPOS, accountId.ToString(), model);
        }
Пример #12
0
        public int GetCountByIdentityDocNo(Guid merchantId, string IdentityDocNo)
        {
            MerchantAccountDAC accountDAC = new MerchantAccountDAC();
            var account = accountDAC.GetById(merchantId);

            var server = ProfileFactory.GetByCountryId(account.CountryId);

            if (server == null)
            {
                throw new InvalidProfileServiceException();
            }
            else
            {
                MerchantProfileRPC merchantProfileDAC = new MerchantProfileRPC(server);

                return(merchantProfileDAC.GetCountByIdentityDocNo(IdentityDocNo));
            }
        }
Пример #13
0
        public void OpenMerchantAccount(Guid merchantId)
        {
            SecurityVerify.Verify <OpenGoogleAuth>(new CustomVerifier("OpenGoogleAuth"), SystemPlatform.FiiiPOS, merchantId.ToString(), (model) =>
            {
                return(model.GoogleVerified);
            });
            var mDAC     = new MerchantAccountDAC();
            var merchant = mDAC.GetById(merchantId);

            if (merchant == null)
            {
                throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, Resources.用户不存在);
            }

            var oldFlag = merchant.ValidationFlag;
            var newFlag = ValidationFlagComponent.AddValidationFlag(oldFlag, ValidationFlag.GooogleAuthenticator);

            mDAC.UpdateGoogleAuthencator(merchant.Id, newFlag);
        }
Пример #14
0
        public DepositAddressInfo GetDepositAddressById(Guid accountId, int cryptoId)
        {
            var crypto = new CryptocurrencyDAC().GetById(cryptoId);

            if (crypto == null)
            {
                throw new CommonException(ReasonCode.RECORD_NOT_EXIST, Resources.支持的币种);
            }

            if (!crypto.Status.HasFlag(CryptoStatus.Deposit))
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, Resources.CurrencyForbidden);
            }

            if (crypto.Enable == (byte)CurrencyStatus.Forbidden)
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, Resources.CurrencyForbidden);
            }

            var dac    = new MerchantWalletDAC();
            var wallet = dac.GetByAccountId(accountId, cryptoId) ?? GenerateWallet(accountId, cryptoId, crypto.Code);

            if (string.IsNullOrEmpty(wallet.Address))
            {
                var accountDAC = new MerchantAccountDAC();
                var account    = accountDAC.GetById(accountId);

                var result = new FiiiFinanceAgent().CreateWallet(crypto.Code, account.Id, AccountTypeEnum.Merchant, account.Email, $"{account.PhoneCode}{account.Cellphone}");
                if (string.IsNullOrWhiteSpace(result.Address))
                {
                    throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.FailedGenerateAddress);
                }

                wallet.Address = result.Address;
                wallet.Tag     = result.DestinationTag;

                dac.UploadAddress(wallet.Id, wallet.Address, wallet.Tag);
            }

            return(new DepositAddressInfo {
                Address = wallet.Address, Tag = wallet.Tag, NeedTag = crypto.NeedTag
            });
        }
        public void ModifyPIN(Guid accountId, string pin)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            SecurityVerify.Verify <UpdatePinVerify>(new CustomVerifier("ModifyPIN"), SystemPlatform.FiiiPOS, account.Id.ToString(), (model) =>
            {
                return(model.PinVerified && model.CombinedVerified);
            });


            if (PasswordHasher.VerifyHashedPassword(account.PIN, pin))
            {
                throw new CommonException(ReasonCode.PIN_MUST_BE_DIFFERENT, Resources.新PIN不能与原PIN一样);
            }

            account.PIN = PasswordHasher.HashPassword(pin);
            dac.UpdatePIN(account);
        }
Пример #16
0
        public bool ModifyIdentity(MerchantProfile profile)
        {
            MerchantAccountDAC accountDAC = new MerchantAccountDAC();
            var account = accountDAC.GetById(profile.MerchantId);

            if (account == null)
            {
                return(false);
            }
            var server = ProfileFactory.GetByCountryId(account.CountryId);

            if (server == null)
            {
                throw new InvalidProfileServiceException();
            }
            else
            {
                MerchantProfileRPC dac = new MerchantProfileRPC(server);
                return(dac.ModifyIdentity(profile));
            }
        }
Пример #17
0
        public void ResetPIN(Guid accountId, string pin)
        {
            SecurityVerify.Verify <ResetPinVerify>(new CustomVerifier("ResetPin"), SystemPlatform.FiiiPOS, accountId.ToString(), (model) =>
            {
                return(model.CombinedVerified);
            });

            MerchantAccountDAC mad     = new MerchantAccountDAC();
            MerchantAccount    account = mad.GetById(accountId);

            if (PasswordHasher.VerifyHashedPassword(account.PIN, pin))
            {
                throw new CommonException(ReasonCode.PIN_MUST_BE_DIFFERENT, Resources.新PIN不能与原PIN一样);
            }
            MerchantAccount ma = new MerchantAccount()
            {
                Id  = accountId,
                PIN = PasswordHasher.HashPassword(pin)
            };

            mad.UpdatePIN(ma);
        }
Пример #18
0
        /// <summary>
        /// 商家Web版修改认证信息
        /// </summary>
        /// <param name="merchantId"></param>
        /// <param name="companyName"></param>
        /// <param name="licenseNo"></param>
        /// <param name="businessLicense"></param>
        /// <returns></returns>
        public bool UpdateMerchantLicense(Guid merchantId, string companyName, string licenseNo, Guid businessLicense)
        {
            MerchantAccountDAC accountDAC = new MerchantAccountDAC();
            var account = accountDAC.GetById(merchantId);

            if (account == null)
            {
                return(false);
            }
            var server = ProfileFactory.GetByCountryId(account.CountryId);

            if (server == null)
            {
                MerchantProfileDAC dac = new MerchantProfileDAC();
                return(dac.UpdateMerchantLicense(merchantId, companyName, licenseNo, businessLicense));
            }
            else
            {
                MerchantProfileRPC dac = new MerchantProfileRPC(server);
                return(dac.UpdateMerchantLicense(merchantId, companyName, licenseNo, businessLicense));
            }
        }
Пример #19
0
        public bool UpdateL2VerifyStatus(Guid id, VerifyStatus verifyStatus, string remark)
        {
            bool result = false;
            MerchantAccountDAC merchantAccountDAC = new MerchantAccountDAC();
            var merchantAccount = merchantAccountDAC.GetById(id);

            if (merchantAccount == null)
            {
                return(result);//查无此人
            }
            var router = ProfileFactory.GetByCountryId(merchantAccount.CountryId);

            if (router == null)
            {
                throw new InvalidProfileServiceException();
            }
            else
            {
                MerchantProfileRPC dac = new MerchantProfileRPC(router);
                result = dac.UpdateL2VerifyStatus(id, verifyStatus, remark);
            }
            return(result);
        }
Пример #20
0
        /// <summary>
        /// 获得商家Profile信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MerchantProfile GetMerchantProfile(Guid id)
        {
            MerchantAccountDAC merchantAccountDAC = new MerchantAccountDAC();
            var merchantAccount = merchantAccountDAC.GetById(id);

            if (merchantAccount == null)
            {
                return(null);//查无此人
            }
            var             router  = ProfileFactory.GetByCountryId(merchantAccount.CountryId);
            MerchantProfile profile = null;

            if (router == null)
            {
                throw new InvalidProfileServiceException();
            }
            else
            {
                MerchantProfileRPC dac = new MerchantProfileRPC(router);
                profile = dac.GetById(id);
            }
            return(profile);
        }
Пример #21
0
        public ProfileDTO GetProfile(Guid accountId)
        {
            var dac   = new MerchantAccountDAC();
            var agent = new MerchantProfileAgent();

            var account = dac.GetById(accountId);
            var profile = agent.GetMerchantProfile(accountId);
            var pos     = new POSDAC().GetById(account.POSId.Value);
            var country = new CountryComponent().GetById(account.CountryId);

            var result = new ProfileDTO
            {
                MerchantAccount    = account.Username,
                LastName           = profile.LastName,
                FirstName          = profile.FirstName,
                IdentityDocNo      = profile.IdentityDocNo,
                IdentityDocType    = (profile.IdentityDocType != IdentityDocType.IdentityCard && profile.IdentityDocType != IdentityDocType.Passport) ? IdentityDocType.IdentityCard : profile.IdentityDocType,
                FrontIdentityImage = profile.FrontIdentityImage,
                BackIdentityImage  = profile.BackIdentityImage,
                HandHoldWithCard   = profile.HandHoldWithCard,
                MerchantName       = account.MerchantName,
                CompanyName        = profile?.CompanyName,
                Email          = account.Email,
                Cellphone      = $"{account.PhoneCode} {account.Cellphone}",
                PosSn          = pos.Sn,
                Country        = country.Name,
                L1VerifyStatus = (int)(profile?.L1VerifyStatus ?? 0),
                L2VerifyStatus = (int)(profile?.L2VerifyStatus ?? 0),
                Address1       = profile?.Address1,
                Address2       = profile?.Address2,
                Postcode       = profile?.Postcode,
                City           = profile?.City,
                State          = profile?.State
            };

            return(result);
        }
Пример #22
0
        public bool UpdateAddress(Guid merchantId, Address address)
        {
            try
            {
                MerchantAccountDAC accountDAC = new MerchantAccountDAC();
                var account = accountDAC.GetById(merchantId);

                var server = ProfileFactory.GetByCountryId(account.CountryId);
                if (server == null)
                {
                    throw new InvalidProfileServiceException();
                }
                else
                {
                    MerchantProfileRPC merchantProfileDAC = new MerchantProfileRPC(server);
                    //赋值
                    return(merchantProfileDAC.UpdateAddress(address));
                }
            }
            catch
            {
                return(false);
            }
        }
Пример #23
0
        public void ModifyEmail(Guid accountId, string code, string token)
        {
            string originalKey = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";

            string key = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";
            Dictionary <string, string> dic = RedisHelper.Get <Dictionary <string, string> >(key);

            if (dic == null)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.EMAIL_CODE_EXPIRE, "验证码已过期");
            }
            if (dic["Code"] != code)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.WRONG_EMAIL_CODE_ENTERRED, "验证码有误");
            }

            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            //SecurityVerify.Verify<PinVerifier>(SystemPlatform.FiiiPOSWeb, FiiipayBusiness.Common, accountId.ToString(), token, account.PIN);
            dac.UpdateEmail(accountId, dic["EmailAddress"]);

            RedisHelper.KeyDelete(key);
        }
Пример #24
0
        public string CreateOrder(Guid merchantAccountId, string fiatCurrency, int cryptoId, decimal amount, PaymentType paymentType, string userToken, string clientIP)
        {
            var accountDAC = new MerchantAccountDAC();

            var account = accountDAC.GetById(merchantAccountId);

            if (!account.IsAllowAcceptPayment)
            {
                throw new CommonException(ReasonCode.Not_Allow_Withdrawal, Resources.禁止收款);
            }

            var coin = new CryptocurrencyDAC().GetById(cryptoId);

            if (!coin.Status.HasFlag(CryptoStatus.Pay))
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, Resources.CurrencyForbidden);
            }

            if (coin.Enable == (byte)CurrencyStatus.Forbidden)
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, Resources.CurrencyForbidden);
            }

            var order = new RedisOrderDTO()
            {
                FiatAmount   = amount,
                CryptoId     = cryptoId,
                FiatCurrency = fiatCurrency,
                MerchantGuid = account.Id,
                OrderNo      = NumberGenerator.GenerateUnixOrderNo(),
                CountryId    = account.CountryId,
                Markup       = account.Markup,
                Type         = paymentType,
                UserId       = Guid.Empty
            };

            Guid?userAccountId = null;

            if (!string.IsNullOrEmpty(userToken))
            {
                if (!userToken.StartsWith(Constant.PAYMENT_CODE_PREFIX))
                {
                    throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.无效的用户Token);
                }

                var paymentInfo = RedisHelper.Get <PaymentCodeDTO>(
                    Constant.REDIS_PAYMENT_CODE_DBINDEX,
                    $"{Constant.REDIS_PAYMENT_CODE_PREFIX}{userToken}");
                if (paymentInfo == null)
                {
                    throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.无效的用户Token);
                }
                userAccountId = paymentInfo.UserId;
            }
            if (userAccountId.HasValue)
            {
                order.UserId = userAccountId.Value;

                SendPayOrderModel model = new SendPayOrderModel();
                model.OrderNo       = order.OrderNo;
                model.UserAccountId = userAccountId.Value.ToString();

                MerchantMSMQ.PubPayOrder(model, 0);
            }
            RedisHelper.StringSet($"fiiipos:order:{ order.OrderNo}", JsonConvert.SerializeObject(order), TimeSpan.FromMinutes(30));
            return(order.OrderNo);
        }
Пример #25
0
        public void Refund(Guid accountId, string orderNo, string pinToken)
        {
            var merchantAccountDAC = new MerchantAccountDAC();
            var merchantAccount    = merchantAccountDAC.GetById(accountId);

            if (merchantAccount == null)
            {
                return;
            }

            new SecurityVerification(SystemPlatform.FiiiPOS).VerifyToken(merchantAccount.Id, pinToken, SecurityMethod.Pin);
            var orderDac = new OrderDAC();

            var order = orderDac.GetByOrderNo(orderNo);

            if (order == null)
            {
                throw new CommonException(10000, Resources.订单不存在);
            }

            if (merchantAccount.Id != order.MerchantAccountId)
            {
                return;
            }

            if (order.Status != OrderStatus.Completed)
            {
                throw new CommonException(10000, Resources.订单状态异常);
            }

            if (DateTime.UtcNow.AddDays(-3) > order.PaymentTime.Value)
            {
                throw new CommonException(10000, Resources.订单超过三天不能退款);
            }

            var merchantWalletDAC = new MerchantWalletDAC();
            var userWalletDAC     = new UserWalletDAC();

            var merchantWallet = merchantWalletDAC.GetByAccountId(order.MerchantAccountId, order.CryptoId);

            if (merchantWallet == null)
            {
                throw new CommonException(10000, Resources.商户不支持的币种);
            }

            if (merchantWallet.Balance < order.ActualCryptoAmount)
            {
                throw new CommonException(10000, Resources.余额不足);
            }

            var userWallet = userWalletDAC.GetByAccountId(order.UserAccountId.Value, order.CryptoId);

            if (userWallet == null)
            {
                throw new CommonException(10000, Resources.用户不支持的币种);
            }
            var orderWithdrawalFee = new OrderWithdrawalFeeDAC().GetByOrderId(order.Id);

            if (orderWithdrawalFee != null && orderWithdrawalFee.Amount > 0)
            {
                var merchantOrderWithdrawalFeeWallet = merchantWalletDAC.GetByAccountId(order.MerchantAccountId, orderWithdrawalFee.CryptoId);
                using (var scope = new TransactionScope())
                {
                    merchantWalletDAC.Decrease(merchantAccount.Id, order.CryptoId, order.ActualCryptoAmount);
                    new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                    {
                        WalletId  = merchantWallet.Id,
                        Action    = "REFUND",
                        Amount    = -order.ActualCryptoAmount,
                        Balance   = merchantWallet.Balance - order.ActualCryptoAmount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund to order({order.OrderNo})"
                    });

                    merchantWalletDAC.Increase(merchantAccount.Id, orderWithdrawalFee.CryptoId, orderWithdrawalFee.Amount);
                    new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                    {
                        WalletId  = merchantOrderWithdrawalFeeWallet.Id,
                        Action    = "REFUND",
                        Amount    = orderWithdrawalFee.Amount,
                        Balance   = merchantWallet.Balance - orderWithdrawalFee.Amount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund to order({order.OrderNo})"
                    });

                    userWalletDAC.Increase(order.UserAccountId.Value, order.CryptoId, order.CryptoAmount);
                    new UserWalletStatementDAC().Insert(new UserWalletStatement
                    {
                        WalletId  = userWallet.Id,
                        Action    = "REFUND",
                        Amount    = order.CryptoAmount,
                        Balance   = userWallet.Balance + order.CryptoAmount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund from order({order.OrderNo})"
                    });

                    order.Status    = OrderStatus.Refunded;
                    order.Timestamp = DateTime.UtcNow;
                    orderDac.UpdateStatus(order);

                    new RefundDAC().Insert(new Refund
                    {
                        OrderId   = order.Id,
                        Status    = RefundStatus.Completed,
                        Timestamp = DateTime.UtcNow
                    });

                    scope.Complete();
                }
            }
            else
            {
                using (var scope = new TransactionScope())
                {
                    merchantWalletDAC.Decrease(merchantAccount.Id, order.CryptoId, order.ActualCryptoAmount);
                    new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                    {
                        WalletId  = merchantWallet.Id,
                        Action    = "REFUND",
                        Amount    = -order.ActualCryptoAmount,
                        Balance   = merchantWallet.Balance - order.ActualCryptoAmount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund to order({order.OrderNo})"
                    });

                    userWalletDAC.Increase(order.UserAccountId.Value, order.CryptoId, order.CryptoAmount);
                    new UserWalletStatementDAC().Insert(new UserWalletStatement
                    {
                        WalletId  = userWallet.Id,
                        Action    = "REFUND",
                        Amount    = order.CryptoAmount,
                        Balance   = userWallet.Balance + order.CryptoAmount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund from order({order.OrderNo})"
                    });

                    order.Status = OrderStatus.Refunded;
                    //order.Timestamp = DateTime.UtcNow;
                    orderDac.UpdateStatus(order);

                    new RefundDAC().Insert(new Refund
                    {
                        OrderId   = order.Id,
                        Status    = RefundStatus.Completed,
                        Timestamp = DateTime.UtcNow
                    });

                    scope.Complete();
                }
            }

            MerchantMSMQ.PubRefundOrder(order.OrderNo, 0);
        }
Пример #26
0
        /// <summary>
        /// 获得MerchantProfile+Account信息体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MerchantProfileSet GetMerchantProfileSet(Guid id)
        {
            MerchantProfileSet profileSet = new MerchantProfileSet();
            //使用Id查询本库的基本信息
            MerchantAccountDAC merchantAccountDAC = new MerchantAccountDAC();
            var merchantAccount = merchantAccountDAC.GetById(id);

            if (merchantAccount == null)
            {
                return(null);//查无此人
            }
            //赋值
            profileSet.Id           = merchantAccount.Id;
            profileSet.Cellphone    = merchantAccount.Cellphone;
            profileSet.Username     = merchantAccount.Username;
            profileSet.MerchantName = merchantAccount.MerchantName;
            //profileSet.IsVerified = merchantAccount.IsVerified;
            profileSet.POSId = merchantAccount.POSId;
            //profileSet.BeaconId = merchantAccount.BeaconId;
            profileSet.Email            = merchantAccount.Email;
            profileSet.IsVerifiedEmail  = merchantAccount.IsVerifiedEmail;
            profileSet.CountryId        = merchantAccount.CountryId;
            profileSet.RegistrationDate = merchantAccount.RegistrationDate;
            profileSet.Photo            = merchantAccount.Photo;
            profileSet.PIN                  = merchantAccount.PIN;
            profileSet.SecretKey            = merchantAccount.SecretKey;
            profileSet.IsAllowWithdrawal    = merchantAccount.IsAllowWithdrawal;
            profileSet.IsAllowAcceptPayment = merchantAccount.IsAllowAcceptPayment;
            profileSet.FiatCurrency         = merchantAccount.FiatCurrency;
            profileSet.AuthSecretKey        = merchantAccount.AuthSecretKey;
            profileSet.ValidationFlag       = merchantAccount.ValidationFlag;

            //使用基本信息中的国别匹配kyc服务器的位置
            if (merchantAccount.POSId.HasValue)
            {
                POS pos = new POSDAC().GetById(merchantAccount.POSId.Value);
                if (pos != null)
                {
                    profileSet.SN = pos.Sn;
                }
            }
            var             server          = ProfileFactory.GetByCountryId(merchantAccount.CountryId);
            MerchantProfile merchantProfile = null;

            if (server == null)
            {
                //查询HK数据库
                MerchantProfileDAC merchantProfileDAC = new MerchantProfileDAC();
                //赋值
                merchantProfile = merchantProfileDAC.GetById(id);
            }
            else
            {
                MerchantProfileRPC merchantProfileDAC = new MerchantProfileRPC(server);
                //赋值
                merchantProfile = merchantProfileDAC.GetById(id);
            }
            if (merchantProfile != null)
            {
                profileSet.Address1             = merchantProfile.Address1;
                profileSet.Address2             = merchantProfile.Address2;
                profileSet.City                 = merchantProfile.City;
                profileSet.L1VerifyStatus       = merchantProfile.L1VerifyStatus;
                profileSet.L2VerifyStatus       = merchantProfile.L2VerifyStatus;
                profileSet.Postcode             = merchantProfile.Postcode;
                profileSet.Country              = merchantProfile.Country;
                profileSet.BusinessLicenseImage = merchantProfile.BusinessLicenseImage;
                profileSet.LicenseNo            = merchantProfile.LicenseNo;
                profileSet.CompanyName          = merchantProfile.CompanyName;
                profileSet.IdentityDocNo        = merchantProfile.IdentityDocNo;
                profileSet.IdentityDocType      = merchantProfile.IdentityDocType;
                profileSet.FirstName            = merchantProfile.FirstName;
                profileSet.LastName             = merchantProfile.LastName;
                profileSet.BackIdentityImage    = merchantProfile.BackIdentityImage;
                profileSet.FrontIdentityImage   = merchantProfile.FrontIdentityImage;
                profileSet.HandHoldWithCard     = merchantProfile.HandHoldWithCard;
            }

            return(profileSet);
        }