Example #1
0
        public async Task <CustomerToken> Create(Customer customer)
        {
            try
            {
                customer.RegistrationDateTimeInUtc = DateTime.UtcNow;

                var success = await customerRepository.Create(customer);

                if (success)
                {
                    var token = await tokenService.Create(customer);

                    CustomerToken customerToken = new CustomerToken
                    {
                        RegistrationDate = customer.RegistrationDateTimeInUtc,
                        Token            = token.Value
                    };

                    return(customerToken);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                Address billingAddress = new Address();
                billingAddress.AdditionalInfo = "Suite II";
                billingAddress.City           = "Monument Valley";
                billingAddress.CountryCode    = "US";
                billingAddress.HouseNumber    = "1";
                billingAddress.State          = "Utah";
                billingAddress.Street         = "Desertroad";
                billingAddress.Zip            = "84536";

                CompanyInformation companyInformation = new CompanyInformation();
                companyInformation.Name = "Acme Labs";

                PersonalNameToken name = new PersonalNameToken();
                name.FirstName     = "Wile";
                name.Surname       = "Coyote";
                name.SurnamePrefix = "E.";

                PersonalInformationToken personalInformation = new PersonalInformationToken();
                personalInformation.Name = name;

                CustomerToken customer = new CustomerToken();
                customer.BillingAddress      = billingAddress;
                customer.CompanyInformation  = companyInformation;
                customer.MerchantCustomerId  = "1234";
                customer.PersonalInformation = personalInformation;

                BankAccountBban bankAccountBban = new BankAccountBban();
                bankAccountBban.AccountNumber = "000000123456";
                bankAccountBban.BankCode      = "05428";
                bankAccountBban.BranchCode    = "11101";
                bankAccountBban.CheckDigit    = "X";
                bankAccountBban.CountryCode   = "IT";

                TokenNonSepaDirectDebitPaymentProduct705SpecificData paymentProduct705SpecificData = new TokenNonSepaDirectDebitPaymentProduct705SpecificData();
                paymentProduct705SpecificData.AuthorisationId = "123456";
                paymentProduct705SpecificData.BankAccountBban = bankAccountBban;

                MandateNonSepaDirectDebit mandate = new MandateNonSepaDirectDebit();
                mandate.PaymentProduct705SpecificData = paymentProduct705SpecificData;

                TokenNonSepaDirectDebit nonSepaDirectDebit = new TokenNonSepaDirectDebit();
                nonSepaDirectDebit.Customer = customer;
                nonSepaDirectDebit.Mandate  = mandate;

                CreateTokenRequest body = new CreateTokenRequest();
                body.NonSepaDirectDebit = nonSepaDirectDebit;
                body.PaymentProductId   = 705;

                CreateTokenResponse response = await client.Merchant("merchantId").Tokens().Create(body);
            }
#pragma warning restore 0168
        }
        public void CreateTokenForCustomerPasswordReset()
        {
            IClient       commerceToolsClient = this.customerFixture.GetService <IClient>();
            Customer      customer            = this.customerFixture.CreateCustomer();
            CustomerToken customerToken       = commerceToolsClient.ExecuteAsync(new CreateTokenForCustomerPasswordResetCommand(customer.Email)).Result as CustomerToken;

            this.customerFixture.CustomersToDelete.Add(customer);
            Assert.NotNull(customerToken);
        }
        public void CreateTokenForCustomerEmailVerification()
        {
            IClient       commerceToolsClient = this.customerFixture.GetService <IClient>();
            Customer      customer            = this.customerFixture.CreateCustomer();
            CustomerToken customerToken       = commerceToolsClient.ExecuteAsync(new CreateTokenForCustomerEmailVerificationCommand(customer.Id, 10, customer.Version)).Result as CustomerToken;

            this.customerFixture.CustomersToDelete.Add(customer);
            Assert.NotNull(customerToken);
        }
Example #5
0
 public void AddCustomerToken(CustomerToken customerToken)
 {
     if (!_jwtConfig.AllowMultipleLoginsFromTheSameCustomer)
     {
         InvalidateCustomerTokens(customerToken.CustomerId);
     }
     DeleteTokensWithSameRefreshTokenSource(customerToken.RefreshTokenIdHashSource);
     _customerTokenRepository.Insert(customerToken);
 }
        public void VerifyCustomerEmail()
        {
            IClient       commerceToolsClient = this.customerFixture.GetService <IClient>();
            Customer      customer            = this.customerFixture.CreateCustomer();
            CustomerToken customerToken       = commerceToolsClient.ExecuteAsync(new CreateTokenForCustomerEmailVerificationCommand(customer.Id, 10, customer.Version)).Result as CustomerToken;
            Customer      retrievedCustomer   = commerceToolsClient.ExecuteAsync(new VerifyCustomerEmailCommand(customerToken.Value, customer.Version)).Result;

            this.customerFixture.CustomersToDelete.Add(retrievedCustomer);
            Assert.Equal(customer.Email, retrievedCustomer.Email);
        }
        public ActionResult Display(string receiptId, string status, string receiptNumber)
        {
            string permissions = "";
            int    stat        = 0;

            if (HasPermission("[receipt]", ref permissions, ref stat))
            {
                return(RedirectToAction("AccessDeny"));
            }
            ViewBag.permissions = permissions;
            ViewBag.stat        = stat;
            ViewBag.Title       = "اطلاعات فیش پرداختی";
            BankReceipt tk = new BankReceipt();

            try
            {
                tk.Id            = long.Parse(receiptId);
                tk               = tk.GetOne();
                tk.ReceiptNumber = receiptNumber;
                tk.Statuse       = int.Parse(status);
                tk.Update();
                if (tk.Statuse == 2)
                {
                    Order ord = new Order();
                    ord.Id = tk.OrderId;
                    ord    = ord.GetOne();
                    CustomerToken token = new CustomerToken();
                    token.Count            = ord.Count;
                    token.CustomerId       = tk.CustomerId;
                    token.OrderId          = tk.OrderId;
                    token.RialPrice        = ord.Rial;
                    token.DollarPrice      = ord.Dollar;
                    token.UroPrice         = ord.Uro;
                    token.PondPrice        = ord.Pond;
                    token.Action           = 1;
                    token.ActionBy         = 1;
                    token.ActionCustomerId = 0;
                    token.Date             = DateTime.Now;
                    token.Add();
                }
                return(RedirectToAction("", "Receipt"));
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate = DateTime.Now;
                log.Add();
            }
            return(View(tk));
        }
        public void GetCustomerByPasswordToken()
        {
            IClient       commerceToolsClient = this.customerFixture.GetService <IClient>();
            Customer      customer            = this.customerFixture.CreateCustomer();
            CustomerToken customerToken       = commerceToolsClient.ExecuteAsync(new CreateTokenForCustomerPasswordResetCommand(customer.Email)).Result as CustomerToken;

            this.customerFixture.CustomersToDelete.Add(customer);
            Customer retrievedCustomer = commerceToolsClient.ExecuteAsync(new GetCustomerByPasswordTokenCommand(customerToken.Value)).Result;

            Assert.Equal(customer.Email, retrievedCustomer.Email);
        }
Example #9
0
        public ActionResult View(long Id, string status)
        {
            string permissions = "";
            int    stat        = 0;

            if (HasPermission("[payrequest]", ref permissions, ref stat))
            {
                return(RedirectToAction("AccessDeny"));
            }
            ViewBag.permissions = permissions;
            ViewBag.stat        = stat;

            ViewBag.Title = "درخواست های واریز";
            PayRequest tk = new PayRequest();

            try
            {
                tk.Id     = Id;
                tk        = tk.GetOne();
                tk.Status = int.Parse(status);
                if (status == "2")
                {
                    tk.PayDate = DateTime.Now;
                }
                tk.Update();

                CustomerToken token = new CustomerToken();
                token.Count            = tk.Count;
                token.CustomerId       = tk.CustomerId;
                token.PayRequestId     = tk.Id;
                token.RialPrice        = tk.Rial;
                token.DollarPrice      = tk.Dollar;
                token.UroPrice         = tk.Uro;
                token.PondPrice        = tk.Pond;
                token.Action           = 2;
                token.ActionBy         = 4;
                token.ActionCustomerId = 0;
                token.Date             = DateTime.Now;
                token.Add();
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate = DateTime.Now;
                log.Add();
            }
            return(View(tk));
        }
Example #10
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                Address billingAddress = new Address();
                billingAddress.AdditionalInfo = "b";
                billingAddress.City           = "Monument Valley";
                billingAddress.CountryCode    = "US";
                billingAddress.HouseNumber    = "13";
                billingAddress.State          = "Utah";
                billingAddress.Street         = "Desertroad";
                billingAddress.Zip            = "84536";

                CompanyInformation companyInformation = new CompanyInformation();
                companyInformation.Name = "Acme Labs";

                PersonalNameToken name = new PersonalNameToken();
                name.FirstName     = "Wile";
                name.Surname       = "Coyote";
                name.SurnamePrefix = "E.";

                PersonalInformationToken personalInformation = new PersonalInformationToken();
                personalInformation.Name = name;

                CustomerToken customer = new CustomerToken();
                customer.BillingAddress      = billingAddress;
                customer.CompanyInformation  = companyInformation;
                customer.MerchantCustomerId  = "1234";
                customer.PersonalInformation = personalInformation;

                CardWithoutCvv cardWithoutCvv = new CardWithoutCvv();
                cardWithoutCvv.CardNumber     = "4567350000427977";
                cardWithoutCvv.CardholderName = "Wile E. Coyote";
                cardWithoutCvv.ExpiryDate     = "1299";
                cardWithoutCvv.IssueNumber    = "12";

                TokenCardData data = new TokenCardData();
                data.CardWithoutCvv = cardWithoutCvv;

                TokenCard card = new TokenCard();
                card.Customer = customer;
                card.Data     = data;

                UpdateTokenRequest body = new UpdateTokenRequest();
                body.Card             = card;
                body.PaymentProductId = 1;

                await client.Merchant("merchantId").Tokens().Update("tokenId", body);
            }
