Accept SEPA Direct Debit with UI components (Legacy)
This is legacy documentation.
- If you are integrating for the first time, go to v2 components.
Use Unzer UI component to add SEPA Direct Debit payment to your checkout page.
Overview
Using UI components for SEPA Direct Debit you get a ready-made form with the 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.
Before you begin
Before you begin- Check the basic integration requirements.
- Familiarize yourself with general guide on integrating using UI components.
Step 1: Add UI components to your payment pageclient side
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
Initiate UI componentLoad our JS script and CSS stylesheet
Load our JS script and CSS stylesheetInclude Unzer’s script and stylesheet on your website.
Always load the script and stylesheet directly from Unzer:
<link rel="stylesheet" href="https://static.unzer.com/v1/unzer.css" />
<script type="text/javascript" src="https://static.unzer.com/v1/unzer.js"></script>
To make your website load faster, insert JavaScript scripts at the bottom of your HTML document.
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 instanceCreate an unzer instance with your public key:
// Creating an unzer instance with your public key
var unzerInstance = new unzer('s-pub-xxxxxxxxxx');
In the previous example, we used a placeholder API key for example purposes. You should replace it with your public key.
Localization and languages
Localization and languagesWe 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
To securely collect payment data from your customer, you need to create a payment form with empty DOM elements and unique ID’s within them. That way unzer.js will know where to place its UI components.
<form id="payment-form" class="unzerUI form" novalidate>
<div id="sepa-IBAN" class="field">
<!-- The IBAN field and the SEPA mandate text will be inserted here -->
</div>
<button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>
Matching IDs
When choosing your ID for a UI component, make sure that the names in your HTML and JavaScript match.
For example:
<div id="sepa-IBAN"> matches containerId: "sepa-IBAN".
SEPA mandate
SEPA Direct Debit payment method requires an approval of SEPA mandate by the customer.
If SEPA Direct Debit is set up for you on the Unzer Payment Processing Platform, the SEPA Direct Debit component loads the mandate text and a consent text from Unzer and shows them. You do not need the sample below.
The SEPA Direct Debit form shows these texts by itself in its container; you do not add them. Place the container above your submit button, so that the customer sees the texts before the submit button and they refer directly to the submit action.
When the customer pays with a stored SEPA Direct Debit type, the SEPA Direct Debit form is not used, so no mandate text is shown automatically. In this case you must add unzerInstance.SepaMandate() to your checkout yourself, with its container also above the submit button. For details, see Pay with a stored SEPA Direct Debit type.
Unzer cannot check what your checkout shows, so you are responsible for placing the components correctly.
If the mandate text cannot be loaded, the component shows “This payment method is currently unavailable.” and createResource() is rejected, so no payment is sent.
If SEPA Direct Debit is set up for you on the legacy core, you can use the following sample mandate text on your page.
| SEPA mandate sample: English text | SEPA mandate sample: German text |
|---|---|
| SEPA Direct Debit Mandate By signing this mandate form, you authorize {NAME OF MERCHANT} to send instructions to your bank to debit your account and your bank to debit your account in accordance with the instructions from {NAME OF MERCHANT}. Note: As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited. Your rights regarding this SEPA mandate are explained in a statement that you can obtain from your bank. In case of refusal or rejection of direct debit payment I instruct my bank irrevocably to inform {NAME OF MERCHANT} or any third party upon request about my name, address and date of birth. | SEPA Lastschrift-Mandat (Bankeinzug) Ich ermächtige {NAME OF MERCHANT}, Zahlungen von meinem Konto mittels SEPA Lastschrift einzuziehen. Zugleich weise ich mein Kreditinstitut an, die von {NAME OF MERCHANT} auf mein Konto gezogenen SEPA Lastschriften einzulösen. Hinweis: Ich kann innerhalb von acht Wochen, beginnend mit dem Belastungsdatum, die Erstattung des belasteten Betrags verlangen. Es gelten dabei die mit meinem Kreditinstitut vereinbarten Bedingungen. Für den Fall der Nichteinlösung der Lastschriften oder des Widerspruchs gegen die Lastschriften weise ich meine Bank unwiderruflich an, {NAME OF MERCHANT} oder Dritten auf Anforderung meinen Namen, Adresse und Geburtsdatum vollständig mitzuteilen. |
Create a payment type resource
Call the method unzerInstance.SepaDirectDebit() to create an instance of the Payment Type SEPA Direct Debit.
// Creating an SEPA Direct Debit instance
var directDebit = unzerInstance.SepaDirectDebit()
// Rendering the input field
directDebit.create('sepa-direct-debit', {
containerId: 'sepa-IBAN'
});
Add an event listener for “submit” of the form.
Inside, create a Promise on the SepaDirectDebit object. The Promise gets either resolved or rejected:
let form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
directDebit.createResource()
.then(function(result) {
// Submit the ID of the created payment type to your
// backend to perform the payment transaction with it.
typeId = result.id;
})
.catch(function(error) {
// handle errors
document.getElementById('error-holder').innerText = error.customerMessage || error.message || 'Error'
})
});
Optional: Recurring payments
For SEPA Direct Debit, the recurrence intent is set when the payment type is created, not on the charge. There is no recurrence field on a SEPA Direct Debit charge.
To create a payment type for recurring payments, set the recurring option of the SEPA Direct Debit form to true. With true, the form loads the mandate text for a reusable mandate. Without the option, or with false, it loads the mandate text for one-off and one-click payments.
var directDebit = unzerInstance.SepaDirectDebit()
directDebit.create('sepa-direct-debit', {
containerId: 'sepa-IBAN',
recurring: true
});
For later charges, use the typeId of the payment type that you created this way.
Pay with a stored SEPA Direct Debit type
When the customer pays with a stored SEPA Direct Debit type, no new payment type is created, but the customer still has to see the mandate text. You must add unzerInstance.SepaMandate() to your checkout for this, with its container above the submit button. It loads and shows the mandate text in the same way as the SEPA Direct Debit form, but does not create a payment type.
Set recurring to the same value that was used when the stored type was created. For saved bank details, this is false. If SEPA Direct Debit is set up for you on the legacy core, SepaMandate shows no text.
<form id="payment-form" class="unzerUI form" novalidate>
<div id="sepa-mandate">
<!-- The SEPA mandate text will be inserted here -->
</div>
<div id="error-holder"></div>
<button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>
var sepaMandate = unzerInstance.SepaMandate()
sepaMandate.create({
containerId: 'sepa-mandate',
recurring: false
});
let form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
sepaMandate.createResource()
.then(function() {
// The mandate text is shown. Charge the stored
// SEPA Direct Debit type on your backend.
})
.catch(function(error) {
// The mandate text could not be loaded. Do not charge the stored type.
document.getElementById('error-holder').innerText = error.customerMessage || error.message || 'Error'
})
});
Saved bank details (one-click) are for customer-initiated payments only and use a one-off mandate (recurring is false). They do not give you the right to collect from the customer’s account repeatedly.
Limitations
recurring: truecreates a reusable SEPA mandate. The mandate does not record whether later payments are scheduled or unscheduled, and you cannot tell them apart afterwards, neither in the API nor in reporting.recurringonly takes effect if SEPA Direct Debit is set up for you on the Unzer Payment Processing Platform. Merchants on the legacy core see no change and will be migrated to the Payment Processing Platform soon.- SEPA Direct Debit does not support
authorize. Use achargetransaction. - SEPA Direct Debit is not available on recurring Payment Page v1. For SEPA Direct Debit on recurring payment pages, see SEPA Direct Debit on recurring payment pages.
Optional: Customize UI components
You can easily customize the font of the form by changing the options within the create method. Here you can set the following styles: fontSize, fontColor and fontFamily.
Sepa.create('sepa-direct-debit', {
containerId: 'sepa-IBAN',
fontSize: '16px',
fontColor: 'lightgrey',
fontFamily: 'Arial, Helvetica, sans-serif'
});
recurring: true) or the mandate text in the customer’s language, you need the server-side integration. For details, see Accept SEPA Direct Debit with a server-side-only integration.Step 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.
