From 83958a528d87d9c68c0d1be47dabda1ee689091a Mon Sep 17 00:00:00 2001 From: Tess Stoddard Date: Wed, 10 Dec 2025 12:25:55 -0700 Subject: [PATCH] fix: replace accounts with sources for p2p transfers --- .../p2p_transfer/P2PTransferBaseAccessor.java | 16 ++++++------ ...eAccessor.java => SourceBaseAccessor.java} | 18 ++++++------- .../mx/path/model/mdx/model/Resources.java | 5 ++++ .../mdx/model/p2p_transfer/AccountData.java | 18 +++++++++++++ .../mdx/model/p2p_transfer/DebitCardData.java | 15 +++++++++++ .../mdx/model/p2p_transfer/P2PTransfer.java | 2 +- .../p2p_transfer/RecurringP2PTransfer.java | 2 +- .../model/mdx/model/p2p_transfer/Source.java | 19 ++++++++++++++ ...java => P2PTransferSourcesController.java} | 10 +++---- ...> P2PTransferSourcesControllerTest.groovy} | 26 +++++++++---------- 10 files changed, 94 insertions(+), 37 deletions(-) rename mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/{AccountBaseAccessor.java => SourceBaseAccessor.java} (59%) create mode 100644 mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/AccountData.java create mode 100644 mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/DebitCardData.java create mode 100644 mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/Source.java rename mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/{P2PTransferAccountsController.java => P2PTransferSourcesController.java} (67%) rename mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/{P2PTransferAccountsControllerTest.groovy => P2PTransferSourcesControllerTest.groovy} (60%) diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/P2PTransferBaseAccessor.java b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/P2PTransferBaseAccessor.java index a7efeda7..e72dd1e7 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/P2PTransferBaseAccessor.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/P2PTransferBaseAccessor.java @@ -21,7 +21,7 @@ public class P2PTransferBaseAccessor extends Accessor { @GatewayAPI @Getter(AccessLevel.PROTECTED) - private AccountBaseAccessor accounts; + private SourceBaseAccessor sources; @GatewayAPI @Getter(AccessLevel.PROTECTED) @@ -95,21 +95,21 @@ public AccessorResponse update(String id, P2PTransfer p2pTransfer) } /** - * Accessor for account operations + * Accessor for source operations * * @return accessor */ @API - public AccountBaseAccessor accounts() { - return accounts; + public SourceBaseAccessor sources() { + return sources; } /** - * Sets account accessor - * @param accounts + * Sets source accessor + * @param sources */ - public void setAccounts(AccountBaseAccessor accounts) { - this.accounts = accounts; + public void setSources(SourceBaseAccessor sources) { + this.sources = sources; } /** diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/AccountBaseAccessor.java b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/SourceBaseAccessor.java similarity index 59% rename from mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/AccountBaseAccessor.java rename to mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/SourceBaseAccessor.java index aaeb129f..78c3f9d6 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/AccountBaseAccessor.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/p2p_transfer/SourceBaseAccessor.java @@ -7,25 +7,25 @@ import com.mx.path.gateway.accessor.Accessor; import com.mx.path.gateway.accessor.AccessorResponse; import com.mx.path.model.mdx.model.MdxList; -import com.mx.path.model.mdx.model.account.Account; +import com.mx.path.model.mdx.model.p2p_transfer.Source; /** - * Accessor base for P2P transfer account operations + * Accessor base for P2P transfer source operations */ @GatewayClass -@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#p2p-transfer-accounts") -public class AccountBaseAccessor extends Accessor { - public AccountBaseAccessor() { +@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#sources") +public class SourceBaseAccessor extends Accessor { + public SourceBaseAccessor() { } /** - * Lists all p2p transfer accounts + * Lists all p2p transfer sources * - * @return MdxList<Account> + * @return MdxList<Source> */ @GatewayAPI - @API(description = "Lists all accounts for P2P transfers") - public AccessorResponse> list() { + @API(description = "Lists all sources for P2P transfers") + public AccessorResponse> list() { throw new AccessorMethodNotImplementedException(); } } diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java index f7960d4e..15bfeaab 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java @@ -64,6 +64,7 @@ import com.mx.path.model.mdx.model.p2p_transfer.Duration; import com.mx.path.model.mdx.model.p2p_transfer.P2PTransfer; import com.mx.path.model.mdx.model.p2p_transfer.RecurringP2PTransfer; +import com.mx.path.model.mdx.model.p2p_transfer.Source; import com.mx.path.model.mdx.model.payment.Bill; import com.mx.path.model.mdx.model.payment.Enrollment; import com.mx.path.model.mdx.model.payment.Merchant; @@ -402,6 +403,10 @@ private static void registerP2PTransferModels(GsonBuilder builder) { builder.registerTypeAdapter(RecurringP2PTransfer.class, new ModelWrappableSerializer("recurring_p2p_transfer")); builder.registerTypeAdapter(new TypeToken>() { }.getType(), new ModelWrappableSerializer("recurring_p2p_transfers")); + // Sources + builder.registerTypeAdapter(Source.class, new ModelWrappableSerializer("source")); + builder.registerTypeAdapter(new TypeToken>() { + }.getType(), new ModelWrappableSerializer("sources")); } private static void registerPaymentsModels(GsonBuilder builder) { diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/AccountData.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/AccountData.java new file mode 100644 index 00000000..9483188e --- /dev/null +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/AccountData.java @@ -0,0 +1,18 @@ +package com.mx.path.model.mdx.model.p2p_transfer; + +import java.math.BigDecimal; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import com.mx.path.model.mdx.model.MdxBase; +import com.mx.path.model.mdx.model.MdxNested; + +@MdxNested +@Data +@EqualsAndHashCode(callSuper = true) +public class AccountData extends MdxBase { + private String accountId; + private BigDecimal availableBalance; + private BigDecimal balance; +} diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/DebitCardData.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/DebitCardData.java new file mode 100644 index 00000000..edf1affa --- /dev/null +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/DebitCardData.java @@ -0,0 +1,15 @@ +package com.mx.path.model.mdx.model.p2p_transfer; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import com.mx.path.model.mdx.model.MdxBase; +import com.mx.path.model.mdx.model.MdxNested; + +@MdxNested +@Data +@EqualsAndHashCode(callSuper = true) +public class DebitCardData extends MdxBase { + private String description; + private String lastFour; +} diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/P2PTransfer.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/P2PTransfer.java index 69ccdf60..1b9d28aa 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/P2PTransfer.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/P2PTransfer.java @@ -14,7 +14,6 @@ @EqualsAndHashCode(callSuper = true) public class P2PTransfer extends MdxBase { private String id; - private String accountId; private BigDecimal amount; private MdxList challenges; private String confirmationId; @@ -25,5 +24,6 @@ public class P2PTransfer extends MdxBase { private String recipientVerificationQuestion; private LocalDate sendOn; private LocalDate sentOn; + private String sourceId; private String status; } diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/RecurringP2PTransfer.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/RecurringP2PTransfer.java index f1a34af9..45e6384b 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/RecurringP2PTransfer.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/RecurringP2PTransfer.java @@ -12,7 +12,6 @@ @EqualsAndHashCode(callSuper = true) public class RecurringP2PTransfer extends MdxBase { private String id; - private String accountId; private BigDecimal amount; private String confirmationId; private String deliveryMethod; @@ -24,5 +23,6 @@ public class RecurringP2PTransfer extends MdxBase { private String recipientVerificationAnswer; private String recipientVerificationQuestion; private LocalDate startOn; + private String sourceId; private String status; } diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/Source.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/Source.java new file mode 100644 index 00000000..417bbecb --- /dev/null +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/p2p_transfer/Source.java @@ -0,0 +1,19 @@ +package com.mx.path.model.mdx.model.p2p_transfer; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import com.mx.path.model.mdx.model.MdxBase; + +@Data +@EqualsAndHashCode(callSuper = true) +public class Source extends MdxBase { + private String id; + private SourceType type; + private AccountData accountData; + private DebitCardData debitCardData; + + public enum SourceType { + ACCOUNT, DEBIT_CARD + } +} diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/P2PTransferAccountsController.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/P2PTransferSourcesController.java similarity index 67% rename from mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/P2PTransferAccountsController.java rename to mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/P2PTransferSourcesController.java index ac65170d..185ea336 100644 --- a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/P2PTransferAccountsController.java +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/P2PTransferSourcesController.java @@ -2,7 +2,7 @@ import com.mx.path.gateway.accessor.AccessorResponse; import com.mx.path.model.mdx.model.MdxList; -import com.mx.path.model.mdx.model.account.Account; +import com.mx.path.model.mdx.model.p2p_transfer.Source; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -12,10 +12,10 @@ @RestController @RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA) -public class P2PTransferAccountsController extends BaseController { - @RequestMapping(value = "/users/{userId}/accounts/p2p_transfer", method = RequestMethod.GET) - public final ResponseEntity> list() { - AccessorResponse> response = gateway().p2pTransfers().accounts().list(); +public class P2PTransferSourcesController extends BaseController { + @RequestMapping(value = "/users/{userId}/p2p_transfers/sources", method = RequestMethod.GET) + public final ResponseEntity> list() { + AccessorResponse> response = gateway().p2pTransfers().sources().list(); return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); } } diff --git a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/P2PTransferAccountsControllerTest.groovy b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/P2PTransferSourcesControllerTest.groovy similarity index 60% rename from mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/P2PTransferAccountsControllerTest.groovy rename to mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/P2PTransferSourcesControllerTest.groovy index 68695d23..d53eb925 100644 --- a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/P2PTransferAccountsControllerTest.groovy +++ b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/P2PTransferSourcesControllerTest.groovy @@ -7,27 +7,27 @@ import static org.mockito.Mockito.verify import com.mx.path.gateway.accessor.AccessorResponse import com.mx.path.gateway.api.Gateway -import com.mx.path.gateway.api.p2p_transfer.AccountGateway import com.mx.path.gateway.api.p2p_transfer.P2PTransferGateway +import com.mx.path.gateway.api.p2p_transfer.SourceGateway import com.mx.path.model.mdx.model.MdxList -import com.mx.path.model.mdx.model.account.Account +import com.mx.path.model.mdx.model.p2p_transfer.Source import org.springframework.http.HttpStatus import spock.lang.Specification -class P2PTransferAccountsControllerTest extends Specification { - P2PTransferAccountsController subject +class P2PTransferSourcesControllerTest extends Specification { + P2PTransferSourcesController subject Gateway gateway P2PTransferGateway p2pTransferGateway - AccountGateway accountGateway + SourceGateway sourceGateway def setup() { - subject = new P2PTransferAccountsController() + subject = new P2PTransferSourcesController() p2pTransferGateway = mock(P2PTransferGateway) - accountGateway = mock(AccountGateway) + sourceGateway = mock(SourceGateway) - doReturn(accountGateway).when(p2pTransferGateway).accounts() + doReturn(sourceGateway).when(p2pTransferGateway).sources() gateway = spy(Gateway.builder().clientId("client-1234").p2pTransfers(p2pTransferGateway).build()) } @@ -38,17 +38,17 @@ class P2PTransferAccountsControllerTest extends Specification { def "list interacts with gateway"() { given: BaseController.setGateway(gateway) - def accounts = new MdxList().tap { - add(new Account()) + def sources = new MdxList().tap { + add(new Source()) } - doReturn(new AccessorResponse>().withResult(accounts)).when(accountGateway).list() + doReturn(new AccessorResponse>().withResult(sources)).when(sourceGateway).list() when: def result = subject.list() then: HttpStatus.OK == result.statusCode - result.body == accounts - verify(accountGateway).list() || true + result.body == sources + verify(sourceGateway).list() || true } }