#pragma warning restore 0168
        }
        public void ResetCustomerPassword()
        {
            IClient       commerceToolsClient = this.customerFixture.GetService <IClient>();
            Customer      customer            = this.customerFixture.CreateCustomer();
            CustomerToken customerToken       = commerceToolsClient.ExecuteAsync(new CreateTokenForCustomerPasswordResetCommand(customer.Email)).Result as CustomerToken;
            var           password            = "******";
            Customer      retrievedCustomer   = commerceToolsClient.ExecuteAsync(new ResetCustomerPasswordCommand(customerToken.Value, password, customer.Version)).Result;

            this.customerFixture.CustomersToDelete.Add(retrievedCustomer);
            CustomerSignInResult customerSignInResult = commerceToolsClient.ExecuteAsync(new LoginCustomerCommand(customer.Email, password)).Result as CustomerSignInResult;

            Assert.NotNull(customerSignInResult);
        }
Example #12
0
        public HttpResponseMessage AddCustomerToken(int CustomerId, string source)
        {
            CustomerToken customerToken = new CustomerToken();

            customerToken.CustomerId    = CustomerId;
            customerToken.EarningSource = source;
            customerToken.Deleted       = false;
            customerToken.CreatedDate   = DateTime.UtcNow;
            if (source == "facebookshare")
            {
                customerToken.NoOfToken = 5;
            }
            _customerService.InsertCustomerToken(customerToken);
            return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = "success" }));
        }
