Basic usage of the Java SDK

Learn about the basic usage of the Java SDK.

The Unzer object

The Unzer object is the main object. You always need it, in order to communicate with the Unzer Payment API (PAPI). In addition it is the facade to all functionality in the SDK. It provides:

  • methods to perform CRUD operations on the resources (payment typecustomerbasket, etc.)
  • methods that allow transactions like authorizationchargecancellation (i.e.refund and reversal) and shipment

This means you have to create the Unzer object and provide your private-key prior to anything you want to do with the SDK.

In order to show potential error messages in the language of the client you can provide the locale within the second argument of the Unzer class constructor. Please refer to the Localisation page for a list of supported locales.

Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');
Unzer unzer = new Unzer('s-priv-xxxxxxxxxx', Locale.GERMANY);

The Payment object

Whenever an authorization or a charge transaction is performed successfully an instance of the Payment class is automatically created.

The Payment object contains all information on the payment process and ties all required resources together. These are some of the information the Payment object stores:

  • references to customer, payment type, etc.
  • references to transactions: charges, authorization, shipment, etc.
  • the amount information: total, charged, canceled and remaining
  • the currency
  • the state of the payment: pending, canceled, completed, etc.

By fetching the Payment object, you can access all the information for the complete payment process.

For a full description of the payment resource please refer to Check payment details

Creating a Payment Type resource

In order to perform transactions the API needs to know, which payment type to use. There are two options here:

  1. reference a payment type that already exists (e. g. registered credit card)
  2. create and reference a new payment type

The following examples show how to create selected payment types.

Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');

Card card = new Card("4711100000000000", "03/99");
card = unzer.createPaymentType(card);
Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');

SepaDirectDebit sdd = new SepaDirectDebit("DE89370400440532013000");
sdd = unzer.createPaymentType(sdd);
Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');

Paypal paypal = new Paypal();
paypal = unzer.createPaymentType(paypal);
Restrictions on card types
You cannot create the Card type with the Java SDK unless you are PCI compliant.
Please refer Card UI Components integration guide  to learn how to use our UI Components to handle card information.

Update a Payment Type resource

Properties of the Unzer Instalment payment type can be updated.

// update Unzer Instalment payment type
Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');

InstallmentSecuredRatePlan installmentSecuredRatePlan = unzer.fetchPaymentType("s-priv-1");

Instant now =;
Instant yesterday = now.minus(1, ChronoUnit.DAYS);

installmentSecuredRatePlan.setAccountHolder("Peter Universum");

installmentSecuredRatePlan = unzer.updatePaymentType(installmentSecuredRatePlan);

Next steps