Accept SEPA Direct Debit with a server-side-only integration
Build your own payment form to add SEPA Direct Debit payment to the checkout page
Overview
SEPA Direct Debit requires the customer to provide their IBAN 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 SEPA Direct Debit component on our demo page.
Before you begin
Before you begin- Check the basic integration requirements.
- Familiarize yourself with the general Server-side-only integration guide.
Step 1: Create a payment type resourceserver side
Choose a one-off or a recurring mandate
Every SEPA Direct Debit payment is collected under a SEPA mandate. When you create the payment type, you decide which mandate type is used with the recurring parameter:
recurring | Use case | Mandate |
|---|---|---|
false or not set | One-off payment, or one-click payment with stored bank details | A new single-use (OOFF) mandate is created for every charge. The payment type itself has no mandate. |
true | Recurring payments, for example subscriptions | One reusable mandate is created when you create the payment type. Every charge with this payment type uses the same mandate: the first collection is sent as FRST, all later collections as RCUR. |
You do not send a sequence type (OOFF, FRST or RCUR). Unzer sets it for each collection.
recurring: true when you create the payment type.Retrieve the SEPA mandate text
Before the customer confirms the payment, you must show them the SEPA mandate text. Fetch the configuration for sepa-direct-debit using your public key. The response contains the creditor details and the mandate text in the customer’s language. If the mandate text cannot be fetched, do not offer SEPA Direct Debit to the customer.
| Parameter | Type | Description |
|---|---|---|
recurring | boolean | Set to true to get the text for a recurring mandate. Set to false or omit it to get the text for a one-off mandate. Use the same value that you send when you create the payment type. Default: false. |
Set the customer’s preferred language with the Accept-Language header, for example Accept-Language: de-DE. If the language is missing, invalid, or not supported, the English text is returned.
GET https://api.unzer.com/v1/types/sepa-direct-debit/config?recurring=true
Header:
Accept-Language: de-DE
The response looks similar to the following example:
{
"creditorId": "DE98ZZZ09999999999",
"iban": "DE89370400440532013000",
"creditorName": "Creditor Name",
"address": {
"street": "Main Street",
"houseNumber": "1",
"zipCode": "10115",
"city": "Berlin",
"country": "DE"
},
"mandateText": "<p>Ich ermächtige / Wir ermächtigen die <b>Creditor Name</b>, <b>Main Street 1, 10115 Berlin, DE</b>, Gläubiger-Identifikationsnummer: <b>DE98ZZZ09999999999</b>, wiederkehrende Zahlungen von meinem / unserem Konto mittels Lastschrift einzuziehen. Zugleich weise ich mein / weisen wir unser Kreditinstitut an, die von <b>Creditor Name</b> auf mein / unser Konto gezogenen Lastschriften einzulösen. Hinweis: Ich kann / Wir können innerhalb von acht Wochen, beginnend mit dem Belastungsdatum, die Erstattung des belasteten Betrages verlangen. Es gelten dabei die mit meinem / unserem Kreditinstitut vereinbarten Bedingungen.</p>",
"language": "de"
}
| Parameter | Type | Description |
|---|---|---|
creditorId | string | The SEPA creditor identifier. |
creditorName | string | The name of the creditor that collects the payments. |
iban | string | The IBAN of the creditor’s bank account. |
address | object | The address of the creditor, with street, houseNumber, zipCode, city and country (ISO 3166 ALPHA-2). |
mandateText | string | The SEPA mandate text in HTML format, with the creditor name, address and creditor identifier already filled in. Show it to the customer as HTML, so that the bold parts and line breaks are kept. |
language | string | The language of mandateText as a two-letter ISO 639-1 code, for example de. This is en if the requested language is not supported. |
bg, cs, da, de, el, en, es, et, fi, fr, hr, hu, it, lt, lv, nl, pl, pt, ro, ru, sk, sl, sv, tr. A language with a region, for example fr-CH, uses the text for the language (fr).Create the payment type
Data for the SEPA Direct Debit payment:
| Payment data | Description |
|---|---|
iban (required) | The IBAN of the customer. |
holder (required) | The bank account holder’s first and last name. Maximum 70 characters, at least 2 characters. The following characters are not allowed: < > § € ! “ # ; = @ [ ] \ _ | ~ …. A / is not allowed at the start or end, or twice in a row. For a one-off payment type without holder, the name of the customer is used. |
bic | The BIC of the customer’s bank. |
recurring | true creates a reusable mandate for recurring payments. false or not set: a new one-off mandate is created for every charge. Default: false. |
language | The customer’s preferred language for the mandate text, for example de or de-DE. Use the same language that you used to show the mandate text. Applies only if recurring is true. For one-off mandates, send language with the charge instead. If missing or not supported, en is used. |
When creating the payment type SEPA 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",
"holder" : "Maximilian Mustermann",
"recurring" : true,
"language" : "de-DE"
}
// 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("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": true,
"geoLocation": {
"clientIp": "127.0.0.143",
"countryIsoA2": "DE"
},
"iban": "DE89370400440532013000",
"bic": "",
"holder": "Maximilian Mustermann",
"mandateId": "3f2a9c1e-7b4d-4e8a-9f61-2c5d8e0b4a17"
}
The mandateId is the reference of the reusable mandate. It is returned only for a payment type that was created with recurring: true. A payment type created with recurring: false never has a mandateId, because its mandates are created with each charge. If you revoke a recurring payment type, the response shows recurring: false but still contains the mandateId of the revoked mandate. For details, see Revoke the mandate.
For a full description of SEPA Direct Debit payment type creation, check API reference.
Step 2: Make a paymentStep 2: Make a paymentserver 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.
What happens with the mandate depends on the payment type:
- One-off or one-click (
recurring: false): everychargecreates a new single-use (OOFF) mandate. You can send the optionallanguageparameter, for exampledeorde-DE, to store the mandate text in the language that you showed to the customer. If missing or not supported,enis used. - Recurring (
recurring: true): everychargeuses the mandate that was created with the payment type.languageis ignored.
You do not need to send the mandate in the charge request. Unzer adds it automatically.
The following example shows a one-off charge (recurring: false) with language:
POST https://api.unzer.com/v1/payments/charges
Body:
{
"amount": "20",
"currency": "EUR",
"language": "de-DE",
"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"
},
"additionalTransactionData": {
"sepaDirectDebit": {
"mandateId": "b8e14d52-0c3a-4f97-a6d2-91e7f5c3b208",
"mandateSignatureDate": "2021-05-10"
}
}
}
The additionalTransactionData.sepaDirectDebit object shows the mandate that the charge was collected under:
| Parameter | Type | Description |
|---|---|---|
mandateId | string | The SEPA mandate reference. For a one-off or one-click payment, this is a new mandate for every charge. For a recurring payment type, this is always the mandateId of the payment type. |
mandateSignatureDate | string | The date the mandate was signed, in the format YYYY-MM-DD. For a one-off or one-click payment, this is the date of the charge. |
The same object is returned for each charge transaction when you fetch the payment with GET https://api.unzer.com/v1/payments/{paymentId}.
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 paymentserver side
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 resultclient side
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 paymentserver side
For more details on managing SEPA Direct Debit payments, such as refunding them, see Manage SEPA Direct Debit payments
Notifications
NotificationsWe 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
Error handlingAll 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
Test & go liveYou 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.
