Additional Resources

Payment resource

Initial payment type and authorization before cancel.

protected Authorization getAuthorization(String typeId, Boolean card3ds) throws MalformedURLException {
        return getAuthorization(typeId, null, null, null, null, card3ds);
}

protected Card createPaymentTypeCard() throws HttpCommunicationException {
        return createPaymentTypeCard("4444333322221111");
}

protected Card createPaymentTypeCard(String cardnumber) throws HttpCommunicationException {
        Card card = getPaymentTypeCard(cardnumber);
        card = (Card)getHeidelpay().createPaymentType(card);
        return card;
}

The payment resource can not be created on its own but will automatically appear when an authorization or direct charge takes place.

Fetching a Payment

The payment resource can be fetched using its id or the external order id which has been set while performing the transaction.

// Fetching a payment by id

Heidelpay heidelpay =  new Heidelpay("s-priv-xxxxxxxxxx");
Authorization authorize = heidelpay.authorize(getAuthorization(createPaymentTypeCard().getId()));

Payment payment = heidelpay.fetchPayment(authorize.getPayment().getId());
// Fetch a payment by external orderid

Heidelpay heidelpay =  new Heidelpay("s-priv-xxxxxxxxxx");
Authorization authorize = heidelpay.authorize(getAuthorization(createPaymentTypeCard().getOrderId()));

Payment payment = heidelpay.fetchPayment(authorize.getPayment().getOrderId());
Please keep in mind that the value for orderId has to be unique for the used KeyPair.

Cancelling a Payment

When cancelling a payment several different scenarios have to be taken into account. In version 1.2.3.0 of the SDK the method Payment::cancelAmount()has been added which covers the following cases of cancellation:

  • Full cancel of a single Charge
  • Full cancel on an Authorization with several Charges
  • Part cancel on a single Charge
  • Part cancel on several Charges
  • Full cancel on an Authorization without Charges
  • Full cancel on Authorization without Charges after part cancel
  • Full cancel on full charged Authorization
  • Full cancel on partly charged Authorization
  • Part cancel on an Authorization with Charges
  • Full cancel on payment type with initializing charge (e.g. Invoice)
  • Part cancel on payment type with initializing charge (e.g. Invoice)
Cancel work flow

23e30c0-payment-cancelamount-flow.png

Payment cancel examples
// Full cancel on payment

Heidelpay heidelpay =  new Heidelpay("s-priv-xxxxxxxxxx");
Authorization authorize = heidelpay.authorize(getAuthorization(createPaymentTypeCard().getOrderId()));

Payment payment = heidelpay.fetchPayment(authorize.getPayment().getOrderId());
Cancel cancel = payment.getAuthorization().cancel();
payment.cancel();
// Part cancel on payment

Heidelpay heidelpay =  new Heidelpay("s-priv-xxxxxxxxxx");
Authorization authorize = heidelpay.authorize(getAuthorization(createPaymentTypeCard().getOrderId()));

Payment payment = heidelpay.fetchPayment(authorize.getPayment().getOrderId());
Cancel cancel = payment.cancel(BigDecimal.ONE);
Payment::amount Params in method Payment.cancel(BigDecimal amount)
Name Type Description
amount BigDecimal The amount to be cancelled.
When this parameter is left out or set null the whole payment will be cancelled.
Required: false