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 @@ -20,6 +20,7 @@
import com.mx.path.model.mdx.accessor.location.LocationBaseAccessor;
import com.mx.path.model.mdx.accessor.managed_card.ManagedCardBaseAccessor;
import com.mx.path.model.mdx.accessor.origination.OriginationBaseAccessor;
import com.mx.path.model.mdx.accessor.p2p_transfer.P2PTransferBaseAccessor;
import com.mx.path.model.mdx.accessor.payment.PaymentBaseAccessor;
import com.mx.path.model.mdx.accessor.payout.PayoutBaseAccessor;
import com.mx.path.model.mdx.accessor.products.ProductBaseAccessor;
Expand Down Expand Up @@ -74,6 +75,10 @@ public abstract class BaseAccessor extends Accessor {
@Getter(AccessLevel.PROTECTED)
private OriginationBaseAccessor originations;

@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private P2PTransferBaseAccessor p2pTransfers;

@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private PaymentBaseAccessor payments;
Expand Down Expand Up @@ -349,6 +354,29 @@ public void setOriginations(OriginationBaseAccessor originations) {
this.originations = originations;
}

/**
* Accessor for p2p transfer operations
*
* @return accessor
*/
@API
public P2PTransferBaseAccessor p2pTransfers() {
if (p2pTransfers != null) {
return p2pTransfers;
}

throw new AccessorMethodNotImplementedException();
}

/**
* Set p2p transfer accessor
*
* @param p2pTransfers
*/
public void setP2pTransfers(P2PTransferBaseAccessor p2pTransfers) {
this.p2pTransfers = p2pTransfers;
}

/**
* Accessor for payment operations
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mx.path.model.mdx.accessor.p2p_transfer;

import com.mx.path.core.common.accessor.API;
import com.mx.path.core.common.accessor.AccessorMethodNotImplementedException;
import com.mx.path.core.common.gateway.GatewayAPI;
import com.mx.path.core.common.gateway.GatewayClass;
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.p2p_transfer.Duration;

/**
* Accessor base for P2P transfer duration operations
*/
@GatewayClass
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#durations")
public class DurationBaseAccessor extends Accessor {
public DurationBaseAccessor() {
}

/**
* List all P2P transfer durations
*
* @return MdxList<Duration>
*/
@GatewayAPI
@API(description = "List all durations for P2P transfers")
public AccessorResponse<MdxList<Duration>> list() {
throw new AccessorMethodNotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mx.path.model.mdx.accessor.p2p_transfer;

import lombok.AccessLevel;
import lombok.Getter;

import com.mx.path.core.common.accessor.API;
import com.mx.path.core.common.gateway.GatewayAPI;
import com.mx.path.core.common.gateway.GatewayClass;
import com.mx.path.gateway.accessor.Accessor;

/**
* Accessor base for p2p transfer operations
*
*/
@GatewayClass
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#p2p-transfers")
public class P2PTransferBaseAccessor extends Accessor {
@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private DurationBaseAccessor durations;

/**
* Accessor for duration operations
*
* @return accessor
*/
@API
public DurationBaseAccessor durations() {
return durations;
}

/**
* Sets duration accessor
* @param durations
*/
public void setDurations(DurationBaseAccessor durations) {
this.durations = durations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.mx.path.model.mdx.model.ondemand.mixins.TransactionMixIn;
import com.mx.path.model.mdx.model.ondemand.mixins.TransactionsPageMixin;
import com.mx.path.model.mdx.model.origination.Origination;
import com.mx.path.model.mdx.model.p2p_transfer.Duration;
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 @@ -284,6 +285,8 @@ public static void registerResources(GsonBuilder builder) {
registerAccountAlertModels(builder);
// Register product models
registerProductModels(builder);
// Register P2P transfer models
registerP2PTransferModels(builder);
}

private static void registerDeviceModels(GsonBuilder builder) {
Expand Down Expand Up @@ -380,6 +383,13 @@ private static void registerDisputesModels(GsonBuilder builder) {
}.getType(), new ModelWrappableSerializer("disputed_transactions"));
}

private static void registerP2PTransferModels(GsonBuilder builder) {
// Duration
builder.registerTypeAdapter(Frequency.class, new ModelWrappableSerializer("duration"));
builder.registerTypeAdapter(new TypeToken<MdxList<Duration>>() {
}.getType(), new ModelWrappableSerializer("durations"));
}

private static void registerPaymentsModels(GsonBuilder builder) {
// Merchant
builder.registerTypeAdapter(Merchant.class, new ModelWrappableSerializer("merchant"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 Duration extends MdxBase<Duration> {
private String description;
private String name;
private String type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mx.path.model.mdx.web.controller;

import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.p2p_transfer.Duration;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA)
public class P2PTransferDurationsController extends BaseController {
@RequestMapping(value = "/users/{userId}/p2p_transfers/durations", method = RequestMethod.GET)
public final ResponseEntity<MdxList<Duration>> list() {
AccessorResponse<MdxList<Duration>> response = gateway().p2pTransfers().durations().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mx.path.model.mdx.web.controller

import static org.mockito.Mockito.doReturn
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.spy
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.DurationGateway
import com.mx.path.gateway.api.p2p_transfer.P2PTransferGateway
import com.mx.path.model.mdx.model.MdxList
import com.mx.path.model.mdx.model.p2p_transfer.Duration

import org.springframework.http.HttpStatus

import spock.lang.Specification

class P2PTransferDurationsControllerTest extends Specification {
P2PTransferDurationsController subject
Gateway gateway
P2PTransferGateway p2pTransferGateway
DurationGateway durationGateway

def setup() {
subject = new P2PTransferDurationsController()
p2pTransferGateway = mock(P2PTransferGateway)
durationGateway = mock(DurationGateway)

doReturn(durationGateway).when(p2pTransferGateway).durations()
gateway = spy(Gateway.builder().clientId("client-1234").p2pTransfers(p2pTransferGateway).build())
}

def cleanup() {
BaseController.clearGateway()
}

def "list interacts with gateway"() {
given:
BaseController.setGateway(gateway)
def durations = new MdxList().tap {
add(new Duration())
}
doReturn(new AccessorResponse<MdxList<Duration>>().withResult(durations)).when(durationGateway).list()

when:
def result = subject.list()

then:
HttpStatus.OK == result.statusCode
result.body == durations
verify(durationGateway).list() || true
}
}