alt

Important information

The API reference is now available here.
The deprecated API reference is available here.

Unzer

Accept Unzer Direct Debit Secured with UI components

Use Unzer UI component to add Unzer Direct Debit Secured payment to your checkout page.

Overview

Using UI components for Unzer Direct Debit Secured you get a ready-made form with the fields necessary to make this type of payment. You can check a demo version of the component here. Basic steps for integrating using UI components are the same for all payment methods and you can read about them here.

For Unzer Direct Debit Secured, you need to provide information about the customer via the customer resource and the information about the products purchased via the basket resource when you make the transaction. This is required for customer assessment and transaction approval. You will also need the customer information to create the invoice document. You should gather this data during the checkout.

Before you begin

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

First, you need to initiate our UI components library and add the payment form to your payment page.

Initiate UI component

Load our JS script and CSS stylesheet

Include Unzer’s script and stylesheet on your website.

Always load the script and stylesheet directly from Unzer:

<link rel="stylesheet" href="https://static.unzer.com/v1/unzer.css" />
<script type="text/javascript" src="https://static.unzer.com/v1/unzer.js"></script>
icon
Faster load time
To make your website load faster, insert JavaScript scripts at the bottom of your HTML document.
icon
Importing Unzer styles
To minimize the risk of Unzer styles affecting the styles of your webpage, we suggest putting unzer.css on top of other imported CSS files.

Create an Unzer instance

Create an unzer instance with your public key:

// Creating an unzer instance with your public key
var unzerInstance = new unzer('s-pub-xxxxxxxxxx');
icon
Placeholder keys
In the previous example, we used a placeholder API key for example purposes. You should replace it with your public key.

Localization and languages

We support localization with locale option parameters. Check the Localization page for a list of all the supported locales.

The auto option (applied by default) uses the client’s browser language.

Here you can see how to set the language, in our case ‘de-DE’ - to do so, add a comma separated parameter to your unzer instance:

// Creating an unzer instance with your public key
var unzerInstance = new unzer('s-pub-xxxxxxxxxx', {locale: 'de-DE'});

Implement Payment form

Option 1: Implement with customer form

If you don’t have information about the customer (and accompanying customerId) or want to update information of already existing customer, you can do so using the customer form. Check Customer UI component page for a detailed information.

Insert the customer form

To use the customer form effectively, you must insert it into your payment form. We recommend placing it between the payment elements and the submit button.

Example:

<form id="payment-form">
    <div id="direct-debit-secured-IBAN" class="field">
        <!-- The IBAN field UI Element will be inserted here -->
    </div>
    <div id="customer" class="field">
        <!-- The customer form UI element will be inserted here -->
    </div>
    <button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
    <!-- You can add the required SEPA mandate text here -->
</form>

SEPA mandate

Unzer Direct Debit payment method requires an approval of SEPA mandate by the customer. You can use the following sample text for creating the SEPA mandate.

SEPA mandate sample: English textSEPA mandate sample: German text
SEPA Direct Debit Mandate

By signing this mandate form, you authorise {NAME OF MERCHANT} to send instructions to your bank to debit your account and your bank to debit your account in accordance with the instructions from {NAME OF MERCHANT}.

Note: As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited. Your rights regarding this SEPA mandate are explained in a statement that you can obtain from your bank.

In case of refusal or rejection of direct debit payment I instruct my bank irrevocably to inform {NAME OF MERCHANT} or any third party upon request about my name, address and date of birth.
SEPA Lastschrift-Mandat (Bankeinzug)

Ich ermächtige {NAME OF MERCHANT}, Zahlungen von meinem Konto mittels SEPA Lastschrift einzuziehen. Zugleich weise ich mein Kreditinstitut an, die von {NAME OF MERCHANT} auf mein Konto gezogenen SEPA Lastschriften einzulösen.

Hinweis: Ich kann innerhalb von acht Wochen, beginnend mit dem Belastungsdatum, die Erstattung des belasteten Betrags verlangen. Es gelten dabei die mit meinem Kreditinstitut vereinbarten Bedingungen.

Für den Fall der Nichteinlösung der Lastschriften oder des Widerspruchs gegen die Lastschriften weise ich meine Bank unwiderruflich an, {NAME OF MERCHANT} oder Dritten auf Anforderung meinen Namen, Adresse und Geburtsdatum vollständig mitzuteilen.

Create the customer resource

A customer resource is created like a Payment Type with the UI components.

let customer = unzerInstance.Customer();
customer.create({containerId: 'customer'});

However, different steps are taken in case you wish to update an already created customer:

let customer = unzerInstance.Customer();
customer.update('p-cst-xxxxxxxxxxxxx', {containerId: 'customer'});

Option 2: Create the customer on the server side

You can also use the customer data provided by your shop system to create the Customer resource on the server-side. This way you can omit rendering the customer form in the frontend and just create the resource and use the id in your transaction request. This might not be feasible in case of B2B customer resource creation. See Create Customer Resource for details on this approach.