Example #13
0
        public void AddCustomerToken(Customer customer, string refreshTokenSerial, string accessToken, string refreshTokenSourceSerial)
        {
            var now   = DateTime.UtcNow;
            var token = new CustomerToken
            {
                CustomerId = customer.Id,
                // Refresh token handles should be treated as secrets and should be stored hashed
                RefreshTokenIdHash       = _encryptionService.GetSha256Hash(refreshTokenSerial),
                RefreshTokenIdHashSource = string.IsNullOrWhiteSpace(refreshTokenSourceSerial) ?
                                           null : _encryptionService.GetSha256Hash(refreshTokenSourceSerial),
                AccessTokenHash             = _encryptionService.GetSha256Hash(accessToken),
                RefreshTokenExpiresDateTime = now.AddMinutes(_jwtConfig.RefreshTokenExpirationMinutes),
                AccessTokenExpiresDateTime  = now.AddMinutes(_jwtConfig.AccessTokenExpirationMinutes)
            };

            AddCustomerToken(token);
        }
Example #14
0
        /// <inheritdoc />
        protected override void InitializeTarget()
        {
            var customerToken = CustomerToken?.Render(LogEventInfo.CreateNullEvent());

            if (!string.IsNullOrWhiteSpace(customerToken))
            {
                LogglyConfig.Instance.CustomerToken = customerToken;

                var applicationName = ApplicationName?.Render(LogEventInfo.CreateNullEvent());
                if (!string.IsNullOrWhiteSpace(applicationName))
                {
                    LogglyConfig.Instance.ApplicationName = applicationName;
                }
            }

            var endPointHostName = EndpointHostname?.Render(LogEventInfo.CreateNullEvent());

            if (!string.IsNullOrWhiteSpace(endPointHostName))
            {
                var endpointPort = EndpointPort?.Render(LogEventInfo.CreateNullEvent());
                if (!int.TryParse(endpointPort ?? string.Empty, out var endpointPortNumber))
                {
                    endpointPortNumber = 0; // Let Loggly guess from LogTransport-enum
                }

                var forwardedForIp = ForwardedForIp?.Render(LogEventInfo.CreateNullEvent());
                if (string.IsNullOrEmpty(forwardedForIp))
                {
                    forwardedForIp = null;
                }

                LogglyConfig.Instance.Transport = new TransportConfiguration()
                {
                    EndpointHostname = endPointHostName,
                    EndpointPort     = endpointPortNumber,
                    LogTransport     = LogTransport,
                    ForwardedForIp   = forwardedForIp,
                }.GetCoercedToValidConfig();
            }

            base.InitializeTarget();
            _pendingTaskCount = 0;
            _client           = ClientFactory.Invoke();
        }
