Exemple #1
0
        public void ShouldInstantiateAndRetrieveClientsDefault()
        {
            //Arrange
            var sdkCredentialsMock    = new Mock <SdkCredentials>(MockBehavior.Strict, PlatformType.Previous);
            var httpClientFactoryMock = new Mock <IHttpClientFactory>();

            httpClientFactoryMock.Setup(mock => mock.CreateClient())
            .Returns(new HttpClient());
            var checkoutConfiguration = new CheckoutConfiguration(sdkCredentialsMock.Object, Environment.Sandbox,
                                                                  httpClientFactoryMock.Object);

            //Act
            ICheckoutApi checkoutApi = new CheckoutApi(checkoutConfiguration);

            //Assert
            checkoutApi.TokensClient().ShouldNotBeNull();
            checkoutApi.CustomersClient().ShouldNotBeNull();
            checkoutApi.PaymentsClient().ShouldNotBeNull();
            checkoutApi.InstrumentsClient().ShouldNotBeNull();
            checkoutApi.DisputesClient().ShouldNotBeNull();
            checkoutApi.RiskClient().ShouldNotBeNull();
            checkoutApi.ForexClient().ShouldNotBeNull();
            checkoutApi.WorkflowsClient().ShouldNotBeNull();
            checkoutApi.SessionsClient().ShouldNotBeNull();
            checkoutApi.AccountsClient().ShouldNotBeNull();
            checkoutApi.PaymentLinksClient().ShouldNotBeNull();
            checkoutApi.HostedPaymentsClient().ShouldNotBeNull();
            checkoutApi.BalancesClient().ShouldNotBeNull();
            checkoutApi.TransfersClient().ShouldNotBeNull();
        }
Exemple #2
0
        public void ShouldInstantiateAndRetrieveClientsPrevious()
        {
            //Arrange
            var sdkCredentialsMock    = new Mock <SdkCredentials>(MockBehavior.Strict, PlatformType.Previous);
            var httpClientFactoryMock = new Mock <IHttpClientFactory>();

            httpClientFactoryMock.Setup(mock => mock.CreateClient())
            .Returns(new HttpClient());
            var checkoutConfiguration = new CheckoutConfiguration(sdkCredentialsMock.Object, Environment.Sandbox,
                                                                  httpClientFactoryMock.Object);

            //Act
            Previous.ICheckoutApi checkoutApi = new Previous.CheckoutApi(checkoutConfiguration);

            //Assert
            checkoutApi.TokensClient().ShouldNotBeNull();
            checkoutApi.CustomersClient().ShouldNotBeNull();
            checkoutApi.SourcesClient().ShouldNotBeNull();
            checkoutApi.PaymentsClient().ShouldNotBeNull();
            checkoutApi.InstrumentsClient().ShouldNotBeNull();
            checkoutApi.DisputesClient().ShouldNotBeNull();
            checkoutApi.WebhooksClient().ShouldNotBeNull();
            checkoutApi.EventsClient().ShouldNotBeNull();
            checkoutApi.RiskClient().ShouldNotBeNull();
            checkoutApi.PaymentLinksClient().ShouldNotBeNull();
            checkoutApi.ReconciliationClient().ShouldNotBeNull();
            checkoutApi.HostedPaymentsClient().ShouldNotBeNull();
            checkoutApi.IdealClient().ShouldNotBeNull();
            checkoutApi.KlarnaClient().ShouldNotBeNull();
            checkoutApi.SepaClient().ShouldNotBeNull();
        }
        private void ShouldCreateConfiguration()
        {
            var credentials           = new StaticKeysSdkCredentials(ValidDefaultSk, ValidDefaultPk);
            var httpClientFactoryMock = new Mock <IHttpClientFactory>();
            var configuration         =
                new CheckoutConfiguration(credentials, Environment.Production, httpClientFactoryMock.Object);

            configuration.Environment.ShouldBe(Environment.Production);
            configuration.SdkCredentials.ShouldBeAssignableTo(typeof(StaticKeysSdkCredentials));
        }
Exemple #4
0
        /// <summary>
        /// Creates a new <see cref="CheckoutApi"/> instance with default dependencies.
        /// </summary>
        /// <param name="secretKey">Your secret key obtained from the Checkout Hub.</param>
        /// <param name="uri">The base URL of the Checkout API you wish to connect to.</param>
        /// <param name="publicKey">Your public key obtained from the Checkout Hub. Required for some API resources.</param>
        /// <returns>The configured instance.</returns>
        public static CheckoutApi Create(string secretKey, string uri, string publicKey = null)
        {
            var configuration = new CheckoutConfiguration(secretKey, uri)
            {
                PublicKey = publicKey
            };

            var apiClient = new ApiClient(configuration);

            return(new CheckoutApi(apiClient, configuration));
        }
Exemple #5
0
        /// <summary>
        /// Creates a new <see cref="CheckoutApi"/> instance with default dependencies.
        /// </summary>
        /// <param name="secretKey">Your secret key obtained from the Checkout Hub.</param>
        /// <param name="useSandbox">Whether to connect to the Checkout Sandbox. False indicates the live environment should be used.</param>
        /// <param name="publicKey">Your public key obtained from the Checkout Hub. Required for some API resources.</param>
        /// <returns>The configured instance.</returns>
        public static CheckoutApi Create(string secretKey, bool useSandbox = true, string publicKey = null)
        {
            var configuration = new CheckoutConfiguration(secretKey, useSandbox)
            {
                PublicKey = publicKey
            };

            var apiClient = new ApiClient(configuration);

            return(new CheckoutApi(apiClient, configuration));
        }
