alt

Important information

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

Unzer

Accept Unzer Direct Debit Secured with server-side-only integration

Build your own payment form to add Unzer Direct Debit Secured payment to the checkout page

Overview

Unzer Direct Debit Secured payment method works similarly to Unzer Direct Debit, it too requires the customer to input their IBAN on the merchants website. You can see an example of the Unzer Direct Debit Secured component on our demo page.

In order for the insurance provider to properly insure a payment, a customer resource should be passed along with the payment request. If you don’t already have a customer resource available, you can create an Unzer Direct Debit Secured UI with a customer form attached.

Before you begin

Step 1: Create a payment type resource
server side

Data for the payment type:

Payment dataDescription
iban (required)The IBAN of the customer

When creating the payment type Unzer Direct Debit Secured, you need to send a request to the Unzer API. The response contains an id , this is later referred to as typeId. You will need this typeId to perform the transaction.


POST https://api.unzer.com/v1/types/sepa-direct-debit-secured

{
  "iban":"DE89370400440532013000"
}
// get the IBAN from your payment form.
$unzer = new Unzer('s-priv-xxxxxxxxxx', SupportedLocale::GERMAN_GERMAN);
$dss= $unzer->createPaymentType(new SepaDirectDebitSecured($iban));
// get the IBAN from your payment form.
Unzer Unzer = new Unzer("s-priv-xxxxxxxxxx");
SepaDirectDebitSecured sepaDirectDebitSecured1 = new SepaDirectDebitSecured(iban);

The response looks similar to the following example:

{
    "id": "s-dds-e37mxcqfq3jo",
    "method": "sepa-direct-debit-secured",
    "recurring": false,
    "geoLocation": {
        "clientIp": "84.115.229.12",
        "countryIsoA2": "AT"
    },
    "iban": "DE89370400440532013000",
    "bic": "COBADEFFXXX",
    "holder": ""
}

For a full description of Unzer Installment payment type creation, check the API reference.

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