In that case you just need to create a simple HTML button on the client side:

<form id="payment-form">
    <div id="direct-debit-secured-IBAN" class="field">
        <!-- The IBAN field UI Element will be inserted here -->
    </div>
    <button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
    <!-- You can add the required SEPA mandate text here -->
</form>

Create a Payment Type resource

Call the method unzerInstance.SepaDirectDebitSecured() to create an instance of the Unzer Direct Debit Secured Payment Type.

// Creating an Unzer Direct Debit Secured instance
var directDebitSecured = unzerInstance.SepaDirectDebitSecured()

// Rendering the input field
directDebitSecured.create('sepa-direct-debit-secured', {
  containerId: 'direct-debit-secured-IBAN'
});

Add an event listener for “submit” of the form.

Option 1: Without the customer form

Get the HTML form by its unique ID and add an event listener.

Inside, create a promise on the Unzer Direct Debit Secured object. The promise gets either resolved or rejected:

let form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
    event.preventDefault();

    directDebitSecured.createResource()
        .then(function(result) {
            // Submit the ID of the created payment type to your
            // backend to perform the payment transaction with it.
            typeId = result.id;
        })
        .catch(function(error) {
            // handle errors
            document.getElementById('error-holder').innerText = error.customerMessage || error.message || 'Error'
        })
});

Option 2: With the customer form

Get the HTML form by its unique ID and add an event listener.

Create a promise for the customer and the SepaDirectDebitSecured object and handle them with Promise.all(). Please Check Customer form with payment for more information for more information.

let form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
    event.preventDefault();

    let paymentTypePromise = directDebitSecured.createResource();
    let customerPromise = customer.createCustomer();
    Promise.all([paymentTypePromise, customerPromise])
        .then(function(values) {
            let paymentTypeId = values[0];
            let customerId = values[1];
            // submit the ids to your back end integration
        })
        .catch(function(error) {
            document.getElementById('error-holder').innerText = error.customerMessage || error.message || 'Error'
        })
});

Optional: Customize UI components

You can easily customize the font of the forms by changing the options within the create method. Here you can set the following styles: fontSize, fontColor and fontFamily.

directDebitSecured.create('sepa-direct-debit-secured', {
    containerId: 'direct-debit-secured-IBAN',
    fontSize: '16px',
    fontColor: 'lightgrey',
    fontFamily: 'Arial,
    Helvetica, sans-serif'
});

Step 2: Make a payment
server side

Besides an always mandatory step of creating the paymentType resource Unzer SepaDirectDebitSecured requires also a Customer and Basket resource.

Create a customer resource

This step is only applicable if you didn’t create a customer resource so far on the client side.

POST: https://api.unzer.com/v1/customers

{
  "birthDate": "1974-10-03",
  "customerId": "info@unzer.com",
  "email": "info@unzer.com",
  "firstname": "Max",
  "lastname": "Mustermann",
  "mobile": "+49123456879",
  "phone": "+49123456789",
  "salutation": "mr",
  "billingAddress": {
    "city": "Heidelpay",
    "country": "DE",
    "name": "Max Mustermann",
    "street": "Vangerowstr. 18",
    "zip": "69115"
  },
  "shippingAddress": {
    "city": "Heidelpay",
    "country": "DE",
    "name": "Max Mustermann",
    "street": "Vangerowstr. 18",
    "zip": "69115"
  }
}
$address = (new Address())
            ->setName('Max Mustermann')
            ->setStreet('Vangerowstr. 18')
            ->setZip('69115')
            ->setCity('Heidelberg')
            ->setCountry('DE');

$customer = (new Customer())
            ->setFirstname('Max')
            ->setLastname('Mustermann')
            ->setSalutation(Salutations::MR)
            ->setCompany('Unzer GmbH')
            ->setBirthDate('1972-12-24')
            ->setEmail('Max.Mustermann@unzer.com')
            ->setMobile('+49 123456789')
            ->setPhone('+49 123456789')
            ->setBillingAddress($address)
            ->setShippingAddress($address);

$unzer->createCustomer($customer);
Address address = new Address();
address
  .setName("Max Mustermann")
  .setStreet("Vangerowstr. 18")
  .setCity("Heidelberg")
  .setZip("69115")
  .setCountry("DE");
      
Customer customer = new Customer("Max", "Mustermann");
customer
  .setCustomerId(customerId)
  .setSalutation(Salutation.mr)
  .setEmail("max.mustermann@unzer.com")
  .setMobile("+49123456789")
  .setBirthDate(getDate("12.12.2000"))
  .setBillingAddress(address)
  .setShippingAddress(address);

customer = unzer.createCustomer(customer);

For a full description of customer resource please refer to relevant Server-side integration documentation page: Manage customer (direct API calls), Manage customer (PHP SDK), Manage customer (Java SDK).

Create a basket resource

The Basket resource stores information about the purchased products, used vouchers, and the shipment costs.

POST: https://api.unzer.com/v1/baskets

