alt

Important information

Please be advised that there will be a scheduled downtime across our API network on November 05 and November 07, 2024. For more information, visit our platform status portal.:
- Scheduled maintenance on November 5, 2024
- Scheduled maintenance on November 7, 2024

Unzer

Accept Bancontact with UI components

Use Unzer UI component to add Unzer Bancontact payment to your checkout page.

Overview

Using UI components v2 for Bancontact, create a payment type resource that will be used to make the payment. You don’t need any form fields for this payment method. The basic steps for integrating using UI components are the same for all payment methods, and you can read about them here.

Legacy integration

This page describes the most recent integration of the UI Components, introduced in Jan 2025. For the Legacy integration guide go here.

Before you begin

Step 1: Add UI components v2 to your payment page
client side

First, you need to initiate our UI components v2 library and add the needed payment type component to your payment page.

Initiate UI Components

Load the Unzer JS script

Include the Unzer JS script on your website. This will load all the Unzer custom UI components with unzer- prefixed. For example, <unzer-paylater-invoice>.

Make sure to always include the script directly from the Unzer domain https://static-v2.unzer.com.

<script
        type="module"
        src="https://static-v2.unzer.com/v2/ui-components/index.js"
></script>
icon info
Faster load time
To make your website load faster, import the unzer script at the bottom of your HTML document.
Make sure to import the script as type=“module”.
icon info
Content security policy
To learn which URLs must be added to the allowlist for Unzer UI components in your content security policy, please refer to Content security policy section.

It is a good practice to put your website in loading state until the Unzer script is loaded, and the UI components are ready to use.

    // Make sure initially your application is in loading state
    // until all Unzer components are loaded
    Promise.all([
        customElements.whenDefined("unzer-payment"),
        // Probably add any other Unzer components used here. For example:
        // customElements.whenDefined("unzer-paylater-invoice"),
    ]).then(() => {
        // Hide the loading state and proceed with next steps
    }).catch((error) => {
        // Handle any error that might occur during the 
        // loading process and initialization
    });

UI setup and configuration

To securely collect payment data from your customer, you need to add the <unzer-payment> component, inside which you insert the needed payment type components.

icon
We recommend putting your submit button inside the <unzer-checkout> element. This will provide automatic handling for enabling/disabling the submit button depending on the current status, and showing/hiding of brand icons.
<unzer-payment
        id="unzer-payment"
        publicKey="s-pub-xyz"
        locale="de-DE">
    <!-- ... Here you will need to add the Unzer payment type tag, so the form UI elements will be inserted -->
    <!--    e.g <unzer-paylater-invoice></unzer-paylater-invoice> -->
</unzer-payment>
<unzer-checkout id='unzer-checkout'>
    <button type="submit" id="yourPaymentButtonId">Pay</button>
</unzer-checkout>

Following parameters need to be passed.

ParameterTypeDescriptionDefault value
publicKey (required)StringThe merchant public key.-
localeStringThe used locale. For more information on supported locales, see Localization.Browser user defined locale.
initDataobjectA key/value object in JSON-format containing data to initialize the payment type. For more information, Check payment methods and their features.Empty object {}

Optional: Customize UI components

Our UI components v2 are provided with a default theme that contains base styles. You can easily customize these styles by overriding the following CSS variables.

Variable nameDescriptionAffected components
--unzer-fontReplaces all fonts with the given font. Users can define any font-face and provide the name of the custom font-face.typography
--unzer-text-colorThe font color use for typography.typography, icons
--unzer-brand-colorThe main color of the application.button, checkbox, radio, loader
--unzer-background-colorThe page background.
--unzer-link-colorThe color of links.link
--unzer-corner-radiusWhether controls will have rounded corners or not. Values can be either 0 or 1.button, tags, chips
--unzer-shadowsWhether shadows are enabled or not. Values can be either 0 or 1.button, card
<head>
    <style>
        :root {
            --unzer-font: SFMono;
            --unzer-brand-color: #ee1818;
            --unzer-text-color: #f19316;
            --unzer-background-color: #6a9472;
            --unzer-link-color: #1330ef;
            --unzer-corner-radius: 0;
            --unzer-shadows: 1
        }
    </style>
</head>

Add Bancontact payment method

To add the Bancontact payment method insert unzer-bancontact in the unzer-payment container.

<unzer-payment 
    publicKey="s-pub-xxxxxxxxxx"
    locale="de-DE">
  <unzer-bancontact></unzer-bancontact>
<unzer-payment>

<unzer-checkout>
    <button type="submit" id="yourPaymentButtonId">Pay</button>
</unzer-checkout>
icon
We recommend putting your submit button inside the <unzer-checkout> element. This will provide automatic handling of the submit whenever the user clicks the submit button, and passing back the creation payload.

Create payment type and customer resources

After the submit button is clicked, the customer and payment data are automatically submitted. You will then need to query the unzer-checkout element and handle the response inside its onPaymentSubmit event listener.

