alt

Important information

There was an update of Unzer TLS/SSL certificates. Learn more

Unzer

Accept Unzer Installment with UI components

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

Overview

Using UI components for Unzer Installment you get a ready-made form with 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.

With Unzer Installment you need to provide information about the customer via a customer resource and the purchased products via a basket resource when you make the transaction. This is required for customer assessment and transaction approval.

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 https://static.unzer.com:

<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 js 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 example above, 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 the payment form

Option 1: Implement with the customer form

If you don’t have information about the customer (and accompanying customer ID) or want to update information of an already existing customer, you can do so using the customer form.

Insert the customer form

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

<form id="payment-form">
    <div id="example-Installment-secured"></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>
</form>

Create a customer resource

A customer resource is created similar to a payment type using the UI components.

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

To update an already existing customer resource:

let customer = unzerInstance.Customer();

// Initialize the form and pass the ID of the customer resource
Customer.initFormFields({
  "lastname": "Universum",
  "firstname": "Peter",
  "salutation": "mr",
  "billingAddress": {
    "street": "Hugo-Junkers-Str. 5",
    "state": "DE-BO",
    "zip": "60386",
    "city": "Frankfurt am Main",
    "country": "DE"
  }
});
customer.update('p-cst-xxxxxxxxxxxxx', {containerId: 'customer'});
let customer = unzerInstance.B2BCustomer();

// Initialize the form and pass the ID of the customer resource
Customer.initFormFields({
    "salutation": "mr",
    "company": "Unzer GmbH",
    "phone": "+4962216471100",
    "mobile": "+49172123456",
    "billingAddress": {
        "name": "Peter Universum",
        "street": "Hugo-Junkers-Str. 5",
        "state": "DE-BO",
        "zip": "60386",
        "city": "Frankfurt am Main",
        "country": "DE"
    },
    "companyInfo": {
        "registrationType": "registered",
            "commercialRegisterNumber": "123456789",
            "function": "OWNER",
            "commercialSector": "OTHER"
    }
});
customer.update('p-cst-xxxxxxxxxxxxx', {containerId: 'customer'});
icon
Note that the customer data should be presented in the same form the Unzer payment API returns the customer object. This includes the birth date, which is accepted in the format “yyyy-mm-dd” only.

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 front end and just create the resource and use the ID in your transaction request.

For server-side customer resource creation, you just need to create a simple HTML button on the client side:

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.

Create a payment type resource

To create an Unzer Installment instance, call the unzerInstance.Installment() method:

let installmentSecured = unzerInstance.InstallmentSecured();

Add an event listener and submit the form


Option 1: Without the customer form

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

Inside, create a Promise on the InstallmentSecured object. The Promise gets either resolved or rejected:

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

    installmentSecured.createResource()
        .then(function(result) {
            let typeId = result.id;
            // submit the payment type ID to your server-side integration
        })
        .catch(function(error) {
            $('#error-holder').html(error.customerMessage || error.message || 'Error')
        })
});

Option 2: With the customer create form

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

Create a Promise for the InstallmentSecured object and a second one for the customer object, and handle both at once using Promise.all().

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

    let paymentTypePromise = installmentSecured.createResource();
    let customerPromise = customer.createCustomer();
    Promise.all([paymentTypePromise, customerPromise])
        .then(function(values) {
            let typeId = values[0];
            let customerId = values[1];
            // Submit the IDs to your server-side integration.
        })
        .catch(function(error) {
            $('#error-holder').html(error.customerMessage || error.message || 'Error')
        })
});

When creating the Promises, be sure you use the following methods:

  • createResource() for the payment type
  • createCustomer() or updateCustomer() for the customer resource

Step 2: Make a payment
server side

Other than the mandatory step of creating the payment type resource, you also require a customer and a basket resource for Unzer Installment payments.

This payment type requires the following workflow:

  1. Fetch the available installment plans and show them to the customer to chose from.
    This is done automatically when creating the payment type in the front end.
  2. Creating the payment type resource using the installment plan details selected by the customer
  3. Performing an authorization transaction to initialize the selected installment plan.
  4. Show the selected installment plan and its conditions to the customer.
  5. Performing a charge transaction after the customer agrees to the conditions.
  6. Perform a shipment transaction to finalize and start the payments

Create a customer resource