{
  "amountTotalGross" : 200.00,
  "amountTotalDiscount" : 10.00,
  "amountTotalVat" : 33.33,
  "currencyCode" : "EUR",
  "orderId" : "Order-12345",
  "note" : "Test Basket",
  "basketItems" : [ {
    "basketItemReferenceId" : "Item-d030efbd4963",
    "unit" : "m",
    "quantity" : 10,
    "amountDiscount" : 10.00,
    "vat" : 0.2,
    "amountGross" : 200.00,
    "amountVat" : 33.33,
    "amountPerUnit" : 16.667,
    "amountNet" : 166.67,
    "title" : "SDM 6 CABLE",
    "subTitle" : "This is brand new Mid 2019 version",
    "imageUrl" : "https://static.unzer.com/paypage/static/media/unzer-logo.ee4b3a61.svg",
    "type": "goods"
  } ]
}
<?php
$unzer = new Unzer('s-priv-xxxxxxxxxx');

$basketItem = (new BasketItem())
    ->setBasketItemReferenceId('Item-d030efbd4963')
    ->setQuantity(10)
    ->setUnit('m')
    ->setAmountPerUnitGross(20.00)
    ->setAmountDiscountPerUnitGross(1.00)
    ->setVat(19.0)
    ->setTitle('SDM 6 CABLE')
    ->setSubTitle('This is brand new Mid 2019 version')
    ->setImageUrl('https://a.storyblok.com/f/91629/x/1ba8deb8cc/unzer_primarylogo__white_rgb.svg')
    ->setType(BasketItemTypes::GOODS);

$basket = (new Basket())
    ->setTotalValueGross(190.00)
    ->setCurrencyCode('EUR')
    ->setOrderId('Order-12345')
    ->setNote('Test Basket')
    ->addBasketItem($basketItem);

$unzer->createBasket($basket);
BasketItem basketItem = new BasketItem()
        .setBasketItemReferenceId("Item-d030efbd4963")
        .setQuantity(BigDecimal.valueOf(10))
        .setUnit("m")
        .setAmountPerUnitGross(BigDecimal.valueOf(20.00))
        .setAmountDiscountPerUnitGross(BigDecimal.valueOf(1.00))
        .setVat(BigDecimal.valueOf(19.0))
        .setTitle("SDM 6 CABLE")
        .setSubTitle("This is brand new Mid 2019 version")
        .setImageUrl(new URL("https://a.storyblok.com/f/91629/x/1ba8deb8cc/unzer_primarylogo__white_rgb.svg"))
        .setType(BasketItem.Type.GOODS);

Basket basket  = new Basket()
        .setTotalValueGross(BigDecimal.valueOf(190.00))
        .setCurrencyCode(Currency.getInstance("EUR"))
        .setOrderId("Order-12345")
        .setNote("Test Basket")
        .addBasketItem(basketItem);

Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
unzer.createBasket(basket);

For a full description of basket resource, refer to the relevant server-side-integration documentation page: Direct API integration, PHP SDK integration, Java SDK integration.

Make a Charge transaction

Now, make a charge transaction with the SepaDirectDebitSecured resource that you created. With a successful charge transaction insured money is transferred from the customer to the merchant and a payment resource is created.

POST https://api.unzer.com/v1/payments/charges
   
Body:
{
    "amount": "20",
    "currency": "EUR",
    "resources": {
        "customerId": "s-cst-6bd9ca06cc57",
        "basketId": "s-bsk-17620",
        "typeId": "s-dds-bchnzvfuecjm"
    }
}
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$sepa-direct-debit-secured = $unzer->fetchPaymentType('s-dds-bchnzvfuecjm');
$charge = $sepa-direct-debit-secured->charge(20.0, 'EUR', 's-cst-6bd9ca06cc57','s-bsk-17620');
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Charge charge = unzer.charge(20.00, Currency.getInstance("EUR"), "s-dds-bchnzvfuecjm", "s-cst-6bd9ca06cc57", "s-bsk-17620");

Step 3: Check status of the payment
server side

After that, 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-41201",
    "state": {
        "id": 1,
        "name": "completed"
    },
    "amount": {
        "total": "20.0000",
        "charged": "20.0000",
        "canceled": "0.0000",
        "remaining": "0.0000"
    },
    "currency": "EUR",
    "orderId": "",
    "invoiceId": "",
    "resources": {
        "customerId": "s-cst-6bd9ca06cc57",
        "paymentId": "s-pay-41201",
        "basketId": "s-bsk-17620",
        "metadataId": "",
        "payPageId": "",
        "traceId": "e3e558163c1086a45bdcb8b8ce3f9df8",
        "typeId": "s-dds-bchnzvfuecjm"
    },
    "transactions": [
        {
            "date": "2021-05-10 15:37:37",
            "type": "charge",
            "status": "success",
            "url": "https://api.unzer.com/v1/payments/s-pay-41201/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 Unzer Direct Debit Secured payments, such as refunding them, see Manage Unzer Direct Debit Secured 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