alt

Important information

Updates to Visa secure data field mandate: Read more about the mandatory changes.

Unzer

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

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

Overview

Unzer Direct Debit requires the customer to provide his IBAN and bank account holder’s first and last name on the merchants website. With that information, the payment method is used to charge a customer bank account directly. You can see an example of the Unzer Direct Debit component on our demo page.

Before you begin

Step 1: Create a payment type resource
server side

Data for the Unzer Direct Debit payment:

Payment dataDescription
accountHolder (required)Specifies the bank account holder’s first and last name
iban (required)The IBAN of the customer

When creating the payment type Unzer Direct Debit, you need to send a request to the Unzer API. The response will contain 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

{
  "iban" : "DE89370400440532013000",
  "accountHolder" : "Maximilian Mustermann"
 
}
// get the IBAN from your payment form.
$unzer = new Unzer('s-priv-xxxxxxxxxx', SupportedLocale::GERMAN_GERMAN);
$sdd= $unzer->createPaymentType(new SepaDirectDebit($iban, $accountHolder));
Unzer unzer = new Unzer(new HttpClientBasedRestCommunication(), "s-priv-xxxxxxxxxx");
SepaDirectDebit sdd = new SepaDirectDebit(iban, accountHolder);
sdd = unzer.createPaymentType(sdd);

The response looks similar to the following example:

{
    "id": "s-sdd-x9z2efxuebce",
    "method": "sepa-direct-debit",
    "recurring": false,
    "geoLocation": {
        "clientIp": "127.0.0.143",
        "countryIsoA2": "DE"
    },
    "iban": "DE89370400440532013000",
    "bic": "",
    "accountHolder": "Maximilian Mustermann"
}

For a full description of Unzer Direct Debit payment type creation, check API reference.

Step 2: Make a payment
server side

Make a charge transaction

Now, make a charge transaction with the SepaDirectDebit typeId that you created in the frontend. With a successful charge transaction 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": {
      "typeId": "s-sdd-zquetx73qvpm"
  }
}
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$sepa-direct-debit = $unzer->fetchPaymentType('s-sdd-zquetx73qvpm');
$charge = $sepa-direct-debit->charge(20.0, 'EUR');
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Charge charge = unzer.charge(BigDecimal.ONE, Currency.getInstance("EUR"), "s-sdd-zquetx73qvpm");

The response looks similar to the following example:

{
    "id": "s-chg-1",
    "isSuccess": true,
    "isPending": false,
    "isError": false,
    "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": "",
    "date": "2021-05-10 15:29:09",
    "resources": {
        "paymentId": "s-pay-133634",
        "traceId": "bbaeefa04492a6bd033845de78b1f774",
        "typeId": "s-sdd-zquetx73qvpm"
    },
    "paymentReference": "",
    "processing": {
        "creatorId": "13213213344324324",
        "identification": "4851.9174.9801",
        "iban": "DE89*************3000",
        "bic": "CO******XX",
        "uniqueId": "31HA07BC813E8DE2B6D6096556538A37",
        "shortId": "4851.9174.9801",
        "traceId": "bbaeefa04492a6bd033845de78b1f774"
    }
}

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 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-xxxx",
  "state": {
    "id": 1,
    "name": "completed"
  },
  "amount": {
    "total": "119.0000",
    "charged": "119.0000",
    "canceled": "0.0000",
    "remaining": "0.0000"
  },
  "currency": "EUR",
  "orderId": "My Order Id",
  "invoiceId": "",
  "resources": {
    "customerId": "",
    "paymentId": "s-pay-xxxx",
    "basketId": "",
    "metadataId": "",
    "payPageId": "",
    "traceId": "e4c4fb1c81d2167eb86eb5a68cfb7760",
    "typeId": "s-sdd-xxxxxxxxxxx"
  },
  "transactions": [
    {
      "date": "2021-05-27 11:45:46",
      "type": "charge",
      "status": "success",
      "url": "https://api.unzer.com/v1/payments/s-pay-xxxx/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 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 payments, such as refunding them, see Manage Unzer Direct Debit 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