Example #15
0
        // GET: profile/Home
        public ActionResult Index()
        {
            ViewBag.Title = TokenShop.Common.LanguageManagment.Translate("dashboard");
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("CustomerId", Session["customer_id"].ToString());
            ViewBag.TicketCount     = new Ticket().GetAll(parameters).Count;
            ViewBag.OpenTicketCount = 0;

            parameters = new Dictionary <string, string>();
            parameters.Add("CustomerId", Session["customer_id"].ToString());
            List <CustomerToken> tokens = new CustomerToken().GetAll(parameters);

            long sum   = 0;
            long count = 0;

            foreach (CustomerToken c in tokens)
            {
                if (c.Action == 1)
                {
                    sum   += c.Count * c.RialPrice;
                    count += c.Count;
                }
            }
            ViewBag.token_price_in = sum;
            ViewBag.token_count_in = count;

            sum   = 0;
            count = 0;
            foreach (CustomerToken c in tokens)
            {
                if (c.Action == 2)
                {
                    sum   += c.Count * c.RialPrice;
                    count += c.Count;
                }
            }
            ViewBag.token_price_out = sum;
            ViewBag.token_count_out = count;
            ViewBag.token_price     = ViewBag.token_price_in - ViewBag.token_price_out;
            ViewBag.token_count     = ViewBag.token_count_in - ViewBag.token_count_out;
            return(View());
        }
