From 84343aa95181bada90a3a73995964fa99371067e Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 13:15:50 +0100 Subject: [PATCH 1/3] [CC-4240] Add recurring flag to SepaDirectDebit payment type Add a fluent recurring(boolean) method to SepaDirectDebit so integrators have a discoverable way to register the type for recurring (mandate-based) collection at creation time. The underlying recurring field already existed on BasePaymentType and was serialized by Gson, so this change is additive and non-breaking. Add Javadoc on the field and method clarifying the flag is set before createPaymentType, cannot be changed afterwards, is not needed for one-off payments, and is unrelated to card-specific recurrenceType. Add a unit test covering serialization (set true/false, absent when unset) and the response map path, plus an integration test for the create+fetch round-trip. Document the change under an Unreleased CHANGELOG section. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 6 ++ .../payment/paymenttypes/BasePaymentType.java | 7 ++ .../payment/paymenttypes/SepaDirectDebit.java | 28 +++++++- .../paymenttypes/SepaDirectDebitTest.java | 68 +++++++++++++++++++ .../paymenttypes/SepaDirectDebitTest.java | 10 +++ .../api-response/sepa-direct-debit/type.json | 12 ++++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/unzer/payment/business/paymenttypes/SepaDirectDebitTest.java create mode 100644 src/test/resources/api-response/sepa-direct-debit/type.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 60b496dc..1794c891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +* Added `recurring` flag on `SepaDirectDebit` for registering a payment type for recurring (mandate-based) collection. + ## [5.9.0](https://github.com/unzerdev/java-sdk/compare/5.8.2..5.9.0) ### Added diff --git a/src/main/java/com/unzer/payment/paymenttypes/BasePaymentType.java b/src/main/java/com/unzer/payment/paymenttypes/BasePaymentType.java index 52231c66..84e3dd12 100644 --- a/src/main/java/com/unzer/payment/paymenttypes/BasePaymentType.java +++ b/src/main/java/com/unzer/payment/paymenttypes/BasePaymentType.java @@ -6,6 +6,13 @@ public abstract class BasePaymentType extends BaseResource implements PaymentType { private String id; + /** + * Indicates whether the payment type is registered for recurring collection. + * + *