Exemple #6
0
        /// <summary>
        /// Creates a new <see cref="ApiClient"/> instance with the provided configuration, HTTP client factory and serializer.
        /// </summary>
        /// <param name="configuration">The Checkout configuration required to configure the client.</param>
        /// <param name="httpClientFactory">A factory for creating HTTP client instances.</param>
        /// <param name="serializer">A serializer used to serialize and deserialize HTTP payloads.</param>
        public ApiClient(
            CheckoutConfiguration configuration,
            IHttpClientFactory httpClientFactory,
            ISerializer serializer)
        {
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            if (httpClientFactory == null)
            {
                throw new ArgumentNullException(nameof(httpClientFactory));
            }
            _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));

            _httpClient = httpClientFactory.CreateClient();
        }
Exemple #7
0
        public ApiClient(CheckoutConfiguration configuration, IApiHttpClient httpClient)
        {
            CheckoutConfiguration = configuration;
            ApiHttpClient         = httpClient;

            CardService              = new CardService(ApiHttpClient, CheckoutConfiguration);
            ChargeService            = new ChargeService(ApiHttpClient, CheckoutConfiguration);
            CustomerService          = new CustomerService(ApiHttpClient, CheckoutConfiguration);
            LookupsService           = new LookupsService(ApiHttpClient, CheckoutConfiguration);
            PayoutsService           = new PayoutsService(ApiHttpClient, CheckoutConfiguration);
            RecurringPaymentsService = new RecurringPaymentsService(ApiHttpClient, CheckoutConfiguration);
            ReportingService         = new ReportingService(ApiHttpClient, CheckoutConfiguration);
            TokenService             = new TokenService(ApiHttpClient, CheckoutConfiguration);

            ContentAdaptor.Setup();
        }
        public CheckoutApi(CheckoutConfiguration configuration)
        {
            var baseApiClient = BaseApiClient(configuration);

            _tokensClient      = new TokensClient(baseApiClient, configuration);
            _customersClient   = new CustomersClient(baseApiClient, configuration);
            _paymentsClient    = new PaymentsClient(baseApiClient, configuration);
            _instrumentsClient = new InstrumentsClient(baseApiClient, configuration);
            _disputesClient    = new DisputesClient(baseApiClient, configuration);
            _riskClient        = new RiskClient(baseApiClient, configuration);
            _forexClient       = new ForexClient(baseApiClient, configuration);
            _workflowsClient   = new WorkflowsClient(baseApiClient, configuration);
            _sessionsClient    = new SessionsClient(baseApiClient, configuration);
            _accountsClient    = new AccountsClient(
                baseApiClient,
                FilesApiClient(configuration),
                configuration);
            _paymentLinksClient   = new PaymentLinksClient(baseApiClient, configuration);
            _hostedPaymentsClient = new HostedPaymentsClient(baseApiClient, configuration);
            _balancesClient       = new BalancesClient(BalancesApiClient(configuration),
                                                       configuration);
            _transfersClient = new TransfersClient(TransfersApiClient(configuration),
                                                   configuration);
        }
Exemple #9
0
 /// <summary>
 /// Creates a new <see cref="CheckoutApi"/> instance and initializes each underlying API client.
 /// </summary>
 /// <param name="apiClient">The API client used to send API requests and handle responses.</param>
 /// <param name="configuration">A configuration object containing authentication and API specific information.</param>
 public CheckoutApi(IApiClient apiClient, CheckoutConfiguration configuration)
 {
     Payments = new PaymentsClient(apiClient, configuration);
     Sources  = new SourcesClient(apiClient, configuration);
     Tokens   = new TokensClient(apiClient, configuration);
 }
 private static ApiClient BalancesApiClient(CheckoutConfiguration configuration)
 {
     return(new ApiClient(configuration.HttpClientFactory,
                          configuration.Environment.GetAttribute <EnvironmentAttribute>().BalancesApiUri));
 }
Exemple #11
0
 public ApiHttpClient(CheckoutConfiguration configuration)
 {
     this.configuration = configuration;
     ResetHandler();
 }
Exemple #12
0
        /// <summary>
        /// Creates a new <see cref="ApiClient"/> instance with the provided configuration and serializer.
        /// </summary>
        /// <param name="configuration">The Checkout configuration required to configure the client.</param>
        /// <param name="serializer">A serializer used to serialize and deserialize HTTP payloads.</param>

        public ApiClient(CheckoutConfiguration configuration, ISerializer serializer)
            : this(configuration, new DefaultHttpClientFactory(), serializer)
        {
        }
Exemple #13
0
 /// <summary>
 /// Creates a new <see cref="ApiClient"/> instance with the provided configuration and HTTP client factory.
 /// </summary>
 /// <param name="configuration">The Checkout configuration required to configure the client.</param>
 /// <param name="httpClientFactory">A factory for creating HTTP client instances.</param>
 public ApiClient(CheckoutConfiguration configuration, IHttpClientFactory httpClientFactory)
     : this(configuration, httpClientFactory, new JsonSerializer())
 {
 }
Exemple #14
0
 /// <summary>
 /// Creates a new <see cref="ApiClient"/> instance with the provided configuration.
 /// </summary>
 /// <param name="configuration">The Checkout configuration required to configure the client.</param>
 public ApiClient(CheckoutConfiguration configuration)
     : this(configuration, new DefaultHttpClientFactory(), new JsonSerializer())
 {
 }
 /// <summary>
 /// Creates a new see <cref="SecretKeyCredentials"/> instance.
 /// </summary>
 /// <param name="configuration">The Checkout configuration containing your secret key.</param>
 public SecretKeyCredentials(CheckoutConfiguration configuration)
 {
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }