예제 #1
0
        public void Create_DeprecatedWithId()
        {
            Random random                   = new Random();
            int    randomNumber             = random.Next(0, 10000);
            var    subMerchantAccountId     = "sub_merchant_account_id_" + randomNumber;
            var    request                  = deprecatedCreateRequest(subMerchantAccountId);
            Result <MerchantAccount> result = gateway.MerchantAccount.Create(request);

            Assert.IsTrue(result.IsSuccess());

            MerchantAccount merchantAccount = result.Target;

            Assert.AreEqual(MerchantAccountStatus.PENDING, merchantAccount.Status);
            Assert.AreEqual("sandbox_master_merchant_account", merchantAccount.MasterMerchantAccount.Id);
            Assert.IsTrue(merchantAccount.IsSubMerchant);
            Assert.IsFalse(merchantAccount.MasterMerchantAccount.IsSubMerchant);
            Assert.AreEqual(subMerchantAccountId, merchantAccount.Id);
        }
예제 #2
0
        public void CreateAsync_WithoutId()
        {
            Task.Run(async () =>
#endif
        {
            var request = createRequest(null);
            Result<MerchantAccount> result = await gateway.MerchantAccount.CreateAsync(request);
            Assert.IsTrue(result.IsSuccess());

            MerchantAccount merchantAccount = result.Target;
            Assert.AreEqual(MerchantAccountStatus.PENDING, merchantAccount.Status);
            Assert.AreEqual("sandbox_master_merchant_account", merchantAccount.MasterMerchantAccount.Id);
            Assert.IsTrue(merchantAccount.IsSubMerchant);
            Assert.IsFalse(merchantAccount.MasterMerchantAccount.IsSubMerchant);
            Assert.IsTrue(merchantAccount.Id != null);
        }
#if net452
            ).GetAwaiter().GetResult();
        }
        private SignonDTO GetAccessToken(POS pos, MerchantAccount account)
        {
            MerchantAccessToken token = new MerchantAccessToken
            {
                POSSN    = pos.Sn,
                Identity = account.Username
            };

            string accessToken = AccessTokenGenerator.IssueToken(token);
            string key         = $"{RedisKeys.FiiiPOS_APP_MerchantId}:{account.Username}";

            RedisHelper.StringSet(Constant.REDIS_TOKEN_DBINDEX, key, accessToken);

            return(new SignonDTO
            {
                AccessToken = accessToken,
                SecretKey = account.SecretKey
            });
        }
예제 #4
0
        public void UpdateAsync_UpdatesAllFields()
        {
            Task.Run(async () =>
#endif
        {
            var request = deprecatedCreateRequest(null);
            Result<MerchantAccount> result = await gateway.MerchantAccount.CreateAsync(request);
            Assert.IsTrue(result.IsSuccess());
            var updateRequest = createRequest(null);
            updateRequest.TosAccepted = null;
            updateRequest.MasterMerchantAccountId = null;
            Result<MerchantAccount> updateResult = await gateway.MerchantAccount.UpdateAsync(result.Target.Id, updateRequest);
            Assert.IsTrue(updateResult.IsSuccess());
            MerchantAccount merchantAccount = updateResult.Target;
            Assert.AreEqual("Job", merchantAccount.IndividualDetails.FirstName);
            Assert.AreEqual("Leoggs", merchantAccount.IndividualDetails.LastName);
            Assert.AreEqual("*****@*****.**", merchantAccount.IndividualDetails.Email);
            Assert.AreEqual("5555551212", merchantAccount.IndividualDetails.Phone);
            Assert.AreEqual("1235", merchantAccount.IndividualDetails.SsnLastFour);
            Assert.AreEqual("193 Credibility St.", merchantAccount.IndividualDetails.Address.StreetAddress);
            Assert.AreEqual("60611", merchantAccount.IndividualDetails.Address.PostalCode);
            Assert.AreEqual("Avondale", merchantAccount.IndividualDetails.Address.Locality);
            Assert.AreEqual("IN", merchantAccount.IndividualDetails.Address.Region);
            Assert.AreEqual("1985-09-10", merchantAccount.IndividualDetails.DateOfBirth);
            Assert.AreEqual("coaterie.com", merchantAccount.BusinessDetails.LegalName);
            Assert.AreEqual("Coaterie", merchantAccount.BusinessDetails.DbaName);
            Assert.AreEqual("123456780", merchantAccount.BusinessDetails.TaxId);
            Assert.AreEqual("135 Credibility St.", merchantAccount.BusinessDetails.Address.StreetAddress);
            Assert.AreEqual("60602", merchantAccount.BusinessDetails.Address.PostalCode);
            Assert.AreEqual("Gary", merchantAccount.BusinessDetails.Address.Locality);
            Assert.AreEqual("OH", merchantAccount.BusinessDetails.Address.Region);
            Assert.AreEqual(FundingDestination.EMAIL, merchantAccount.FundingDetails.Destination);
            Assert.AreEqual("*****@*****.**", merchantAccount.FundingDetails.Email);
            Assert.AreEqual("3125551212", merchantAccount.FundingDetails.MobilePhone);
            Assert.AreEqual("122100024", merchantAccount.FundingDetails.RoutingNumber);
            Assert.AreEqual("8798", merchantAccount.FundingDetails.AccountNumberLast4);
            Assert.AreEqual("Job Leoggs OH", merchantAccount.FundingDetails.Descriptor);
        }
#if net452
            ).GetAwaiter().GetResult();
        }
