Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class P2PTransferBaseAccessor extends Accessor {
@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private AccountBaseAccessor accounts;
private SourceBaseAccessor sources;

@GatewayAPI
@Getter(AccessLevel.PROTECTED)
Expand Down Expand Up @@ -95,21 +95,21 @@ public AccessorResponse<P2PTransfer> 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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&lt;Account&gt;
* @return MdxList&lt;Source&gt;
*/
@GatewayAPI
@API(description = "Lists all accounts for P2P transfers")
public AccessorResponse<MdxList<Account>> list() {
@API(description = "Lists all sources for P2P transfers")
public AccessorResponse<MdxList<Source>> list() {
throw new AccessorMethodNotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -402,6 +403,10 @@ private static void registerP2PTransferModels(GsonBuilder builder) {
builder.registerTypeAdapter(RecurringP2PTransfer.class, new ModelWrappableSerializer("recurring_p2p_transfer"));
builder.registerTypeAdapter(new TypeToken<MdxList<RecurringP2PTransfer>>() {
}.getType(), new ModelWrappableSerializer("recurring_p2p_transfers"));
// Sources
builder.registerTypeAdapter(Source.class, new ModelWrappableSerializer("source"));
builder.registerTypeAdapter(new TypeToken<MdxList<Source>>() {
}.getType(), new ModelWrappableSerializer("sources"));
}

private static void registerPaymentsModels(GsonBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AccountData> {
private String accountId;
private BigDecimal availableBalance;
private BigDecimal balance;
}
Original file line number Diff line number Diff line change
@@ -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<DebitCardData> {
private String description;
private String lastFour;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@EqualsAndHashCode(callSuper = true)
public class P2PTransfer extends MdxBase<P2PTransfer> {
private String id;
private String accountId;
private BigDecimal amount;
private MdxList<Challenge> challenges;
private String confirmationId;
Expand All @@ -25,5 +24,6 @@ public class P2PTransfer extends MdxBase<P2PTransfer> {
private String recipientVerificationQuestion;
private LocalDate sendOn;
private LocalDate sentOn;
private String sourceId;
private String status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@EqualsAndHashCode(callSuper = true)
public class RecurringP2PTransfer extends MdxBase<RecurringP2PTransfer> {
private String id;
private String accountId;
private BigDecimal amount;
private String confirmationId;
private String deliveryMethod;
Expand All @@ -24,5 +23,6 @@ public class RecurringP2PTransfer extends MdxBase<RecurringP2PTransfer> {
private String recipientVerificationAnswer;
private String recipientVerificationQuestion;
private LocalDate startOn;
private String sourceId;
private String status;
}
Original file line number Diff line number Diff line change
@@ -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<Source> {
private String id;
private SourceType type;
private AccountData accountData;
private DebitCardData debitCardData;

public enum SourceType {
ACCOUNT, DEBIT_CARD
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MdxList<Account>> list() {
AccessorResponse<MdxList<Account>> response = gateway().p2pTransfers().accounts().list();
public class P2PTransferSourcesController extends BaseController {
@RequestMapping(value = "/users/{userId}/p2p_transfers/sources", method = RequestMethod.GET)
public final ResponseEntity<MdxList<Source>> list() {
AccessorResponse<MdxList<Source>> response = gateway().p2pTransfers().sources().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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<MdxList<Account>>().withResult(accounts)).when(accountGateway).list()
doReturn(new AccessorResponse<MdxList<Source>>().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
}
}