Do this step only 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"
  }
}
$unzer = new Unzer("s-priv-xxxxxxxxxxx");
$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);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxxx");
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);

The response looks similar to the following example:

{
"id":"s-cst-23e165524229"
}

The examples show B2C customer creation. For a full description of customer resource, e.g. updating and handling B2B customers, For a full description of customer resource, refer to the 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, as well as shipment costs and VAT amounts.

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"
  } ]
}
$unzer = new Unzer("s-priv-xxxxxxxxxxx");
$basketItem = (new BasketItem())
    ->setBasketItemReferenceId('Item-d030efbd4963')
    ->setQuantity(10)
    ->setUnit('m')
    ->setAmountPerUnit(16.667)
    ->setAmountNet(166.67)
    ->setAmountDiscount(10.0)
    ->setVat(0.2)
    ->setAmountGross(200.0)
    ->setAmountVat(33.33)
    ->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())
    ->setAmountTotalGross(200.00)
    ->setCurrencyCode('EUR')
    ->setOrderId('Order-12345')
    ->setNote('Test Basket')
    ->addBasketItem($basketItem);

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

BasketItem basketItem = new BasketItem();
basketItem.setBasketItemReferenceId("Item-d030efbd4963");
basketItem.setUnit("m");
basketItem.setQuantity(10);
basketItem.setAmountDiscount(new BigDecimal("10.0"));
basketItem.setVat(new BigDecimal("0.2"));
basketItem.setAmountGross(new BigDecimal("200.00"));
basketItem.setAmountVat(new BigDecimal("33.33"));
basketItem.setAmountPerUnit(new BigDecimal("16.667"));
basketItem.setAmountNet(new BigDecimal("166.67"));
basketItem.setTitle("SDM 6 CABLE");
basketItem.setSubTitle("This is brand new Mid 2019 version");
basketItem.setImageUrl("https://a.storyblok.com/f/91629/x/1ba8deb8cc/unzer_primarylogo__white_rgb.svg");
basketItem.setType("goods");

Basket basket = new Basket();
basket.setAmountTotalGross(new BigDecimal("200.00"));
basket.setAmountTotalDiscount(new BigDecimal("10.00"));
basket.setAmountTotalVat(new BigDecimal("33.33"));
basket.setCurrencyCode(Currency.getInstance("EUR"));
basket.addBasketItem(basketItem);
basket.setOrderId("Order-12345");
basket.setNode("Test Basket");

Basket basket = unzer.createBasket(basket);

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

Make an authorize transaction

Now, perform an authorize transaction using the InstallmentSecured resource that you created.

POST https://api.unzer.com/v1/payments/authorize

{
  "amount": 100.0,
  "currency": "EUR",
  "orderId": "Your Order Id",
  "paymentReference": "Test authorize transaction",
  "resources": {
    "basketId": "s-bsk-xxxxxxxxxx",
    "customerId": "s-cst-xxxxxxxxxx",
    "typeId": "s-ins-upbgliswcvry"
  },
  "returnUrl": "https://url.of-your-return-controller.de"
}
$unzer = new Unzer("s-priv-xxxxxxxxxxx");
$authorize = $unzer->authorize(
    100.0,
    'EUR',
    's-ins-xxxxxxxxxxx',
    https://url.of-your-return-controller.de,
    's-cst-xxxxxxxxxx',
    'Your Order Id',
    null,
    's-bsk-xxxxxxxxxx'
);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxxx");
Authorize charge = unzer.authorize(
  100.00,
  Currency.getInstance("EUR"),
  's-ins-xxxxxxxxxxx',
  new URL("https://url.of-your-return-controller.de"),
  "s-cst-xxxxxxxxxxx",
  "s-bsk-xxxxxxxxxxx"
);

The response looks similar to the following example:

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

Display the chosen installment plan

After the authorize transaction is successful, you have to display the information of the chosen installment plan to the customer and display a download link of the PDF supplied in the response. If there was an error during the authorize transaction, display the corresponding customerMessage in the frontend instead.

You should also display a button which places the order and triggers the Charge transaction when clicked.

<div>
    <div>
      Total Purchase Amount: <!-- provide the total purchase amount and currency from your Backend integration-->
    </div>
    <div>
      Total Interest Amount: <!-- provide the total interest amount and currency from your Backend integration-->
    </div>
    <div>
        Total Amount: <!-- provide the total amount and currency from your Backend integration-->
    </div>
