Java SDK

Check out our Java SDK.

Maven Integration

The SDK can be downloaded from the central maven repository (version x.x.x.x, see https://mvnrepository.com/artifact/com.heidelpay.payment/heidelpayJava ). The dependency for the Java Unzer SDK is the following:

<!-- https://mvnrepository.com/artifact/com.heidelpay.payment/heidelpayJava -->
<dependency>
    <groupId>com.heidelpay.payment</groupId>
    <artifactId>heidelpayJava</artifactId>
    <version>x.x.x.x</version>
</dependency>

heidelpay class

The heidelpay class is instantiated using your private or public key:

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

Payment type objects

How to create payment types
We recommend to create the payment types using our Javascript or Mobile SDK.
Restrictions on card types
You cannot create credit card types with the Java SDK unless you are fully PCI DSS certified.
Please refer to our Web Integration documentation to learn how to use our UI Components to handle card information.

With the payment type object you specify which payment method you want to use. Some of the payment methods expect data, others are just empty:

Payment type object Description
com.heidelpay.payment.paymenttypes.Card Credit card payments
com.heidelpay.payment.paymenttypes.Giropay Online Banking using Giropay
com.heidelpay.payment.paymenttypes.Ideal Online Banking using iDEAL
com.heidelpay.payment.paymenttypes.Invoice Invoice
com.heidelpay.payment.paymenttypes.InvoiceGuaranteed Unzer Invoice Secured
com.heidelpay.payment.paymenttypes.Paypal PayPal
com.heidelpay.payment.paymenttypes.Prepayment Unzer Prepayment
com.heidelpay.payment.paymenttypes.Przelewy24 Przelewy24
com.heidelpay.payment.paymenttypes.SepaDirectDebit Unzer Direct Debit
com.heidelpay.payment.paymenttypes.SepaDirectDebitGuaranteed Unzer Direct Debit Secured
com.heidelpay.payment.paymenttypes.Sofort Online Banking using Sofort

Start your payment

There are two ways to execute a payment. If you have already created a payment type resource using our Web integration or the Mobile integration you only need to pass the returned id to the authorize or charge call.

If you did not create a payment type so far, you have to pass the payment type object to the authorize or charge call.

Authorize a payment (reserve money on the customers payment account):

Authorize
Authorize is not possible for all payment types. Only the payment types listed in Authorize are supported
Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

// Already created the payment type using our Javascript or Mobile SDK's
Authorization authorize = heidelpay.authorize(BigDecimal.ONE, Currency.getInstance("EUR"), "s-crd-fm7tifzkqewy", new URL("https://www.heidelpay.com"));


// Without a payment type created before
Card card = new Card("4444333322221111", "12/19");
Authorization authorize2 = heidelpay.authorize(BigDecimal.ONE, Currency.getInstance("EUR"), card, new URL("https://www.heidelpay.com"));

The return object is an Authorization. If the redirectUrl within the Authorization object is not null then you have to redirect the end customer to this url. This is needed for all payment methods which require some additional input from the customer, such as Sofort, Giropay, Ideal, P24, Paypal and Card payments in case of 3DS.

Charge a payment

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

// Already created the payment type using our Javascript or Mobile SDK's
Charge charge2 = heidelpay.charge(BigDecimal.ONE, Currency.getInstance("EUR"), "s-sft-fm7tifzkqewy", new URL("https://www.heidelpay.com"));


// Without a payment type created before
Charge charge2 = heidelpay.charge(BigDecimal.ONE, Currency.getInstance("EUR"), new Sofort(), new URL("https://www.heidelpay.com"));

The return object is a Charge. If the redirectUrl within the Charge object is not null then you have to redirect the end customer to this url.

Payment id
You should store the payment id which you get by calling authorize.getPaymentId() or charge.getPaymentId()

Payment status

You can always retrieve the payment status by fetching the payment with the payment id:

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

Payment payment = heidelpay.fetchPayment(authorize.getPayment().getId());

The payment object gives you an overview about the payment:

Property Description
paymentState
amountTotal
amountCharged
amountCanceled
amountRemaining
Overview about the amounts. For details about the amounts check Payments
customerId
paymentTypeId
ID of all referenced resources
authorization
chargesList
cancelList
List of all transactions involved within this payment

Charge after Authorize

If you started with an Authorize you can easily load the Authorization object or the Payment object and execute a charge on it.

Alternative you can also authorize using the heidelpay object.

All 3 options are listed in the code samples:

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

// Charge using Authorize object
Authorization authorization = heidelpay.fetchAuthorization("s-pay-1");
Charge charge = authorization.charge();

// Charge using Payment object
Payment payment = heidelpay.fetchPayment("s-pay-1");
Charge charge2 = payment.charge();

// Charge using heidelpay object
Charge charge3 = heidelpay.chargeAuthorization("s-pay-1");

Cancel an Authorize

To cancel an Authorization you can either fetch the Payment object or the Authorization object and execute a cancel on it.

Alternatively the heidelpay object also provides methods to cancel an Authorization.

When canceling an Authorization you can also provide an amount. In this case the Authorization is canceled only partly.

All 3 options are listed within the sample code:

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

// Cancel Authorization
Authorization authorization = heidelpay.fetchAuthorization("s-pay-1");
Cancel cancel = authorization.cancel();
// Or
Cancel cancel = authorization.cancel(new Cancel());

// Cancel Payment
Payment payment = heidelpay.fetchPayment("s-pay-1");
Cancel cancel2 = payment.cancel(new BigDecimal(0.1));

// Cancel using heidelpay object
Cancel cancel3 = heidelpay.cancelAuthorization("s-pay-1");

Cancel a charge (Refund)

To cancel a Charge you need to fetch the Charge object and execute a cancel on it.

Alternatively the heidelpay object also provides methods to cancel a Charge.

When canceling a Charge you can also provide an amount. In this case the Charge is canceled only partly.

All 2 options are listed within the sample code:

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

// cancel a charge using Charge object
Charge charge = heidelpay.fetchCharge("s-pay-1", "s-chg-1");
Cancel cancel = charge.cancel();
// Or
Cancel cancel = charge.cancel(new Cancel());

// cancel a charge using heidelpay object
Cancel cancel = heidelpay.cancelCharge("s-pay-1", "s-chg-1", BigDecimal.ONE);

Shipment

To execute a Shipment you need to call the shipment method in heidelpay object:

Heidelpay heidelpay = new heidelpay("s-priv-xxxxxxxxxx");

Shipment shipment = heidelpay.shipment(authorize.getPaymentId());
System Requirements

Read More
Installation

Read More
Basic usage of the SDK

Read More
Performing Transactions

Read More
Additional Resources

Read More
Payment Page

Read More
Basket model

Read More
Customer

Read More
Metadata

Read More
Versioning

Read More
Migrate to Unzer Java SDK

Migrate from the old heidelpay Java SDK to the new Unzer Java SDK.

Read More