예제 #1
0
        /**
         * Build token for authentication on WebSocket
         */
        public async Task <string> BuildToken(string apiKey)
        {
            var createTokenResponse     = new CreateTokenResponse();
            var createApiFailedResponse = new CreateApiResponseFailed();
            var account = await this._accountRepository.GetAccountByApiKey(apiKey);

            if (account == null)
            {
                createApiFailedResponse.Reason = Enum.GetName(typeof(CreateApiFailedEnum), CreateApiFailedEnum.FAILED);
                return(JsonConvert.SerializeObject(createApiFailedResponse));
            }

            if (((DateTime)account.ApiKeyExpirationDate <= DateTime.Now))
            {
                createApiFailedResponse.Reason = Enum.GetName(typeof(CreateApiFailedEnum), CreateApiFailedEnum.NOTOKEN);
                return(JsonConvert.SerializeObject(createApiFailedResponse));
            }

            this._logger.Debug($"Token value before edit {account.Token}");

            //edit token and save it
            this._accountRepository.Entities().AddOrUpdate(account.Id, account, (i, editedAccount) =>
            {
                editedAccount.Token    = Guid.NewGuid().ToString();
                editedAccount.IsEdited = true;
                return(editedAccount);
            });

            createTokenResponse.Token = account.Token;//"7j60imkfu60w";//account.Token;

            this._logger.Debug($"Token value after edit {createTokenResponse.Token}");


            return(JsonConvert.SerializeObject(createTokenResponse));
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateTokenResponse response = new CreateTokenResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Token", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Token = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("TokenId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.TokenId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("TokenType", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.TokenType = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        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
        }
예제 #4
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                TokenizePaymentRequest body = new TokenizePaymentRequest();
                body.Alias = "Some alias";

                CreateTokenResponse response = await client.Merchant("merchantId").Payments().Tokenize("paymentId", body);
            }
#pragma warning restore 0168
        }
예제 #5
0
        public IActionResult CreateToken([FromBody] CreateTokenRequest request)
        {
            UserModel user = _userManager.LoginUser(request.Username, request.Password);

            if (user == null)
            {
                return(BadRequest("Username or password is incorrect."));
            }

            CreateTokenResponse response = new CreateTokenResponse();

            response.Token     = CreateUserToken(user);
            response.ExpiresIn = DateTime.Now.AddMilliseconds(int.Parse(_configuration["Jwt:ExpiresInMs"]));

            return(Ok(response));
        }
예제 #6
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);
            }
        }
예제 #7
0
        public IActionResult CreateToken([FromBody] CreateTokenRequest request)
        {
            try
            {
                var input = new AuthenticationInput(request.UserName, request.Password);
                var user  = _useCase.Execute(input);
                var token = _tokenService.CreateToken(user);

                var response = new CreateTokenResponse
                {
                    Token   = new JwtSecurityTokenHandler().WriteToken(token),
                    Expires = token.ValidTo
                };

                return(Created("https://paella.com", response));
            }
            catch (System.Exception)
            {
                return(BadRequest());
            }
        }