alt

Important information

Updates to Visa secure data field mandate: Read more about the mandatory changes.

Unzer

Notifications

Receive notifications about any changes related to your payments.

Overview

Unzer supports notifications for payment events that you can configure as webhooks.

Webhooks are individually defined HTTP callbacks from one website to another. They can go either way and are usually triggered by events. To keep your app or website up to date with any changes happening to your payments, you can register a webhook triggered by relevant events. To send notifications, we’re using the standard HTTP/1.1 protocol.

For the full list of webhook events supported by the Unzer API go to Supported webhook events.

icon

To get the updated state of a resource:

  • Don’t use the event name as an indicator of the state of a resource. To get the latest state of the resource, you should always fetch the resource using the Unzer API.
  • Don’t use the event’s retrieveUrl to fetch the event’s resource without making sure the domain is legit.
  • Always fetch the event by creating an API request for the affected resource with correct Unzer API domain.

Step 1: Prepare your API

Other than meeting the basic requirements your API should also fulfill the following:

  • Accept text/plain content-type requests
  • Respond with the standard HTTP 200 OK success code, to acknowledge a received notification and prevent sending it again.

Notification examples

You’ll get notifications based on your public key, as a JSON payload. For example:

{
   "event":"types",
   "publicKey":"s-pub-xxxxxxxxxx",
   "retrieveUrl":"https://api.unzer.com/v1/types/card/s-crd-88xu7qjboupc"
}
{
  "event":"payment.pending",
  "publicKey":"s-pub-xxxxxxxxxx",
  "retrieveUrl":"https://api.unzer.com/v1/payments/s-pay-774",
  "paymentId":"s-pay-774"
}

Error handling

If our system doesn’t receive the standard HTTP 200 OK success code within 20 seconds, it tries to resend the notification in the following intervals:

Retry attemptInterval
11–2 minutes after the initial webhook event
25–6 minutes after the 1st retry attempt
310–11 minutes after the 2nd retry attempt
430–31 minutes after the 3rd retry attempt
560–61 minutes after the 4th retry attempt
6–16 (10 times)Every 60 minutes

If your API doesn’t respond after the last retry attempt, the notification gets marked as undeliverable, and you can’t retrieve it anymore.

Step 2: Register event notification

Register a URL to which you want to get notifications, and specify the events that you want to get notified about.

Selected event types

To enable notifications for selected event use event key. For example to trigger notifications for all charge related events:

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Webhook webhook = unzer.registerSingleWebhook(new Webhook("https://your.notification.handler.url", WebhookEventEnum.AUTHORIZE));

The method returns a Webhook object that stores the Unzer API response.

{
  "id": "s-whk-1",
  "event": "charge",
  "url": "https://www.yourApiUrl.com/notifications"
}

To enable notifications for multiple events with one request call registerMultipleWebhooks:

The method returns a Webhooks object that stores the eventList from the Unzer API response.

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Webhook webhook = unzer.registerMultiWebhooks(new Webhook(
    "https://your.notification.handler.url",
    Arrays.asList(WebhookEventEnum.AUTHORIZE, WebhookEventEnum.CHARGE, WebhookEventEnum.SHIPMENT)
));
{
    "events": [
        {
         "id": "s-whk-3",
         "url": "https://www.yourApiUrl.com/notifications",
         "event": "authorize"
       },
       {
         "id": "s-whk-4",
         "url": "https://www.yourApiUrl.com/notifications",
         "event": "charge"
       },
       {
         "id": "s-whk-5",
         "url": "https://www.yourApiUrl.com/notifications",
         "event": "shipment"
       }
    ]
}

All events

To get notified about every single event, set event to all, for example:

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Webhook webhook = unzer.registerSingleWebhook(new Webhook("https://your.notification.handler.url", WebhookEventEnum.ALL));

Step 3: Manage webhooks

Using Unzer API webhooks endpoint you can retrieve, update and delete your webhooks.

Retrieve webhooks

The Java SDK does not support fetching by Webhook-ID as of now.

To retrieve all of your existing webhooks, call the Unzer.getWebhooks method with no webhook ID:

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
WebhookList webhookList = unzer.getWebhooks();

Update webhooks

To update the URL of an existing webhook, call the Unzer.updateWebhookmethod, with the edited webhook object.

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
// Get Webhook-List from Unzer API as described above and retrieve Webhook-ID for the Webhook to be updated
webhook.setUrl("https://newNotificationUrl.com");
unzer.updateSingleWebhook(webhookId, webhook);

Delete webhooks

To delete an existing webhook, call the Unzer::updateWebhookmethod, with the webhook’s ID as parameter:

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Webhook webhook = unzer.deleteSingleWebhook('s-whk-1');

To delete all of your existing webhooks, call the Unzer::updateWebhookmethod with no parameter:

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
WebhookList webhook = unzer.deleteMultiWebhook();

For details on Unzer API webhook calls, please check API reference guide.

Handle incoming events

Whenever an event is triggered, the corresponding URL is called. The POST request contains the json-information about the event which you can use to fetch the corresponding resource which in turn can be used to update the state of the order or payment in your shop.

See also