The following code example shows how to read customer and payment data from the response.

    // Make sure that this code is executed after the elements are rendered
    const unzerCheckout = document.getElementById('unzer-checkout');
    unzerCheckout.onPaymentSubmit = (response) => {
        if (response.submitResponse && response.customerResponse) {
            if (response.customerResponse.success) {
                // Optional: Only in case a new customer is created in the frontend.
                const customerId = response.customerResponse.data.id;
            }

            if (response.submitResponse.success) {
                const paymentTypeId = response.submitResponse.data.id;
            }

            // Submit all IDs to your server-side integration to perform the payment transaction.
        }
    };

Step 2: Make a payment
server side

Make a charge transaction

Now, make a charge transaction with the Bancontact typeId that you created and the returnUrl leading back to your shop after the payment is finished on the external page. With the charge transaction, an amount is requested but is not yet transferred. Initially, the transaction will be pending, and a payment resource is created.


POST https://api.unzer.com/v1/payments/charges
   
Body:
{
  "amount" : "20",
  "currency": "EUR",
  "returnUrl": "https://www.my-shop-url.de/returnhandler",
  "resources" : {
    "typeId" : "s-bct-jldsmlmiprwe"
  }
}
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$bancontact = $unzer->fetchPaymentType('s-bct-0ajzmaxcuvhc');
$charge = $bancontact->charge(20.0, 'EUR', 'https://www.my-shop-url.de/returnhandler');

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Charge charge = unzer.charge(BigDecimal.ONE, Currency.getInstance("EUR"), "s-bct-0ajzmaxcuvhc", new URL("https://www.my-shop-url.de/returnhandler"));

The response looks similar to the following example:

{
    "id": "s-chg-1",
    "isSuccess": true,
    "isPending": false,
    "isError": false,
    "redirectUrl": "https://payment.unzer.com/v1/redirect/bancontact/s-sGYdGywWpxzW",
    "message": {
        "code": "COR.000.100.112",
        "merchant": "Request successfully processed in 'Merchant in Connector Test Mode'",
        "customer": "Your payments have been successfully processed in sandbox mode."
    },
    "amount": "20.0000",
    "currency": "EUR",
    "returnUrl": "https://www.my-shop-url.de/returnhandler",
    "date": "2021-05-10 00:51:03",
    "resources": {
        "paymentId": "s-pay-131937",
        "traceId": "70ddf3152a798c554d9751a6d77812ae",
        "typeId": "s-bct-jldsmlmiprwe"
    },
    "paymentReference": "",
    "processing": {
        "uniqueId": "31HA07BC8157BD2BC04D483EFA914465",
        "shortId": "4845.3426.1987",
        "traceId": "70ddf3152a798c554d9751a6d77812ae"
    }
}

For a full description of the charge transaction, refer to the relevant server-side integration documentation page: Charge a payment (direct API calls), Charge a payment (PHP SDK), Charge a payment (Java SDK).

Forward the customer to the external payment page

After you charge the Bancontact resource, implement the following flow:

  1. Forward the customer to the redirectUrl returned in response to your charge request.
  2. The customer is forwarded to the Bancontact payment page.
  3. After a successful payment or abort on the Bancontact page, the customer is redirected to the returnURL specified in the initial charge call.

Step 3: Check status of the payment
server side

Once the customer is redirected to the returnUrl, you can fetch the payment details from the API, by using the resources.paymentId from the charge response above to handle the payment according to its status. If the status of the payment is completed, the payment process has been finished successfully and can be considered as paid. Check all possible payment states here.

GET https://api.unzer.com/v1/payments/{payment_ID}

{
    "id": "s-pay-xxxxxx",
    "state": {
        "id": 1,
        "name": "completed"
    },
    "amount": {
        "total": "20.0000",
        "charged": "20.0000",
        "canceled": "0.0000",
        "remaining": "0.0000"
    },
    "currency": "EUR",
    "orderId": "",
    "invoiceId": "",
    "resources": {
        "customerId": "",
        "paymentId": "s-pay-131937",
        "basketId": "",
        "metadataId": "",
        "payPageId": "",
        "traceId": "70ddf3152a798c554d9751a6d77812ae",
        "typeId": "s-bct-xxxxxxxxx"
    },
    "transactions": [
        {
            "date": "2021-05-10 00:51:03",
            "type": "charge",
            "status": "success",
            "url": "https://api.unzer.com/v1/payments/s-pay-xxxxxxx/charges/s-chg-1",
            "amount": "20.0000"
        }
    ]
}

Step 4: Display the payment result
client side

Use the information from the Check status of the payment step to display the payment result to your customer.
This can be the success or error page of your shop. If something went wrong, you can use the client message from the API response and show it to the customer.

Manage payment
server side

For more details on managing Bancontact payments, see Manage Bancontact payments

Notifications

We recommend subscribing to the payment event to receive notifications about any changes to the payment resource. As soon as the event is triggered you should fetch the payment and update the order status in your shop according to its status.

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

For more details on implementing webhooks to receive notifications, see Notifications page.

Error handling

All requests to the API can result in an error that should be handled. Refer to the Error handling guide to learn more about Unzer API (and other) errors and handling them.

Test & go live

You should always test your integration before going live. First perform test transactions using test data. Next, check against Integration checklist and Go-live checklist to make sure the integration is complete and you’re ready to go live.

See also