Accept Unzer Prepayment with UI components
Use Unzer UI component to add Unzer Prepayment payment method to your checkout page.
Overview
Using UI components v2 for Unzer Prepayment you create a payment type resource that will be used to make the payment. Basic steps for integrating using UI components are the same for all payment methods and you can read about them here.
Legacy integration
This page describes the most recent integration of the UI Components, introduced in Jan 2025. For the Legacy integration guide go 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 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 with unzer-
prefixed. For example, <unzer-paylater-invoice>
.
Make sure to always include the script directly from the Unzer domain https://static-v2.unzer.com
.
<script
type="module"
src="https://static-v2.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>
Add Unzer Prepayment payment method
To add the Unzer Prepayment payment method insert unzer-prepayment
in the unzer-payment
container.
<unzer-payment
publicKey="s-pub-xxxxxxxxxx"
locale="de-DE">
<unzer-prepayment></unzer-prepayment>
<unzer-payment>
<unzer-checkout>
<button type="submit" id="yourPaymentButtonId">Pay</button>
</unzer-checkout>
<unzer-checkout>
element.
This will provide automatic handling of the submit whenever the user clicks the submit button, and passing back the
creation payload.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.
// Make sure that this code is executed after the elements are rendered
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 Prepayment
typeId
that you created. With a successful charge
transaction a payment
resource is created. At this point no money has been transferred. The customer has to transfer the amount to the bank account which information are provided in the charge transaction response.
POST https://api.unzer.com/v1/payments/charges
{
"amount" : "50",
"currency" : "EUR",
"returnUrl" : "https://www.my-shop-url.de/returnhandler",
"resources" : {
"typeId" : "s-ppy-ptz1cm2u4x7i"
}
}
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$prepayment = $unzer->fetchPaymentType('s-ppy-ptz1cm2u4x7i');
$charge = $prepayment->charge(20.0, 'EUR', 'https://www.my-shop-url.de/returnhandler');
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Prepayment charge = unzer.charge(BigDecimal.ONE, Currency.getInstance("CHF"), "s-ppy-ptz1cm2u4x7i", new URL("https://www.my-shop-url.de/returnhandler"));
The response looks similar to the following example:
{
"id": "s-chg-1",
"isSuccess": true,
"isPending": false,
"isError": false,
"message": {
"code": "COR.000.100.112",
"customer": "Request successfully processed in 'Merchant in Connector Test Mode'"
},
"amount": "50.6000",
"currency": "EUR",
"returnUrl": "https://www.my-shop-url.de/returnhandler",
"date": "2018-09-26 14:15:13",
"resources": {
"paymentId": "s-pay-7786",
"typeId": "s-ppy-ptz1cm2u4x7i"
},
"processing": {
"iban": "DE89370400440532013000",
"bic": "COBADEFFXXX",
"uniqueId": "31HA07BC8137E7B23DE99031E56C4924",
"shortId": "4018.9771.3370",
"descriptor": "4018.9771.3370",
"holder": "Merchant Thuan"
}
}
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
Once the transaction is made, 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. Check all possible payment states here.
Charge
will always be in status pending.GET https://api.unzer.com/v1/payments/{payment_ID}
{
"id": "s-pay-921",
"state": {
"id": 0,
"name": "pending"
},
"amount": {
"total": "50.6000",
"charged": "0.0000",
"canceled": "0.0000",
"remaining": "50.6000"
},
"currency": "EUR",
"orderId": "",
"invoiceId": "",
"resources": {
"customerId": "",
"paymentId": "s-pay-921",
"basketId": "",
"metadataId": "",
"payPageId": "",
"traceId": "b51b892a8896e73c8cfe740803e79531",
"typeId": "s-ppy-vaq3p5vkfbmm"
},
"transactions": [
{
"date": "2021-05-17 11:51:32",
"type": "charge",
"status": "pending",
"url": "https://api.unzer.com/v1/payments/s-pay-921/charges/s-chg-1",
"amount": "50.6000"
}
]
}
Step 4. Display payment resultclient side
After the transaction is made you should display its result to the customer in the front end. Here you have to display the bank Information, the customer should transfer the money to.
They can also be shown on the success page or in the customer backend of your shop.
sprintf(
"Please transfer the amount of %f %s to the following account:<br /><br />"
. "Holder: %s<br/>"
. "IBAN: %s<br/>"
. "BIC: %s<br/><br/>"
. "<i>Please use only this identification number as the descriptor: </i><br/>"
. "%s",
$charge->getAmount(),
$charge->getCurrency(),
$charge->getHolder(),
$charge->getIban(),
$charge->getBic(),
$charge->getDescriptor()
);
Manage paymentserver side
For more details on managing Unzer Prepayment payments, such as refunding them, see Manage Unzer Prepayment 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.