예제 #5
0
        private Order Generate(MerchantAccount merchantAccount, Cryptocurrency coin, string unifiedFiatCurrency, string fiatCurrency, decimal fiatAmount, PaymentType paymentType, string merchantClientIP = null)
        {
            var order = new Order
            {
                Id                  = Guid.NewGuid(),
                OrderNo             = IdentityHelper.OrderNo(),
                MerchantAccountId   = merchantAccount.Id,
                CryptoId            = coin.Id,
                CryptoCode          = coin.Code,
                FiatAmount          = fiatAmount,
                PaymentType         = paymentType,
                FiatCurrency        = fiatCurrency,
                Status              = OrderStatus.Pending,
                Timestamp           = DateTime.UtcNow,
                ExpiredTime         = DateTime.UtcNow.AddMinutes(30),
                Markup              = merchantAccount.Markup,
                ExchangeRate        = GetExchangeRate(merchantAccount.CountryId, fiatCurrency, coin),
                UnifiedExchangeRate = GetExchangeRate(merchantAccount.CountryId, unifiedFiatCurrency, coin),
                UnifiedFiatCurrency = unifiedFiatCurrency,
                MerchantIP          = merchantClientIP
            };

            //(order.ActualFiatAmount, order.CryptoAmount, order.TransactionFee, order.ActualCryptoAmount) =
            //    CalculateAmount(amount, account.Markup, account.Receivables_Tier, order.ExchangeRate, coin);
            //(order.UnifiedFiatAmount, order.UnifiedActualFiatAmount) = CalculateUnifiedAmount(order.FiatAmount, order.ActualFiatAmount, order.UnifiedExchangeRate);
            //return order;
            var calcModel =
                CalculateAmount(fiatAmount, merchantAccount.Markup, merchantAccount.Receivables_Tier, order.ExchangeRate, coin);

            order.ActualFiatAmount   = calcModel.FiatTotalAmount;
            order.CryptoAmount       = calcModel.CryptoAmount;
            order.TransactionFee     = calcModel.TransactionFee;
            order.ActualCryptoAmount = calcModel.ActualCryptoAmount;

            var model = CalculateUnifiedAmount(calcModel.CryptoAmount, calcModel.ActualCryptoAmount, order.UnifiedExchangeRate);

            order.UnifiedFiatAmount       = model.UnifiedFiatAmount;
            order.UnifiedActualFiatAmount = model.UnifiedActualFiatAmount;
            return(order);
        }
예제 #6
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);
        }
예제 #7
0
        public Merchant(NodeWrapper node)
        {
            if (node == null)
                return;

            NodeWrapper merchantNode = node.GetNode("merchant");

            Id = merchantNode.GetString("id");
            Email = merchantNode.GetString("email");
            CompanyName = merchantNode.GetString("company-name");
            CountryCodeAlpha3 = merchantNode.GetString("country-code-alpha3");
            CountryCodeAlpha2 = merchantNode.GetString("country-code-alpha2");
            CountryCodeNumeric = merchantNode.GetString("country-code-numeric");
            CountryName = merchantNode.GetString("country-name");

            Credentials = new OAuthCredentials(node.GetNode("credentials"));

            var merchantAccountXmlNodes = merchantNode.GetList("merchant-accounts/merchant-account");
            MerchantAccounts = new MerchantAccount[merchantAccountXmlNodes.Count];
            for (int i = 0; i < merchantAccountXmlNodes.Count; i++)
            {
                MerchantAccounts[i] = new MerchantAccount(merchantAccountXmlNodes[i]);
            }
        }
