Skip to content

Latest commit

 

History

History
335 lines (242 loc) · 11.3 KB

webhook-subscriptions.md

File metadata and controls

335 lines (242 loc) · 11.3 KB

Webhook Subscriptions

WebhookSubscriptionsApi webhookSubscriptionsApi = client.getWebhookSubscriptionsApi();

Class Name

WebhookSubscriptionsApi

Methods

List Webhook Event Types

Lists all webhook event types that can be subscribed to.

CompletableFuture<ListWebhookEventTypesResponse> listWebhookEventTypesAsync(
    final String apiVersion)

Parameters

Parameter Type Tags Description
apiVersion String Query, Optional The API version for which to list event types. Setting this field overrides the default version used by the application.

Response Type

ListWebhookEventTypesResponse

Example Usage

webhookSubscriptionsApi.listWebhookEventTypesAsync(null).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

List Webhook Subscriptions

Lists all webhook subscriptions owned by your application.

CompletableFuture<ListWebhookSubscriptionsResponse> listWebhookSubscriptionsAsync(
    final String cursor,
    final Boolean includeDisabled,
    final String sortOrder,
    final Integer limit)

Parameters

Parameter Type Tags Description
cursor String Query, Optional A pagination cursor returned by a previous call to this endpoint.
Provide this to retrieve the next set of results for your original query.

For more information, see Pagination.
includeDisabled Boolean Query, Optional Includes disabled Subscriptions.
By default, all enabled Subscriptions are returned.
Default: false
sortOrder String Query, Optional Sorts the returned list by when the Subscription was created with the specified order.
This field defaults to ASC.
limit Integer Query, Optional The maximum number of results to be returned in a single page.
It is possible to receive fewer results than the specified limit on a given page.
The default value of 100 is also the maximum allowed value.

Default: 100

Response Type

ListWebhookSubscriptionsResponse

Example Usage

Boolean includeDisabled = false;

webhookSubscriptionsApi.listWebhookSubscriptionsAsync(null, includeDisabled, null, null).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

Create Webhook Subscription

Creates a webhook subscription.

CompletableFuture<CreateWebhookSubscriptionResponse> createWebhookSubscriptionAsync(
    final CreateWebhookSubscriptionRequest body)

Parameters

Parameter Type Tags Description
body CreateWebhookSubscriptionRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

CreateWebhookSubscriptionResponse

Example Usage

CreateWebhookSubscriptionRequest body = new CreateWebhookSubscriptionRequest.Builder(
    new WebhookSubscription.Builder()
        .name("Example Webhook Subscription")
        .eventTypes(Arrays.asList(
            "payment.created",
            "payment.updated"
        ))
        .notificationUrl("https://example-webhook-url.com")
        .apiVersion("2021-12-15")
        .build()
)
.idempotencyKey("63f84c6c-2200-4c99-846c-2670a1311fbf")
.build();

webhookSubscriptionsApi.createWebhookSubscriptionAsync(body).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

Delete Webhook Subscription

Deletes a webhook subscription.

CompletableFuture<DeleteWebhookSubscriptionResponse> deleteWebhookSubscriptionAsync(
    final String subscriptionId)

Parameters

Parameter Type Tags Description
subscriptionId String Template, Required [REQUIRED] The ID of the Subscription to delete.

Response Type

DeleteWebhookSubscriptionResponse

Example Usage

String subscriptionId = "subscription_id0";

webhookSubscriptionsApi.deleteWebhookSubscriptionAsync(subscriptionId).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

Retrieve Webhook Subscription

Retrieves a webhook subscription identified by its ID.

CompletableFuture<RetrieveWebhookSubscriptionResponse> retrieveWebhookSubscriptionAsync(
    final String subscriptionId)

Parameters

Parameter Type Tags Description
subscriptionId String Template, Required [REQUIRED] The ID of the Subscription to retrieve.

Response Type

RetrieveWebhookSubscriptionResponse

Example Usage

String subscriptionId = "subscription_id0";

webhookSubscriptionsApi.retrieveWebhookSubscriptionAsync(subscriptionId).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

Update Webhook Subscription

Updates a webhook subscription.

CompletableFuture<UpdateWebhookSubscriptionResponse> updateWebhookSubscriptionAsync(
    final String subscriptionId,
    final UpdateWebhookSubscriptionRequest body)

Parameters

Parameter Type Tags Description
subscriptionId String Template, Required [REQUIRED] The ID of the Subscription to update.
body UpdateWebhookSubscriptionRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

UpdateWebhookSubscriptionResponse

Example Usage

String subscriptionId = "subscription_id0";
UpdateWebhookSubscriptionRequest body = new UpdateWebhookSubscriptionRequest.Builder()
    .subscription(new WebhookSubscription.Builder()
        .name("Updated Example Webhook Subscription")
        .enabled(false)
        .build())
    .build();

webhookSubscriptionsApi.updateWebhookSubscriptionAsync(subscriptionId, body).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

Update Webhook Subscription Signature Key

Updates a webhook subscription by replacing the existing signature key with a new one.

CompletableFuture<UpdateWebhookSubscriptionSignatureKeyResponse> updateWebhookSubscriptionSignatureKeyAsync(
    final String subscriptionId,
    final UpdateWebhookSubscriptionSignatureKeyRequest body)

Parameters

Parameter Type Tags Description
subscriptionId String Template, Required [REQUIRED] The ID of the Subscription to update.
body UpdateWebhookSubscriptionSignatureKeyRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

UpdateWebhookSubscriptionSignatureKeyResponse

Example Usage

String subscriptionId = "subscription_id0";
UpdateWebhookSubscriptionSignatureKeyRequest body = new UpdateWebhookSubscriptionSignatureKeyRequest.Builder()
    .idempotencyKey("ed80ae6b-0654-473b-bbab-a39aee89a60d")
    .build();

webhookSubscriptionsApi.updateWebhookSubscriptionSignatureKeyAsync(subscriptionId, body).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

Test Webhook Subscription

Tests a webhook subscription by sending a test event to the notification URL.

CompletableFuture<TestWebhookSubscriptionResponse> testWebhookSubscriptionAsync(
    final String subscriptionId,
    final TestWebhookSubscriptionRequest body)

Parameters

Parameter Type Tags Description
subscriptionId String Template, Required [REQUIRED] The ID of the Subscription to test.
body TestWebhookSubscriptionRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

TestWebhookSubscriptionResponse

Example Usage

String subscriptionId = "subscription_id0";
TestWebhookSubscriptionRequest body = new TestWebhookSubscriptionRequest.Builder()
    .eventType("payment.created")
    .build();

webhookSubscriptionsApi.testWebhookSubscriptionAsync(subscriptionId, body).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});