Esempio n. 1
0
        private async Task ShouldRetrieveWebhook()
        {
            var webhookResponse = new WebhookResponse();

            _apiClient.Setup(apiClient =>
                             apiClient.Get <WebhookResponse>("webhooks/wh_kve4kqtq3ueezaxriev666j4ky", _authorization,
                                                             CancellationToken.None))
            .ReturnsAsync(() => webhookResponse);

            IWebhooksClient client = new WebhooksClient(_apiClient.Object, _configuration.Object);

            var response = await client.RetrieveWebhook("wh_kve4kqtq3ueezaxriev666j4ky");

            response.ShouldNotBeNull();
            response.ShouldBeSameAs(webhookResponse);
        }
Esempio n. 2
0
        private async Task ShouldRegisterWebhook()
        {
            var webhookRequest  = new WebhookRequest();
            var webhookResponse = new WebhookResponse();

            _apiClient.Setup(apiClient =>
                             apiClient.Post <WebhookResponse>("webhooks", _authorization, webhookRequest,
                                                              CancellationToken.None, null))
            .ReturnsAsync(() => webhookResponse);

            IWebhooksClient client = new WebhooksClient(_apiClient.Object, _configuration.Object);

            var response = await client.RegisterWebhook(webhookRequest);

            response.ShouldNotBeNull();
            response.ShouldBe(webhookResponse);
        }
        private async Task ShouldTestFullWebhookOperations()
        {
            await CleanUp();

            const string url = "https://checkout.com/webhooks";
            //Create webhook
            var webhookResponse = await RegisterWebhook(url);

            webhookResponse.ShouldNotBeNull();
            webhookResponse.Id.ShouldNotBeNull();
            webhookResponse.Url.ShouldBe(url);
            webhookResponse.ContentType.ShouldBe(WebhookContentType.Json);
            webhookResponse.EventTypes.ShouldBe(_eventTypes);

            //Retrieve webhook
            WebhookResponse retrieveWebhook = await Retriable(async() =>
                                                              await PreviousApi.WebhooksClient().RetrieveWebhook(webhookResponse.Id));

            retrieveWebhook.ShouldNotBeNull();
            retrieveWebhook.Id.ShouldBe(webhookResponse.Id);
            retrieveWebhook.Url.ShouldBe(webhookResponse.Url);
            retrieveWebhook.Active.ShouldBe(webhookResponse.Active);
            retrieveWebhook.ContentType.ShouldBe(webhookResponse.ContentType);
            retrieveWebhook.EventTypes.ShouldBe(webhookResponse.EventTypes);

            //Update webhook
            const string urlChanged    = "https://checkout.com/failed2";
            var          updateRequest = new WebhookRequest
            {
                Url        = urlChanged,
                Headers    = retrieveWebhook.Headers,
                EventTypes = new List <string> {
                    "source_updated"
                },
                ContentType = WebhookContentType.Json
            };

            var updateWebhook = await Retriable(async() =>
                                                await PreviousApi.WebhooksClient().UpdateWebhook(webhookResponse.Id, updateRequest));

            updateWebhook.ShouldNotBeNull();
            updateWebhook.HttpStatusCode.ShouldNotBeNull();
            updateWebhook.ResponseHeaders.ShouldNotBeNull();
            updateWebhook.Url.ShouldBe(urlChanged);
            updateWebhook.Headers.ShouldBe(retrieveWebhook.Headers);
            updateWebhook.EventTypes.ShouldNotBe(retrieveWebhook.EventTypes);
            updateWebhook.EventTypes.ShouldBe(updateRequest.EventTypes);

            //Delete webhook
            var emptyResponse = await PreviousApi.WebhooksClient().RemoveWebhook(webhookResponse.Id);

            emptyResponse.ShouldNotBeNull();
            emptyResponse.HttpStatusCode.ShouldNotBeNull();
            emptyResponse.ResponseHeaders.ShouldNotBeNull();

            //Confirm delete
            try
            {
                var nonExistingWebhook = await PreviousApi.WebhooksClient().RetrieveWebhook(webhookResponse.Id);

                nonExistingWebhook.ShouldBeNull();
            }
            catch (CheckoutApiException ex)
            {
                ex.HttpStatusCode.ShouldBe(HttpStatusCode.NotFound);
            }
        }