예제 #8
0
 public void FiiiPOSVerifyPin(MerchantAccount account, string pin)
 {
     SecurityVerify.Verify(new PinVerifier(), SystemPlatform.FiiiPOS, account.Id.ToString(), account.PIN, pin);
 }
        public void RetrievesCurrencyIsoCode()
        {
            MerchantAccount foundMerchantAccount = gateway.MerchantAccount.Find("sandbox_master_merchant_account");

            Assert.AreEqual("USD", foundMerchantAccount.CurrencyIsoCode);
        }
예제 #10
0
        public async Task <UserManagerResponse> RegisterUserAsync(RegisterViewModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new NullReferenceException("Register Model is Null");
                }

                if (model.Password != model.ConfirmPassword)
                {
                    return new UserManagerResponse
                           {
                               Message   = "Confirm password doesn't match password",
                               IsSuccess = false,
                           }
                }
                ;

                var IdentityUser = new IdentityUser
                {
                    Email    = model.Email,
                    UserName = model.Email,
                };

                var result = await _userManager.CreateAsync(IdentityUser, model.Password);

                if (result.Succeeded)
                {
                    //register to User and Merchant table
                    var user = new User();

                    var merchant = new MerchantAccount();
                    user.Email     = model.Email;
                    user.Role      = "Merchant";
                    user.Password  = "******"; //aspNetusers Management
                    user.CreatedOn = DateTime.Now;

                    await _context.Users.AddAsync(user);

                    await _context.SaveChangesAsync();

                    merchant.UserId          = user.UserId;
                    merchant.BusinessName    = model.BusinessName;
                    merchant.BusinessPhone   = model.BusinessPhone;
                    merchant.BusinessAddress = model.BusinessAddress;
                    merchant.ApiKey          = ApiUtil.GenerateKey(); //generate random key
                    merchant.SecretKey       = "secret";              //aspnet management
                    merchant.WebHook         = model.MerchantWebHook;
                    merchant.CreatedOn       = DateTime.Now;

                    await _context.MerchantAccounts.AddAsync(merchant);

                    await _context.SaveChangesAsync();


                    return(new UserManagerResponse
                    {
                        Message = "User created successfully",
                        IsSuccess = true,
                    });
                }

                //did not succeed
                return(new UserManagerResponse
                {
                    Message = "User did not create",
                    IsSuccess = false,
                    Errors = result.Errors.Select(e => e.Description),
                });
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }
예제 #11
0
 public void Find()
 {
     MerchantAccount merchantAccount = gateway.MerchantAccount.Create(createRequest(null)).Target;
     MerchantAccount foundMerchantAccount = gateway.MerchantAccount.Find(merchantAccount.Id);
     Assert.AreEqual(merchantAccount.Id, foundMerchantAccount.Id);
 }
예제 #12
0
 private Order Generate(MerchantAccount account, Cryptocurrency coin, string unifiedFiatCurrency, decimal amount, PaymentType paymentType, string merchantClientIP = null)
 {
     return(Generate(account, coin, unifiedFiatCurrency, account.FiatCurrency, amount, paymentType, merchantClientIP));
 }
        public SignonDTO BindingAccount(string merhcantAccount, string posSN)
        {
            var             accountDac = new MerchantAccountDAC();
            MerchantAccount account    = accountDac.GetByUsername(merhcantAccount);

            SecurityVerify.Verify <BindAccountVerify>(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merhcantAccount, (model) =>
            {
                bool result = true;
                result      = result && merhcantAccount.Equals(model.MerchantAccount);
                result      = result && model.CellphoneVerified && model.PinVerified;
                if (account == null)
                {
                    return(false);
                }
                if (ValidationFlagComponent.CheckSecurityOpened(account.ValidationFlag, ValidationFlag.GooogleAuthenticator))
                {
                    result = result && model.GoogleVerified;
                }
                return(result);
            });

            var posDac = new POSDAC();

            if (account.Status == AccountStatus.Locked)
            {
                throw new CommonException(ReasonCode.ACCOUNT_LOCKED, Resources.帐号已锁定);
            }

            var pos = posDac.GetBySn(posSN);

            if (pos == null)
            {
                throw new GeneralException(Resources.SN码不存在);
            }

            if (account.POSId.HasValue)
            {
                if (account.POSId == pos.Id)
                {
                    throw new GeneralException(Resources.AccountHasBoundThisPOS);
                }
                else
                {
                    throw new GeneralException(Resources.AccountHasBoundOtherPOS);
                }
            }

            if (pos.Status)
            {
                throw new GeneralException(Resources.POSHasBoundOtherAccount);
            }

            UserAccount userAccount = null;

            if (!string.IsNullOrEmpty(account.InvitationCode))
            {
                userAccount = new UserAccountDAC().GetByInvitationCode(account.InvitationCode);
            }

            POSMerchantBindRecord posBindRecord = new POSMerchantBindRecord
            {
                POSId            = pos.Id,
                SN               = pos.Sn,
                MerchantId       = account.Id,
                MerchantUsername = account.Username,
                BindTime         = DateTime.UtcNow,
                BindStatus       = (byte)POSBindStatus.Binded
            };

            using (var scope = new TransactionScope())
            {
                account.POSId = pos.Id;
                accountDac.BindPos(account);
                posDac.ActivePOS(pos);
                new POSMerchantBindRecordDAC().Insert(posBindRecord);
                if (!string.IsNullOrEmpty(account.InvitationCode) && userAccount != null)
                {
                    ReBindInviter(posSN, account.Id, userAccount.Id, account.InvitationCode);
                }

                scope.Complete();
            }

            return(GetAccessToken(pos, account));
        }
        public SignonDTO Signup(int countryId, string cellphone, string merchantAccount, string merchantName, string posSn, string invitationCode, string pin)
        {
            SecurityVerify.Verify <FiiiPosSignUpVerify>(new CustomVerifier("FiiiPosSignUp"), SystemPlatform.FiiiPOS, $"{countryId}:{cellphone}", (model) =>
            {
                return(model.CellphoneVerified);
            });

            var country = new CountryComponent().GetById(countryId);

            if (country == null)
            {
                throw new CommonException(10000, Resources.国家不存在);
            }
            var cacheKey = $"{countryId}{cellphone}";
            var verifier = new FiiiPosRegisterVerifier();
            var dic      = verifier.GetRegisterModel(SystemPlatform.FiiiPOS, cacheKey, false);

            MerchantAccount excistAccount = new MerchantAccountDAC().GetByUsername(merchantAccount);

            if (excistAccount != null)
            {
                throw new CommonException(ReasonCode.ACCOUNT_EXISTS, Resources.帐号已存在);
            }

            UserAccount inviterAccount = new UserAccount();

            if (!string.IsNullOrEmpty(invitationCode))
            {
                inviterAccount = new UserAccountDAC().GetUserAccountByInviteCode(invitationCode);
                if (inviterAccount == null)
                {
                    throw new CommonException(ReasonCode.INVITORCODE_NOT_EXISTS, Resources.邀请码不存在);
                }
            }

            var posDac = new POSDAC();
            var pos    = posDac.GetInactivedBySn(posSn);

            if (pos == null)
            {
                throw new CommonException(ReasonCode.POSSN_ERROR, Resources.SN码不存在);
            }

            var merchantMS = new MasterSettingDAC().SelectByGroup("Merchant");

            Guid            beInvitedAccountId = Guid.NewGuid();
            MerchantAccount account            = new MerchantAccount
            {
                CountryId        = countryId,
                Cellphone        = cellphone,
                Username         = merchantAccount,
                MerchantName     = merchantName,
                PIN              = PasswordHasher.HashPassword(pin),
                Id               = beInvitedAccountId,
                POSId            = pos.Id,
                IsVerifiedEmail  = false,
                PhoneCode        = dic["PhoneCode"],
                RegistrationDate = DateTime.UtcNow,
                Status           = AccountStatus.Active,
                SecretKey        = beInvitedAccountId.ToString(),
                FiatCurrency     = dic["FiatCurrency"],
                Markup           = Convert.ToDecimal(merchantMS.First(e => e.Name == "Merchant_Markup").Value),
                Receivables_Tier = Convert.ToDecimal(merchantMS.First(e => e.Name == "Merchant_TransactionFee").Value),
                //默认开启手机验证
                ValidationFlag = (byte)ValidationFlag.Cellphone,
                InvitationCode = invitationCode
            };

            POSMerchantBindRecord posBindRecord = new POSMerchantBindRecord
            {
                POSId            = pos.Id,
                SN               = pos.Sn,
                MerchantId       = account.Id,
                MerchantUsername = merchantAccount,
                BindTime         = DateTime.UtcNow,
                BindStatus       = (byte)POSBindStatus.Binded
            };

            MerchantProfile profile = new MerchantProfile
            {
                MerchantId     = account.Id,
                Country        = account.CountryId,
                Cellphone      = account.Cellphone,
                L1VerifyStatus = VerifyStatus.Uncertified,
                L2VerifyStatus = VerifyStatus.Uncertified
            };

            MerchantProfileAgent agent = new MerchantProfileAgent();
            bool addProfileResult      = agent.AddMerchant(profile);

            if (!addProfileResult)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, "Add merchant profile error.");
            }
            int recordId = default(int);

            try
            {
                using (var scope = new TransactionScope())
                {
                    posDac.ActivePOS(pos);
                    new MerchantAccountDAC().Insert(account);
                    recordId = new POSMerchantBindRecordDAC().Insert(posBindRecord);
                    if (!string.IsNullOrEmpty(invitationCode))
                    {
                        BindInviter(posSn, beInvitedAccountId, inviterAccount.Id, invitationCode);
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                agent.RemoveMerchantById(profile);

                //LogHelper.Error(ex);
                throw;
            }

            if (!string.IsNullOrEmpty(invitationCode))
            {
                RabbitMQSender.SendMessage("InvitePosBindSuccess", new Tuple <Guid, long>(inviterAccount.Id, recordId));
            }

            verifier.DeleteCacheModel(SystemPlatform.FiiiPOS, cacheKey);

            return(GetAccessToken(pos, account));
        }
예제 #15
0
        private OrderWithdrawalFee CalculateOrderAmount(ref Order order, RedisOrderDTO orderDto, MerchantAccount account, Cryptocurrency coin)
        {
            var orderWithdrawalFee = new OrderWithdrawalFee()
            {
                Timestamp = DateTime.UtcNow
            };

            var wallet = new MerchantWalletDAC().GetByAccountId(account.Id, new CryptocurrencyDAC().GetByCode("FIII").Id);

            if (wallet == null || !wallet.SupportReceipt)
            {
                Excute(ref order);
            }
            else
            {
                var exchangeFiiiRate = GetExchangeRate(orderDto.CountryId, order.FiatCurrency, new CryptocurrencyDAC().GetById(wallet.CryptoId));
                var fiiiCoin         = new CryptocurrencyDAC().GetById(wallet.CryptoId);

                //var tempFiatActualAmount = orderDto.FiatAmount * (1 + account.Markup);
                var tempFiatActualAmount = orderDto.FiatAmount + (orderDto.FiatAmount * account.Markup).ToSpecificDecimal(4);

                var fiiiTransactionFee = ((orderDto.FiatAmount + orderDto.FiatAmount * account.Markup) * account.Receivables_Tier / exchangeFiiiRate)
                                         .ToSpecificDecimal(
                    fiiiCoin.DecimalPlace);
                if (wallet.Balance < fiiiTransactionFee)
                {
                    Excute(ref order);
                }
                else
                {
                    orderWithdrawalFee.CryptoId = fiiiCoin.Id;
                    orderWithdrawalFee.Amount   = fiiiTransactionFee;

                    order.ActualFiatAmount   = tempFiatActualAmount.ToSpecificDecimal(4);
                    order.CryptoAmount       = ((orderDto.FiatAmount + orderDto.FiatAmount * account.Markup) / order.ExchangeRate).ToSpecificDecimal(coin.DecimalPlace);
                    order.TransactionFee     = 0;
                    order.ActualCryptoAmount = order.CryptoAmount;

                    var model = CalculateUnifiedAmount(order.CryptoAmount, order.ActualCryptoAmount, order.UnifiedExchangeRate);
                    order.UnifiedFiatAmount       = model.UnifiedFiatAmount;
                    order.UnifiedActualFiatAmount = model.UnifiedActualFiatAmount;
                }
            }
            void Excute(ref Order inOrder)
            {
                var calcModel =
                    CalculateAmount(orderDto.FiatAmount, account.Markup, account.Receivables_Tier, inOrder.ExchangeRate, coin);

                inOrder.ActualFiatAmount   = calcModel.FiatTotalAmount;
                inOrder.CryptoAmount       = calcModel.CryptoAmount;
                inOrder.TransactionFee     = calcModel.TransactionFee;
                inOrder.ActualCryptoAmount = calcModel.ActualCryptoAmount;

                var model = CalculateUnifiedAmount(inOrder.CryptoAmount, inOrder.ActualCryptoAmount, inOrder.UnifiedExchangeRate);

                inOrder.UnifiedFiatAmount       = model.UnifiedFiatAmount;
                inOrder.UnifiedActualFiatAmount = model.UnifiedActualFiatAmount;

                orderWithdrawalFee.CryptoId = inOrder.CryptoId;
                orderWithdrawalFee.Amount   = 0;
            }

            return(orderWithdrawalFee);
        }