Example #16
0
        public async Task Test()
        {
            CreateTokenRequest createTokenRequest = new CreateTokenRequest();

            createTokenRequest.PaymentProductId = (1);
            TokenCard card = new TokenCard();

            createTokenRequest.Card = (card);
            CustomerToken customer = new CustomerToken();

            card.Customer = (customer);
            Address billingAddress = new Address();

            customer.BillingAddress    = (billingAddress);
            billingAddress.CountryCode = ("NL");
            TokenCardData mandate = new TokenCardData();

            card.Data = (mandate);
            CardWithoutCvv cardWithoutCvv = new CardWithoutCvv();

            mandate.CardWithoutCvv        = (cardWithoutCvv);
            cardWithoutCvv.CardholderName = ("Jan");
            cardWithoutCvv.IssueNumber    = ("12");
            cardWithoutCvv.CardNumber     = ("4567350000427977");
            cardWithoutCvv.ExpiryDate     = ("0820");

            using (Client client = GetClient())
            {
                CreateTokenResponse createTokenResponse = await client
                                                          .Merchant("9991")
                                                          .Tokens()
                                                          .Create(createTokenRequest);

                Assert.NotNull(createTokenResponse.Token);

                DeleteTokenParams deleteTokenRequest = new DeleteTokenParams();

                await client
                .Merchant("9991")
                .Tokens()
                .Delete(createTokenResponse.Token, deleteTokenRequest);
            }
        }
Example #17
0
        public HttpResponseMessage AddCustomerTraffic(int CustomerId)
        {
            CustomerTraffic customerTraffic = new CustomerTraffic();

            //var guid = Request.Headers.GetValues("CustomerGUID").FirstOrDefault();
            customerTraffic.CustomerId   = CustomerId;
            customerTraffic.IpAddress    = GetClientIp();
            customerTraffic.CreatedOnUtc = DateTime.UtcNow;
            customerTraffic.UpdatedOnUtc = DateTime.UtcNow;
            var CustomerTraffic = _customerService.InsertCustomerTraffic(customerTraffic);

            if (CustomerTraffic != null)
            {
                CustomerToken customerToken = new CustomerToken();
                customerToken.CustomerId    = CustomerId;
                customerToken.EarningSource = "traffic";
                customerToken.Deleted       = false;
                customerToken.CreatedDate   = DateTime.UtcNow;
                customerToken.NoOfToken     = 1;
                _customerService.InsertCustomerToken(customerToken);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = "success", data = customerTraffic }));
        }
        // not tested on postman
        public async Task <CustomerToken> LoginUser(AppUser user)
        {
            // test for injections
            // Don't return any user id never
            CustomerToken customerToken;

            try
            {
                if (db != null)
                {
                    //Find the post for specific post id
                    // user name entry found
                    var userinfo = await db.AppUser.FirstOrDefaultAsync(p => p.AppUserName == user.AppUserName);

                    // userinfo;


                    if (userinfo != null)
                    {
                        // password validated
                        var _hashedPwd = userinfo.AppUserPwd;
                        // password is hashed and requires to be validate by security layer
                        bool _findMatch = Security.SecurityLogin.ValidatePassword(user.AppUserPwd, _hashedPwd);
                        // add token information if not exists
                        // token information found and not expired
                        if (!_findMatch)
                        {
                            // dont proceed
                            var appError = await db.AppError.FindAsync((int)BlueKangarooErrorCode.USER_ID_PASSWORD_NOT_CORRECT);

                            throw new Exception(appError.AppErrorDescription);
                        }

                        var tokenInformation = await db.AppToken.FirstOrDefaultAsync(token => token.AppTokenUserId == userinfo.AppUserId);

                        if (tokenInformation != null)
                        {
                            if (tokenInformation.TokenExpiredDate > DateTime.Now)
                            {
                                customerToken = new CustomerToken()
                                {
                                    customerTokenId = tokenInformation.AppTokenId.ToString()
                                };
                                return(customerToken);
                            }
                        }
                        else
                        {
                            // add the toke information first time login
                            // the method is accessible earlier only with bearer token
                            // this is add on token to return to client
                            Guid _tokenId      = Guid.NewGuid();
                            var  _newTokenInfo = await db.AppToken.AddAsync(new AppToken()
                            {
                                AppTokenId       = _tokenId,
                                AppTokenUserId   = userinfo.AppUserId,
                                TokenExpiredDate = DateTime.Now.AddDays(30),
                                CreatedDate      = DateTime.Now,
                                // for a while just inser new id
                                // later add Role through dependency injection
                                CreatedBy     = Guid.NewGuid(),
                                AppClientName = Security.SecurityLogin.CreateHash(_tokenId.ToString()),
                                AppNameDesc   = userinfo.AppUserId.ToString() + "-" + userinfo.CreatedDate.ToString(),
                                IsActive      = true,
                                AppUserPwd    = userinfo.AppUserPwd
                            });

                            await db.SaveChangesAsync();

                            customerToken = new CustomerToken()
                            {
                                customerTokenId = _newTokenInfo.Entity.AppTokenId.ToString()
                            };
                            return(customerToken);
                        }
                    }
                    else
                    {
                        var appError = await db.AppError.FindAsync((int)BlueKangarooErrorCode.USER_ID_PASSWORD_NOT_CORRECT);

                        throw new Exception(appError.AppErrorDescription);
                    }
                }
            }
            catch (Exception excp)
            {
                throw excp;
            }

            return(null);
        }
