public async Task ShouldInstantiateClientWithCustomHttpClientFactory()
        {
            var checkoutApi = CheckoutSdk
                              .Builder()
                              .Previous()
                              .StaticKeys()
                              .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_PUBLIC_KEY"))
                              .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_SECRET_KEY"))
                              .Environment(Environment.Sandbox)
                              .HttpClientFactory(new TestingClientFactory())
                              .Build();

            checkoutApi.ShouldNotBeNull();

            try
            {
                await checkoutApi.EventsClient().RetrieveAllEventTypes();

                throw new XunitException();
            }
            catch (Exception ex)
            {
                ex.ShouldNotBeNull();
                ex.ShouldBeAssignableTo(typeof(CheckoutApiException));
                ex.Message.ShouldBe("The API response status code (508) does not indicate success.");
            }
        }
Example #2
0
 public void ShouldFailInitAuthorization_InvalidCredentials()
 {
     try
     {
         CheckoutSdk.Builder()
         .OAuth()
         .ClientCredentials("fake", "fake")
         .Environment(Environment.Sandbox)
         .Build();
         throw new XunitException();
     }
     catch (Exception e)
     {
         e.Message.ShouldBe("OAuth client_credentials authentication failed with error: invalid_client");
     }
 }
        protected SandboxTestFixture(PlatformType platformType)
        {
            var logFactory = new NLogLoggerFactory();

            _log = logFactory.CreateLogger(typeof(SandboxTestFixture));
            switch (platformType)
            {
            case PlatformType.Previous:
                PreviousApi = CheckoutSdk.Builder()
                              .Previous()
                              .StaticKeys()
                              .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_PUBLIC_KEY"))
                              .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_SECRET_KEY"))
                              .Environment(Environment.Sandbox)
                              .LogProvider(logFactory)
                              .HttpClientFactory(new DefaultHttpClientFactory())
                              .Build();
                break;

            case PlatformType.Default:
                DefaultApi = CheckoutSdk.Builder().StaticKeys()
                             .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PUBLIC_KEY"))
                             .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_SECRET_KEY"))
                             .Environment(Environment.Sandbox)
                             .LogProvider(logFactory)
                             .Build();
                break;

            case PlatformType.DefaultOAuth:
                DefaultApi = CheckoutSdk.Builder().OAuth()
                             .ClientCredentials(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"),
                                                System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET"))
                             .Scopes(OAuthScope.Files, OAuthScope.Flow, OAuthScope.Fx, OAuthScope.Gateway,
                                     OAuthScope.Marketplace, OAuthScope.SessionsApp, OAuthScope.SessionsBrowser,
                                     OAuthScope.Vault, OAuthScope.PayoutsBankDetails, OAuthScope.TransfersCreate,
                                     OAuthScope.TransfersView, OAuthScope.BalancesView)
                             .Environment(Environment.Sandbox)
                             .LogProvider(logFactory)
                             .Build();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(platformType), platformType, null);
            }
        }
Example #4
0
 public void ShouldFailInitAuthorization_CustomFakeAuthorizationUri()
 {
     try
     {
         CheckoutSdk.Builder()
         .OAuth()
         .ClientCredentials(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"),
                            System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET"))
         .AuthorizationUri(new Uri("https://test.checkout.com"))
         .HttpClientFactory(new DefaultHttpClientFactory())
         .Build();
         throw new XunitException();
     }
     catch (Exception e)
     {
         e.Message.ShouldBe("OAuth client_credentials authentication failed with error: invalid_client");
     }
 }
Example #5
0
        public void ShouldInstantiateClientWithCustomHttpClientFactory()
        {
            var httpClientFactory = new Mock <IHttpClientFactory>();

            httpClientFactory.Setup(mock => mock.CreateClient())
            .Returns(new HttpClient());

            var checkoutApi = CheckoutSdk
                              .Builder()
                              .StaticKeys()
                              .PublicKey(ValidDefaultPk)
                              .SecretKey(ValidDefaultSk)
                              .Environment(Environment.Sandbox)
                              .HttpClientFactory(httpClientFactory.Object)
                              .Build();

            checkoutApi.ShouldNotBeNull();
            httpClientFactory.Verify(mock => mock.CreateClient());
        }
Example #6
0
        private void ShouldCreateStaticKeysCheckoutSdks()
        {
            var checkoutApi1 = CheckoutSdk
                               .Builder()
                               .StaticKeys()
                               .PublicKey(ValidDefaultPk)
                               .SecretKey(ValidDefaultSk)
                               .Environment(Environment.Sandbox)
                               .Build();

            checkoutApi1.ShouldNotBeNull();

            var checkoutApi2 = CheckoutSdk
                               .Builder()
                               .StaticKeys()
                               .SecretKey(ValidDefaultSk)
                               .Environment(Environment.Sandbox)
                               .Build();

            checkoutApi2.ShouldNotBeNull();
        }
Example #7
0
        private void ShouldFailToCreateCheckoutSdks()
        {
            try
            {
                CheckoutSdk.Builder()
                .Previous()
                .StaticKeys()
                .PublicKey(InvalidPreviousPk)
                .SecretKey(ValidPreviousSk)
                .Environment(Environment.Sandbox)
                .Build();
                throw new XunitException();
            }
            catch (Exception e)
            {
                e.ShouldBeAssignableTo(typeof(CheckoutArgumentException));
                e.Message.ShouldBe("invalid public key");
            }

            try
            {
                CheckoutSdk
                .Builder()
                .Previous()
                .StaticKeys()
                .PublicKey(ValidPreviousPk)
                .SecretKey(InvalidPreviousSk)
                .Environment(Environment.Sandbox)
                .Build();
                throw new XunitException();
            }
            catch (Exception e)
            {
                e.ShouldBeAssignableTo(typeof(CheckoutArgumentException));
                e.Message.ShouldBe("invalid secret key");
            }
        }