For most payment types this is a read-only value returned by the API. + * {@code sepa-direct-debit} is the type where it is also accepted on creation + * (see {@link SepaDirectDebit#recurring(boolean)}).

+ */ private Boolean recurring; private GeoLocation geoLocation; diff --git a/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java b/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java index 97330ab7..5d6583db 100644 --- a/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java +++ b/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java @@ -15,7 +15,12 @@ import java.util.Currency; /** - * Sepa direct debit business object. Iban is mandatory, bic and holder are optional fields + * Sepa direct debit business object. Iban is mandatory, bic and holder are optional fields. + * + *

For {@code sepa-direct-debit} the recurrence intent is captured once, at type registration, + * via the {@code recurring} flag (see {@link #recurring(boolean)}). Unlike most payment types, + * where {@code recurring} is a read-only value returned by the API, this type also accepts the + * flag when the type is created.

* * @author Unzer E-Com GmbH */ @@ -32,6 +37,27 @@ public SepaDirectDebit(String iban) { this.iban = iban; } + /** + * Registers this {@code sepa-direct-debit} type for recurring (mandate-based) collection. + * + *

This flag must be set before the type is registered via + * {@link com.unzer.payment.Unzer#createPaymentType(PaymentType)}; it cannot be changed + * afterwards. It is not needed for one-off payments.

+ * + *

This is unrelated to {@code recurrenceType} on charges/authorizations, which is + * card-specific.

+ * + *

The fluent return value is a convenience over the Lombok-generated + * {@link #setRecurring(Boolean)} setter, which keeps working.

+ * + * @param recurring {@code true} to register the type for recurring collection + * @return this instance, for chaining + */ + public SepaDirectDebit recurring(boolean recurring) { + setRecurring(recurring); + return this; + } + @Override public String getResourceUrl() { return "/v1/types/sepa-direct-debit/"; diff --git a/src/test/java/com/unzer/payment/business/paymenttypes/SepaDirectDebitTest.java b/src/test/java/com/unzer/payment/business/paymenttypes/SepaDirectDebitTest.java new file mode 100644 index 00000000..4cfc00db --- /dev/null +++ b/src/test/java/com/unzer/payment/business/paymenttypes/SepaDirectDebitTest.java @@ -0,0 +1,68 @@ +package com.unzer.payment.business.paymenttypes; + +import com.unzer.payment.communication.JsonParser; +import com.unzer.payment.communication.json.ApiSepaDirectDebit; +import com.unzer.payment.paymenttypes.SepaDirectDebit; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.Objects; +import java.util.Scanner; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SepaDirectDebitTest { + + private static final String IBAN = "DE89370400440532013000"; + + private static String compactJson(SepaDirectDebit sdd) { + return new JsonParser().toJson(sdd).replaceAll("\\s", ""); + } + + private static String getResponse(String response) { + return new Scanner(Objects.requireNonNull( + SepaDirectDebitTest.class.getResourceAsStream("/api-response/sepa-direct-debit/" + response))) + .useDelimiter("\\A").next(); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void recurring_flag_is_serialized_when_set(boolean recurring) { + SepaDirectDebit sdd = new SepaDirectDebit(IBAN).recurring(recurring); + + assertTrue(compactJson(sdd).contains("\"recurring\":" + recurring)); + } + + @Test + void recurring_fluent_method_returns_same_instance_and_sets_lombok_value() { + SepaDirectDebit sdd = new SepaDirectDebit(IBAN); + + assertEquals(sdd, sdd.recurring(true)); + assertEquals(Boolean.TRUE, sdd.getRecurring()); + + sdd.setRecurring(false); + assertTrue(compactJson(sdd).contains("\"recurring\":false")); + } + + @Test + void recurring_key_absent_when_not_set() { + SepaDirectDebit sdd = new SepaDirectDebit(IBAN); + + assertFalse(compactJson(sdd).contains("recurring")); + } + + @Test + void recurring_is_mapped_from_response() { + ApiSepaDirectDebit apiObject = + new JsonParser().fromJson(getResponse("type.json"), ApiSepaDirectDebit.class); + + SepaDirectDebit sdd = new SepaDirectDebit(IBAN); + sdd.map(sdd, apiObject); + + assertEquals(Boolean.TRUE, sdd.getRecurring()); + assertEquals("s-sdd-giqxlgfvwjb7", sdd.getId()); + } +} diff --git a/src/test/java/com/unzer/payment/integration/paymenttypes/SepaDirectDebitTest.java b/src/test/java/com/unzer/payment/integration/paymenttypes/SepaDirectDebitTest.java index dc3493a6..480305c4 100644 --- a/src/test/java/com/unzer/payment/integration/paymenttypes/SepaDirectDebitTest.java +++ b/src/test/java/com/unzer/payment/integration/paymenttypes/SepaDirectDebitTest.java @@ -32,6 +32,16 @@ void testCreateSepaDirectDebitFullType() { assertSddEquals(sddOriginal, sddCreated); } + @Test + void testCreateRecurringSepaDirectDebitType() { + Unzer unzer = getUnzer(Keys.LEGACY_PRIVATE_KEY); + SepaDirectDebit sdd = unzer.createPaymentType(getSepaDirectDebit().recurring(true)); + assertNotNull(sdd.getId()); + + SepaDirectDebit fetchedSdd = (SepaDirectDebit) unzer.fetchPaymentType(sdd.getId()); + assertEquals(Boolean.TRUE, fetchedSdd.getRecurring()); + } + @Test void testChargeSepaDirectDebitType() { Unzer unzer = getUnzer(Keys.LEGACY_PRIVATE_KEY); diff --git a/src/test/resources/api-response/sepa-direct-debit/type.json b/src/test/resources/api-response/sepa-direct-debit/type.json new file mode 100644 index 00000000..90f3d493 --- /dev/null +++ b/src/test/resources/api-response/sepa-direct-debit/type.json @@ -0,0 +1,12 @@ +{ + "id": "s-sdd-giqxlgfvwjb7", + "method": "sepa-direct-debit", + "recurring": true, + "iban": "DE89370400440532013000", + "bic": "COBADEFFXXX", + "holder": "Max Mustermann", + "geoLocation": { + "clientIp": "0:0:0:0:0:0:0:1", + "countryIsoA2": "" + } +} From a28fc062a29de6b674509f5b2ce64abdac31ce8a Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 15:48:50 +0100 Subject: [PATCH 2/3] [CC-4240] Remove changelog entry; consolidated into CC-4252 release PR Changelog and version edits are scoped to the release ticket (CC-4252), so this feature branch no longer touches CHANGELOG and won't conflict. --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1794c891..60b496dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] - -### Added - -* Added `recurring` flag on `SepaDirectDebit` for registering a payment type for recurring (mandate-based) collection. - ## [5.9.0](https://github.com/unzerdev/java-sdk/compare/5.8.2..5.9.0) ### Added From c98ff191c13197ed5062c241885865367d6ca048 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:56:19 +0100 Subject: [PATCH 3/3] [CC-4240] [CC-4240] Drop "Lombok-generated" from recurring(boolean) Javadoc BasePaymentType#setRecurring(Boolean) is hand-written, not Lombok-generated. Addresses PR #196 review feedback. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../java/com/unzer/payment/paymenttypes/SepaDirectDebit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java b/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java index 5d6583db..5d719879 100644 --- a/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java +++ b/src/main/java/com/unzer/payment/paymenttypes/SepaDirectDebit.java @@ -47,7 +47,7 @@ public SepaDirectDebit(String iban) { *

This is unrelated to {@code recurrenceType} on charges/authorizations, which is * card-specific.

* - *

The fluent return value is a convenience over the Lombok-generated + *

The fluent return value is a convenience over the * {@link #setRecurring(Boolean)} setter, which keeps working.

* * @param recurring {@code true} to register the type for recurring collection