Example #19
0
        public ActionResult Transfer(string count, string reciver_code, string code, string state)
        {
            ViewBag.Title = "انتقال توکن";
            try
            {
                ViewBag.state = int.Parse(state);
                if (state == "2")
                {
                    reciver_code = code;
                }
                ViewBag.code = reciver_code;
                bool     valid = true;
                Customer rc    = new Customer();
                Dictionary <string, string> paramter = new Dictionary <string, string>();
                paramter.Add("UserCode", reciver_code);
                List <Customer> lst = rc.GetAll(paramter);
                if (lst.Count != 1)
                {
                    ViewBag.DangerMessage = "شخصی با شناسه مورد نظر شما یافت نشد";
                    valid = false;
                }
                else
                {
                    ViewBag.transfer_user_name = lst[0].FirstName + " " + lst[0].LastName;
                    ViewBag.state = 2;
                }
                rc = lst[0];

                Customer customer = new Customer();
                customer.Id = long.Parse(Session["customer_id"].ToString());
                customer    = customer.GetOne();

                if (long.Parse(count) > customer.TokenCount)
                {
                    ViewBag.DangerMessage = "موجودی فعلی حساب شما " + customer.TokenCount + " واحد می باشد";
                    valid = false;
                }
                if (state == "1")
                {
                    valid = false;
                }
                if (valid)
                {
                    Setting set = new Setting();
                    set.Id = 1;
                    set    = set.GetOne();

                    CustomerToken token = new CustomerToken();
                    token.Count            = long.Parse(count);
                    token.CustomerId       = rc.Id;
                    token.OrderId          = 0;
                    token.RialPrice        = set.Rial;
                    token.DollarPrice      = set.Dollar;
                    token.UroPrice         = set.Uro;
                    token.PondPrice        = set.Pond;
                    token.Action           = 1;
                    token.ActionBy         = 3;
                    token.ActionCustomerId = customer.Id;
                    token.Date             = DateTime.Now;
                    token.Add();

                    token                  = new CustomerToken();
                    token.Count            = long.Parse(count);
                    token.CustomerId       = customer.Id;
                    token.OrderId          = 0;
                    token.RialPrice        = set.Rial;
                    token.DollarPrice      = set.Dollar;
                    token.UroPrice         = set.Uro;
                    token.PondPrice        = set.Pond;
                    token.Action           = 2;
                    token.ActionBy         = 2;
                    token.ActionCustomerId = rc.Id;
                    token.Date             = DateTime.Now;
                    token.Add();

                    return(RedirectToAction("TransferDone", "token"));
                }
            }
            catch (Exception ex)
            {
                ErrorLog log = new ErrorLog();
                log.Description = ex.Message;
                if (ex.InnerException != null)
                {
                    log.Description += ";" + ex.Message;
                }
                log.ErrorDate  = DateTime.Now;
                log.CustomerId = long.Parse(Session["customer_id"].ToString());
                log.Add();
            }
            return(View());
        }