Accept Unzer Direct Debit with UI components v2
BetaUse Unzer UI component to add Unzer Direct Debit payment to your checkout page.
Overview
Using UI components v2 for Unzer Direct Debit, you can create a paylater-direct-debit
payment type resource that is used to make the payment.
The form of this payment type consists of the IBAN, Account holder, and a birth date input fields.
Basic steps for integrating using UI components are the same for all payment methods, and you can read about them here.
With Unzer Direct Debit you need to provide information about the customer via a customer
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
Before you begin- Check the basic integration requirements.
- Familiarize yourself with general guide on integrating using UI components.
Step 1: Add UI components v2 to your payment pageclient side
Step 1: Add UI components v2 to your payment page [client side]First, you need to initiate our UI components v2 library and add the needed payment type component to your payment page.
Initiate UI Components
Initiate UI Components v2Load the Unzer JS script
Load the Unzer JS scriptInclude the Unzer JS script on your website. This will load all the Unzer custom UI components, prefixed with unzer-
e.g <unzer-paylater-invoice>
.
Make sure to always include the script directly from the Unzer domain https://static.unzer.com
<script
type="module"
src="https://static.unzer.com/v2/ui-components/index.js"
></script>
To make your website load faster, import the unzer script at the bottom of your HTML document.
Make sure to import the script as type=“module”
To learn which URLs must be added to the allowlist for Unzer UI components in your content security policy, please refer to Content security policy section.
It is a good practice to put your website in loading state until the Unzer script is loaded, and the UI components are ready to use.
// Make sure initially your application is in loading state
// until all Unzer components are loaded
Promise.all([
customElements.whenDefined("unzer-payment"),
// Probably add any other Unzer components used here. For example:
// customElements.whenDefined("unzer-paylater-invoice"),
]).then(() => {
// Hide the loading state and proceed with next steps
}).catch((error) => {
// Handle any error that might occur during the
// loading process and initialization
});
UI setup and configuration
UI setup and configurationTo securely collect payment data from your customer, you need to add the <unzer-payment>
component, inside which you insert the needed payment type components.
<unzer-checkout>
element.
This will provide automatic handling for enabling/disabling the submit button depending on the current status,
and showing/hiding of brand icons.<unzer-payment
id="unzer-payment"
publicKey="s-pub-xyz"
locale="de-DE">
<!-- ... Here you will need to add the Unzer payment type tag, so the form UI elements will be inserted -->
<!-- e.g <unzer-paylater-invoice></unzer-paylater-invoice> -->
</unzer-payment>
<unzer-checkout id='unzer-checkout'>
<button type="submit" id="yourPaymentButtonId">Pay</button>
</unzer-checkout>
Following parameters need to be passed.
Parameter | Type | Description | Default value |
---|---|---|---|
publicKey (required) | String | The merchant public key. | - |
locale | String | The used locale. For more information on supported locales, see Localization. | Browser user defined locale. |
initData | object | A key/value object in JSON-format containing data to initialize the payment type. For more information, Check payment methods and their features. | Empty object {} |
Optional: Customize UI components
Optional: Customize UI componentsOur UI Components v2 are provided with a default theme that contains base styles. You can easily customize these styles by overriding the following CSS variables.
Variable name | Description | Affected components |
---|---|---|
--unzer-font | Replaces all fonts with the given font. Users can define any font-face and provide the name of the custom font-face. | typography |
--unzer-text-color | The font color use for typography. | typography, icons |
--unzer-brand-color | The main color of the application. | button, checkbox, radio, loader |
--unzer-background-color | The page background. | |
--unzer-link-color | The color of links. | link |
--unzer-corner-radius | Whether controls will have rounded corners or not. Values can be either 0 or 1. | button, tags, chips |
--unzer-shadows | Whether shadows are enabled or not. Values can be either 0 or 1. | button, card |
<head>
<style>
:root {
--unzer-font: SFMono;
--unzer-brand-color: #ee1818;
--unzer-text-color: #f19316;
--unzer-background-color: #6a9472;
--unzer-link-color: #1330ef;
--unzer-corner-radius: 0;
--unzer-shadows: 1;
}
</style>
</head>
Implement the payment form
First you need to insert the Unzer Direct Debit <unzer-paylater-direct-debit>
inside the <unzer-payment>
and add your submit button.
<unzer-payment
id="unzer-payment"
publicKey="s-pub-xyz"
locale="de-DE">
<unzer-paylater-direct-debit></unzer-paylater-direct-debit>
</unzer-payment>
<unzer-checkout id='unzer-checkout'>
<button type="submit" id="yourPaymentButtonId">Pay</button>
</unzer-checkout>
In case you want also to create/update your customer information, then you will need to use our Unzer UI customer elements.
Option 1: Implement with customer elements
Option 1: Implement with customer elementsIf 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 Unzer UI customer elements.
Customer element | Description |
---|---|
<unzer-shipping-address> | Adds the customer shipping address information (email, salutation, firstname, lastname, country, street, post code, city, mobile number) |
<unzer-billing-address> | Adds the customer billing address information (firstname, lastname, country, street, post code, city). |
The Unzer UI customer elements can be inserted either inside or outside the <unzer-payment>
element.
On submit, all data from the added Unzer UI customer elements will be gathered and submitted together with the payment form,
in order to create the customer and payment type resources.
In case you wish to initialize the customer elements with the data of an already created customer, you will need to call
the setCustomerData()
function of the <unzer-payment>
element, and pass a customer object in JSON format.
customer object
Parameter | Type | Description | Default value |
---|---|---|---|
id | String | The ID of the customer you wish to update. If not passed, then a new customer will be created. | |
salutation | String | The salutation for the customer. Allowed values are:"mr" , "mrs" , "diverse" | "mr" |
firstname | String | The first name of the customer. | "" |
lastname | String | The last name of the customer. | "" |
birthDate | String | The birth date of the customer. | "" |
email | String | The E-mail of the customer. | "" |
mobileNumber | mobileNumber Object | The mobile number | {} |
shippingAddress | address object | The shipping address for the customer in JSON format. | {} |
billingAddress | address object | The billing address for the customer in JSON format. | {} |
address object
Parameter | Type | Description | Default value |
---|---|---|---|
name | String | The firstname + lastname of the customer | "" |
street | String | The street and house number | "" |
zip | String | The zip-code | "" |
city | String | The city | "" |
state | String | The state | "" |
country | String | The country ISO country code ISO 3166 ALPHA-2 | "DE" |
shippingType only in shippingAddress | String | The shippingType. Allowed values are:"equals-billing" , "different-address" , "branch-pickup" , "post-office-pickup" , "pack-station" | "DE" |
mobileNumber object
Parameter | Type | Description | Default value |
---|---|---|---|
prefix | String | The country prefix of the mobile number | "" |
phone | String | The mobile number | "" |
The following code example shows the options described above:
<unzer-payment
id="unzer-payment"
publicKey="s-pub-xyz"
locale="de-DE">
<unzer-paylater-direct-debit></unzer-paylater-direct-debit>
</unzer-payment>
<p>Shipping Information</p>
<unzer-shipping-address></unzer-shipping-address>
<p>Billing Information</p>
<unzer-billing-address></unzer-billing-address>
<unzer-checkout id='unzer-checkout'>
<button type="submit" id="yourPaymentButtonId">Pay</button>
</unzer-checkout>
const unzerPaymentElement = document.getElementById('unzer-payment');
unzerPaymentElement.setCustomerData({
"id": "s-cst-xyz",
"lastname": "Universum",
"firstname": "Peter",
"salutation": "mr",
"birthDate": "20.12.1987",
"mobileNumber": {
"prefix": "49",
"phone": "1234"
},
"shippingAddress": {
"name": "Peter Universum",
"street": "Hugo-Junkers-Str. 5",
"zip": "60386",
"city": "Frankfurt am Main",
"country": "DE",
"shippingType": "equals-billing"
},
"billingAddress": {
"state": "Peter Universum",
"street": "Hugo-Junkers-Str. 5",
"zip": "60386",
"city": "Frankfurt am Main",
"country": "DE"
}
})
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.
In that case you just need to render the payment type form and create a simple HTML button on the client side.
Create Payment Type and Customer Resources
Create Payment Type and Customer ResourcesAfter the submit button is clicked, the customer and payment data are automatically submitted. You will then need
to query the unzer-checkout
element and handle the response inside its onPaymentSubmit
event listener.
The following code example shows how to read customer and payment data from the response.
// ...
const unzerCheckout = document.getElementById('unzer-checkout');
unzerCheckout.onPaymentSubmit = (response) => {
if (response.submitResponse && response.customerResponse) {
if (response.customerResponse.success) {
// Optional: Only in case a new customer is created in the frontend.
const customerId = response.customerResponse.data.id;
}
if (response.submitResponse.success) {
const paymentTypeId = response.submitResponse.data.id;
}
// Submit all IDs to your server-side integration to perform the payment transaction.
}
};
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.
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 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 Unzer Direct Debit payments, such as refunding them, see Manage Unzer 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.