Unzer Docs

Accept Unzer Invoice with UI components

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

icon

If you are using payment types invoice or invoice-secured, note that these methods are now deprecated. They are currently supported but there are no further developments planned for them.

If you want to access the relevant documentation, see Unzer Invoice and Unzer Invoice Secured.

Overview

Using UI components for Unzer Invoice, you create a paylater-invoice payment type resource that is used to make the payment. The form of this payment type consists of a checkbox for the client to accept the terms and conditions. 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 Invoice you need to provide information about the customer via a customers resource and the purchased products via a 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 are responsible for gathering 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 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. Please check the Localization page on supported locales.

The auto option (which is 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 customer form

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

Insert the customer form

To use the customer form effectively, you must insert it into your payment form. We recommend placing it above the payment elements.

Here is a short example:

<form id="payment-form">
    <div id="customer" class="field">
        <!-- The customer form UI element will be inserted here -->
    </div>
    <div id="example-paylater-invoice"></div>
    <button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>

Create the customer resource

A customer resource is created like a payment type with the UI components. Please make sure to set the option paymentTypeName to “paylater-invoice” in order to allow rendering a specialized form for this payment type.

let customer = unzerInstance.Customer();
customer.create({
    containerId: 'customer',
    paymentTypeName: 'paylater-invoice'
    });
let customer = unzerInstance.B2BCustomer();
customer.create({
    containerId: 'customer',
    paymentTypeName: 'paylater-invoice'
    });

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. This might not be feasible in case of B2B customer resource creation. Refer to the section Create customer resource for details on this approach.

In that case you just need to render the payment type form and create a simple HTML button on the client side:

<form id="payment-form">
    <div id="example-paylater-invoice"></div>
    <button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>

Create a payment type resource

To create a payment type resource – an Unzer Invoice instance, call the unzerInstance.PaylaterInvoice() method:

let paylaterInvoice = unzerInstance.PaylaterInvoice();

Add an event listener and submit 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 PaylaterInvoice object. The Promise gets either resolved or rejected:

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

    paylaterInvoice.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 by its unique ID and add an event listener.

Create a Promise for the customer and the PaylaterInvoice object and handle them with Promise.all().

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

        let customerPromise = customer.createCustomer();
        let paylaterInvoicePromise = paylaterInvoice.createResource();
        Promise.all([paylaterInvoicePromise, 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')
            })
    });

In the example, paylaterInvoicePromise and customerPromise were created to temporarily store individual promises.

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

  • createResource() for the PaymentType
  • createCustomer() for the Customer resource

After that you can simply handle both promises with Promise.all() and the recently created variables as parameter list.

Step 2: Make a payment 
server side

Besides an always mandatory step of creating the paymentType resource, Unzer paylater-invoice also requires a customer and a basket resource.

Create the customer resource

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

B2C customer creation

To process transactions for B2C customers, the following customer fields are mandatory:

Parameter Type Description
firstname (required) string The customer’s first name
lastname(required) string The customer’s last name
salutation string Specify the customer’s Salutation. Available values are mr, mrs, unknown
customerId string Customer’s Unique ID. It identifies the customer and can be used within the GET request. It must be unique.
birthDate (required) string The birth date of the customer in ‘YYYY-MM-DD’ format.
email (required) string The customer’s email address
shippingAddress (required) object The customer’s shipping address.
shippingAddress.name string Name of person for the shipping address
shippingAddress.street string The customer’s street including house number
shippingAddress.state string The customer’s state
shippingAddress.zip string The customer’s postal code
shippingAddress.city string The customer’s city
shippingAddress.country string The customer’s country in ISO country code ISO 3166 ALPHA-2
shippingAddress.shippingType The shipping type, valid values are equals-billing,
different-address,
branch-pickup,
post-office-pickup,
pack-station
billingAddress (required if different from the shipping address) object The customer’s billing address
billingAddress.name string The customer’s name for the billing address
billingAddress.street string The customer’s street including house number
billingAddress.state string The customer’s state
billingAddress.zip string The customer’s postal code
billingAddress.city string The customer’s city
billingAddress.country string The customer’s country in ISO country code ISO 3166 ALPHA-2 (only for billing address)
POST https://api.unzer.com/v1/customers

{
    "firstname": "John",
    "lastname": "Doe",
    "salutation": "mr",
    "customerId": "12345678",
    "birthDate": "1987-12-20",
    "email": "John.Doe@unzer.com",
    "billingAddress": {
        "name": "John Doe",
        "street": "Hugo-Junkers-Str. 5",
        "state": "DE-BO",
        "zip": "60386",
        "city": "Frankfurt am Main",
        "country": "DE"
    },
    "shippingAddress": {
        "name": "John Doe",
        "street": "Hugo-Junkers-Str. 5",
        "state": "DE-BO",
        "zip": "60386",
        "city": "Frankfurt am Main",
        "country": "DE",
        "shippingType": "equals-billing"
    }
}

The response looks similar to the following example:

{
  "id":"s-cst-c552940bca23"
}

B2B customer creation

To process transactions for B2B customers, the following customer fields are mandatory:

Parameter Type Description
firstname (required) string The customer’s first name
lastname (required) string The customer’s last name
salutation (required) string Specify the customer’s salutation. Available values are mr, mrs, unknown
company(required) string The customer’s company name
customerId string Customer’s Unique ID. It identifies the customer and can be used within the GET request. It must be unique.
birthDate (required) string The birth date of the customer in ‘YYYY-MM-DD’ format
email (required) string The customer’s email address
shippingAddress (required) object The customer’s shipping address.
shippingAddress.name string Name of the customer for the shipping address
shippingAddress.street string The customer’s street including house number
shippingAddress.state string The customer’s state
shippingAddress.zip string The customer’s postal code
shippingAddress.city string The customer’s city
shippingAddress.country string The customer’s country in ISO country code ISO 3166 ALPHA-2
shippingAddress.shippingType The shipping type, valid values are equals-billing, different-address, branch-pickup, post-office-pickup, pack-station
billingAddress (required if different from the shipping address) object The customer’s billing address
billingAddress.name string The customer’s name for the billing address
billingAddress.street string The customer’s street
billingAddress.state string The customer’s state
billingAddress.zip string The customer’s postal code
billingAddress.city string The customer’s city
billingAddress.country string The customer’s country in ISO country code ISO 3166 ALPHA-2 (only for billing address)
companyInfo.companyType string The company type.
Valid values are authority, association, sole, company, other
companyInfo.registrationType string B2B is registered or not registered as a customer
companyInfo.function string Must be OWNER for NOT_REGISTERED, restricted ‘<’ and ‘>’
companyInfo.commercialSector string Mandatory if companyInfoModel.registrationType is REGISTERED, restricted ‘<’ and ‘>’
companyInfo.owner.firstname (required) string The first name of the company owner
companyInfo.owner.lastname (required) string The last name of the company owner
companyInfo.owner.birthDate (required) string The birth date of the company owner
POST https://api.unzer.com/v1/customers

{
    "firstname": "John",
    "lastname": "Doe",
    "salutation": "mr",
    "company": "Unzer GmbH",
    "customerId": "12345678",
    "birthDate": "1987-12-20",
    "email": "John.Doe@unzer.com",
    "billingAddress": {
        "name": "John Doe",
        "street": "Hugo-Junkers-Str. 5",
        "state": "DE-BO",
        "zip": "60386",
        "city": "Frankfurt am Main",
        "country": "DE"
    },
    "shippingAddress": {
        "name": "John Doe",
        "street": "Hugo-Junkers-Str. 5",
        "state": "DE-BO",
        "zip": "60386",
        "city": "Frankfurt am Main",
        "country": "DE",
        "shippingType": "equals-billing"
    },
    "companyInfo": {
        "registrationType": "not_registered",
        "function": "OWNER",
        "commercialSector": "AIRPORT",
        "companyType": "sole",
        "owner": {
            "firstname": "SoleFirst",
            "lastname": "SoleLast",
            "birthdate": "1995-06-21"
        }
    }
}
Currently not supported.
Currently not supported.

The response looks similar to the following example:

{
    "id": "s-cst-b9acaba781f3"
}

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

Create a basket resource

The basket resource stores information about the purchased products, used vouchers as well as the shipment costs.

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

{
    "currencyCode": "EUR",
    "orderId": "O-12345-AB",
    "totalValueGross": 2000.00,
    "note": "basket note",
    "basketItems": [
        {
            "title": "Notebook pro",
            "subTitle": "basket item subtitle",
            "basketItemReferenceId": "item-1",
            "quantity": 1,
            "amountPerUnitGross": 2000.00,
            "vat": 19,
            "type": "goods",
            "unit": "pc"
        }
    ]
}
Currently not supported
Currently not supported

The response looks similar to the following example:

{
  "id": "s-bsk-1380"
}

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

Make an authorize transaction

Now, make an authorize transaction with the paylater-invoice resource that you created earlier. With a successful authorize transaction, the amount is authorized and a payment resource is created. At this point no money has been transferred.

Parameter Type Description
amount (required) float The authorization amount
currency (required) string The authorization currency, in the ISO 4217 alpha-3 format (e.g. EUR)
invoiceId string The invoice ID for the payment from the shop system.
customerId (required) string The ID of the customers resource to be used (e.g. s-cst-e692f3892497)
basketId (required) string The basket ID for the payment
typeId (required) string The ID of the payment type resource to be used (such as s-piv-voi3gcbwinos)

Provide the customer risk information

To increase the acceptance rate of your invoice payments, we strongly recommend that you provide additional information about your customer. The following fields can be provided to allow us to apply a detailed risk check:

Parameter Type Description
threatMetrixId string The ThreatMetrix session ID
customerGroup string Customer classification for the customer if known valid values:
TOP: Customers with more than 3 paid* transactions
GOOD: Customers with more than 1 paid* transactions
BAD: Customers with defaulted/fraudulent orders
NEUTRAL: Customers without paid* transactions
confirmedAmount string The amount/value of the successful transactions paid by the end customer
confirmedOrders string The number of successful transactions paid* by the end customer
registrationLevel string Customer registration level
0=guest, 1=registered
registrationDate string Customer registration date in your shop
(YYYYMMDD)

*paid: A paid transaction is a transaction where you have the payment status of the customer for previous transactions (external factoring invoice, instalment or direct debit transactions must be excluded because you might have no information about the actual payment status of the customer).

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

Body
{
    "amount": "30.00",                                    
    "currency": "EUR",
    "invoiceId" : "INV-123456",
    "resources": {
        "customerId": "s-cst-e692f3892497",
        "basketId": "s-bsk-116",
        "typeId":  "s-piv-voi3gcbwinos"
    },
    "additionalTransactionData": {
      "riskData": {
        "threatMetrixId": "f544if49wo4f74ef1x",
        "customerGroup":"TOP",
        "confirmedAmount":"2569",
        "confirmedOrders":"14",
        "registrationLevel":"1",
        "registrationDate":"20160412"
      }
    }
}

Step 3: Check status of payment
server side

Once the transaction is made, 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. Check all possible payment states here.

GET: https://api.unzer.com/v1/payments/s-pay-xxxxxxx
Currently not supported
Currently not supported

Step 4: Display payment result
client side

Use the information from the check status of 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 Invoice payments, see Manage Unzer Invoice 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.

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