</div>
<div>
    <strong>Please download your rate plan <a href="<!-- provide the PDF Link from your Backend integration-->">here</a></strong><br/>
</div>
<div id="place_order" class="ui bottom attached primary button" tabindex="0" onclick="<!--trigger a charge transaction in your server-side integration-->">Place order</div>

Make a charge transaction

Now, make a charge transaction with the InstallmentSecured resource that you created. With a successful charge transaction, the amount has been prepared to be insured, and a payment resource is created.

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

{
  "amount": 100.0,
  "currency": "EUR",
  "orderId": "Your Order Id",
  "paymentReference": "Test charge transaction",
  "resources": {
    "basketId": "s-bsk-xxxxxxxxxx",
    "customerId": "s-cst-xxxxxxxxxx",
    "typeId": "s-ins-xxxxxxxxxx"
  },
  "returnUrl": "https://url.of-your-return-controller.de"
}
$unzer = new Unzer("s-priv-xxxxxxxxxxx");
$charge = $unzer->charge(
    100.0,
    'EUR',
    's-ins-xxxxxxxxxxx',
    'https://url.of-your-return-controller.de',
    's-cst-xxxxxxxxxx',
    'Your Order Id',
    null,
    's-bsk-xxxxxxxxxx',
    null,
    null,
    'Test charge transaction'
);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxxx");
Charge charge = unzer.charge(
  100.00,
  Currency.getInstance("EUR"),
  's-ins-xxxxxxxxxxx',
  new URL("https://url.of-your-return-controller.de"),
  "s-cst-xxxxxxxxxxx",
  "s-bsk-xxxxxxxxxxx"
);

The response looks similar to the following example:

{
  "id": "s-chg-1",
  "isSuccess": true,
  "isPending": false,
  "isError": false,
  "message": {
    "code": "OK"
  },
  "amount": "119.0000",
  "currency": "EUR",
  "date": "2021-06-15 08:24:07",
  "resources": {
    "customerId": "s-cst-33c5b9bef5a7",
    "paymentId": "s-pay-174811",
    "basketId": "s-bsk-41794",
    "metadataId": "",
    "payPageId": "",
    "traceId": "23dc97dac8f55b870c93048d251af12f",
    "typeId": "s-ins-fiqgzhw6j2su"
  },
  "paymentReference": "",
  "processing": {
    "externalOrderId": "8b9718f3-6b5d-40b7-9376-79bf74818cbe",
    "zgReferenceId": "4702417365603530003141093",
    "uniqueId": "31HA07BC811A66C29D3E9AE7ED47A055",
    "shortId": "4876.7184.8553",
    "traceId": "23dc97dac8f55b870c93048d251af12f"
  }
}

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).

Step 3: Check status of the payment
server side

Once the Payment is made, you can fetch the Payment details from the PAPI to handle the Payment according to its status.

GET https://api.unzer.com/v1/payments/{payment_ID}
{
    "id": "s-pay-1762",
    "state": {
        "id": 0,
        "name": "pending"
    },
    "amount": {
        "total": "119.0000",
        "charged": "119.0000",
        "canceled": "0.0000",
        "remaining": "0.0000"
    },
    "currency": "EUR",
    "orderId": "o932271001622632368",
    "invoiceId": "",
    "resources": {
        "customerId": "s-cst-9d5f19fa17cc",
        "paymentId": "s-pay-1762",
        "basketId": "s-bsk-1582",
        "metadataId": "",
        "payPageId": "",
        "traceId": "059e6c3d3e1174bf53905f9546ef22f2",
        "typeId": "s-ins-u9hir9xkiliz"
    },
    "transactions": [
        {
            "date": "2021-06-02 11:12:49",
            "type": "authorize",
            "status": "success",
            "url": "https://api.heidelpay.com/v1/payments/s-pay-1762/authorize/s-aut-1",
            "amount": "119.0000"
        },
        {
            "date": "2021-06-02 11:13:00",
            "type": "charge",
            "status": "success",
            "url": "https://api.heidelpay.com/v1/payments/s-pay-1762/charges/s-chg-1",
            "amount": "119.0000"
        }
    ]
}

Step 4: Display the payment result
client side

Use the information from the Check status of the payment step to show 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 Installment payments, see Manage Unzer Installment 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