Esempio n. 1
0
        public void CreateConsumerToken()
        {
            // X-Example: POST /payments/v1/authorizations/{authorizationToken}/customer-token
            var username = "******";
            var password = "******";

            var klarna = new Klarna(username, password, KlarnaEnvironment.TestingEurope);
            var authorization_token = "234534...345345....345";
            var consumertokenreqest = new PaymentGenerateConsumerTokenRequest {
                BillingAddress = new PaymentAddressInfo {
                    GivenName     = "John",
                    FamilyName    = "Doe",
                    StreetAddress = "Sveavägen 46",
                    PostalCode    = "103 69",
                    Country       = "SE",
                    Email         = "*****@*****.**",
                    City          = "Stockholm",
                    Phone         = "+46752242244"
                }
            };

            try
            {
                var consumertoken = klarna.Payment.GenerateConsumerToken(authorization_token, consumertokenreqest).Result;
                Console.WriteLine("Consumer Token ID: " + consumertoken.TokenId);
            }
            catch (AggregateException ae)
            {
                foreach (var e in ae.InnerExceptions)
                {
                    if (e is ApiException)
                    {
                        var apiException = (ApiException)e;
                        Console.WriteLine("Status code: " + apiException.StatusCode);
                        Console.WriteLine("Error: " + string.Join("; ", apiException.ErrorMessage.ErrorMessages));
                    }
                    else
                    {
                        // Rethrow any other exception or process it
                        Console.WriteLine(e.Message);
                        throw;
                    }
                }
            }
            // /X-Example: POST /payments/v1/authorizations/{authorizationToken}/customer-token
        }
Esempio n. 2
0
        public void CreateConsumerToken()
        {
            var username = "******";
            var password = "******";

            var klarna = new Klarna(username, password, KlarnaEnvironment.TestingEurope);
            var authorization_token = "234534...345345....345";
            var consumertokenreqest = new PaymentGenerateConsumerTokenRequest {
                BillingAddress = new PaymentAddressInfo {
                    GivenName     = "John",
                    FamilyName    = "Doe",
                    StreetAddress = "Sveavägen 46",
                    PostalCode    = "103 69",
                    Country       = "SE",
                    Email         = "*****@*****.**",
                    City          = "Stockholm",
                    Phone         = "+46752242244"
                }
            };

            try
            {
                var consumertoken = klarna.Payment.GenerateConsumerToken(authorization_token, consumertokenreqest).Result;
                Console.WriteLine("Consumer Token ID: " + consumertoken.TokenId);
            }
            catch (ApiException ex)
            {
                Console.WriteLine(ex.ErrorMessage.ErrorCode);
                Console.WriteLine(ex.ErrorMessage.ErrorMessages);
                Console.WriteLine(ex.ErrorMessage.CorrelationId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Generate a consumer token
        /// <a href="https://developers.klarna.com/api/#payments-api-generate-a-consumer-token">https://developers.klarna.com/api/#payments-api-generate-a-consumer-token</a>
        /// </summary>
        /// <param name="authorizationToken">Authorization token from JS client</param>
        /// <param name="consumerTokenRequest">The <see cref="PaymentGenerateConsumerTokenRequest"/> object</param>
        /// <returns><see cref="PaymentGenerateConsumerTokenResponse"/></returns>
        public async Task <PaymentGenerateConsumerTokenResponse> GenerateConsumerToken(string authorizationToken, PaymentGenerateConsumerTokenRequest consumerTokenRequest)
        {
            var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.PaymentAuthorizations, $"{authorizationToken}/customer-token");

            var response = await Post <PaymentGenerateConsumerTokenResponse>(url, consumerTokenRequest);

            return(response);
        }