Skip to content

Commit 6df9db0

Browse files
author
Tess Stoddard
committed
feat: add v20260427 list endpoints for payments and recurring payments
1 parent 88f57e9 commit 6df9db0

6 files changed

Lines changed: 109 additions & 9 deletions

File tree

mdx-models/src/main/java/com/mx/path/model/mdx/accessor/payment/PaymentBaseAccessor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ public AccessorResponse<MdxList<Payment>> list() {
194194
throw new AccessorMethodNotImplementedException();
195195
}
196196

197+
/**
198+
* List all payments - Version 20260427
199+
*
200+
* @return
201+
*/
202+
@GatewayAPI
203+
@API(description = "List all payments version 20260427")
204+
public AccessorResponse<MdxList<Payment>> list20260427() {
205+
throw new AccessorMethodNotImplementedException();
206+
}
207+
197208
/**
198209
* Accessor for bill operations
199210
*

mdx-models/src/main/java/com/mx/path/model/mdx/accessor/payment/RecurringPaymentBaseAccessor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public AccessorResponse<MdxList<Frequency>> frequencies() {
6767
throw new AccessorMethodNotImplementedException();
6868
}
6969

70+
/**
71+
* List all recurring payments - Version 20260427
72+
*
73+
* @return
74+
*/
75+
@GatewayAPI
76+
@API(description = "List all recurring payments verion 20260427")
77+
public AccessorResponse<MdxList<RecurringPayment>> list20260427() {
78+
throw new AccessorMethodNotImplementedException();
79+
}
80+
7081
/**
7182
* List all recurring payments
7283
*

mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/PaymentsController.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,19 @@ public final ResponseEntity<Payment> createPayment(@RequestBody Payment paymentR
9090
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
9191
}
9292

93+
@SuppressWarnings("MagicNumber")
9394
@RequestMapping(value = "/payments", method = RequestMethod.GET)
94-
public final ResponseEntity<MdxList<Payment>> getPaymentList() {
95-
AccessorResponse<MdxList<Payment>> response = gateway().payments().list();
96-
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
95+
public final ResponseEntity<?> getPaymentList(HttpServletRequest request) {
96+
return versioned(request)
97+
.defaultVersion(MdxList.class, MdxList.class, payments -> {
98+
AccessorResponse<MdxList<Payment>> response = gateway().payments().list();
99+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
100+
})
101+
.version(20260427, MdxList.class, MdxList.class, payments -> {
102+
AccessorResponse<MdxList<Payment>> response = gateway().payments().list20260427();
103+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
104+
})
105+
.execute();
97106
}
98107

99108
@RequestMapping(value = "/payments/{id}", method = RequestMethod.GET)

mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/RecurringPaymentsController.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.springframework.web.bind.annotation.RequestMethod;
1414
import org.springframework.web.bind.annotation.RestController;
1515

16+
import jakarta.servlet.http.HttpServletRequest;
17+
1618
@RestController
1719
@RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA)
1820
public class RecurringPaymentsController extends BaseController {
@@ -23,10 +25,19 @@ public final ResponseEntity<MdxList<Frequency>> getRecurringPaymentFrequencies()
2325
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
2426
}
2527

28+
@SuppressWarnings("MagicNumber")
2629
@RequestMapping(value = "/users/{userId}/recurring_payments", method = RequestMethod.GET)
27-
public final ResponseEntity<MdxList<RecurringPayment>> getRecurringPayments() {
28-
AccessorResponse<MdxList<RecurringPayment>> response = gateway().payments().recurring().list();
29-
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
30+
public final ResponseEntity<?> getRecurringPayments(HttpServletRequest request) {
31+
return versioned(request)
32+
.defaultVersion(MdxList.class, MdxList.class, recurringPayments -> {
33+
AccessorResponse<MdxList<RecurringPayment>> response = gateway().payments().recurring().list();
34+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
35+
})
36+
.version(20260427, MdxList.class, MdxList.class, recurringPayments -> {
37+
AccessorResponse<MdxList<RecurringPayment>> response = gateway().payments().recurring().list20260427();
38+
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
39+
})
40+
.execute();
3041
}
3142

3243
@RequestMapping(value = "/users/{userId}/recurring_payments", method = RequestMethod.POST, consumes = MDX_MEDIA)

mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/PaymentsControllerTest.groovy

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,35 @@ class PaymentsControllerTest extends Specification {
6868
BaseController.setGateway(gateway)
6969

7070
def payment = new Payment()
71-
def payments = new MdxList<>().tap { add(payment) }
71+
def payments = new MdxList<Payment>().tap { add(payment) }
7272

7373
when:
7474
Mockito.doReturn(new AccessorResponse<MdxList<Payment>>().withResult(payments)).when(paymentGateway).list()
75-
def response = subject.getPaymentList()
75+
def response = subject.getPaymentList(buildRequest(null, "application/vnd.mx.mdx.v6+json"))
7676

7777
then:
7878
HttpStatus.OK == response.getStatusCode()
7979
response.getBody() == payments
8080
verify(paymentGateway).list() || true
8181
}
8282

83+
def "getPayments v20260427 interacts with gateway"() {
84+
given:
85+
BaseController.setGateway(gateway)
86+
87+
def payment = new Payment()
88+
def payments = new MdxList<Payment>().tap { add(payment) }
89+
90+
when:
91+
Mockito.doReturn(new AccessorResponse<MdxList<Payment>>().withResult(payments)).when(paymentGateway).list20260427()
92+
def response = subject.getPaymentList(buildRequest(null, "application/vnd.mx.mdx.v6+json;version=20260427"))
93+
94+
then:
95+
HttpStatus.OK == response.getStatusCode()
96+
response.getBody() == payments
97+
verify(paymentGateway).list20260427() || true
98+
}
99+
83100
def "createPayment interacts with gateway"() {
84101
given:
85102
BaseController.setGateway(gateway)

mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/RecurringPaymentsControllerTest.groovy

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
package com.mx.path.model.mdx.web.controller
22

3+
import static org.mockito.Mockito.mock
34
import static org.mockito.Mockito.spy
45
import static org.mockito.Mockito.verify
6+
import static org.mockito.Mockito.when
57

8+
import com.google.gson.Gson
9+
import com.google.gson.GsonBuilder
10+
import com.mx.path.core.context.Session
611
import com.mx.path.gateway.accessor.AccessorResponse
712
import com.mx.path.gateway.api.Gateway
813
import com.mx.path.gateway.api.payment.PaymentGateway
914
import com.mx.path.gateway.api.payment.RecurringPaymentGateway
1015
import com.mx.path.model.mdx.model.Frequency
1116
import com.mx.path.model.mdx.model.MdxList
17+
import com.mx.path.model.mdx.model.Resources
1218
import com.mx.path.model.mdx.model.payment.RecurringPayment
1319

1420
import org.mockito.Mockito
1521
import org.springframework.http.HttpStatus
1622

1723
import spock.lang.Specification
1824

25+
import jakarta.servlet.http.HttpServletRequest
26+
1927
class RecurringPaymentsControllerTest extends Specification {
2028
RecurringPaymentsController subject
2129
Gateway gateway
2230
PaymentGateway paymentGateway
2331
RecurringPaymentGateway recurringPaymentGateway
32+
Gson gson
2433

2534
def setup() {
2635
subject = new RecurringPaymentsController()
2736
recurringPaymentGateway = spy(RecurringPaymentGateway.builder().build())
2837
paymentGateway = PaymentGateway.builder().recurring(recurringPaymentGateway).build()
2938
gateway = Gateway.builder().payments(paymentGateway).build()
39+
40+
GsonBuilder builder = new GsonBuilder()
41+
Resources.registerResources(builder)
42+
gson = builder.create()
3043
}
3144

3245
def cleanup() {
@@ -58,13 +71,29 @@ class RecurringPaymentsControllerTest extends Specification {
5871

5972
when:
6073
Mockito.doReturn(new AccessorResponse<MdxList<RecurringPayment>>().withResult(recurringPayments)).when(recurringPaymentGateway).list()
61-
def response = subject.getRecurringPayments()
74+
def response = subject.getRecurringPayments(buildRequest(null, "application/vnd.mx.mdx.v6+json"))
6275

6376
then:
6477
verify(recurringPaymentGateway).list() || true
6578
response.getBody() == recurringPayments
6679
}
6780

81+
def "index recurring payments v20260427 invokes gateway"() {
82+
given:
83+
RecurringPayment recurringPayment = new RecurringPayment()
84+
MdxList<RecurringPayment> recurringPayments = new MdxList<>()
85+
recurringPayments.add(recurringPayment)
86+
BaseController.setGateway(gateway)
87+
88+
when:
89+
Mockito.doReturn(new AccessorResponse<MdxList<RecurringPayment>>().withResult(recurringPayments)).when(recurringPaymentGateway).list20260427()
90+
def response = subject.getRecurringPayments(buildRequest(null, "application/vnd.mx.mdx.v6+json;version=20260427"))
91+
92+
then:
93+
verify(recurringPaymentGateway).list20260427() || true
94+
response.getBody() == recurringPayments
95+
}
96+
6897
def "get recurring payment invokes gateway"() {
6998
given:
7099
RecurringPayment recurringPayment = new RecurringPayment()
@@ -126,4 +155,16 @@ class RecurringPaymentsControllerTest extends Specification {
126155
verify(recurringPaymentGateway).cancel(recurringPayment.id) || true
127156
HttpStatus.NO_CONTENT == response.getStatusCode()
128157
}
158+
159+
def buildRequest(Object body, String contentType) {
160+
HttpServletRequest request = mock(HttpServletRequest.class)
161+
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(gson.toJson(body))))
162+
if (Session.current() != null) {
163+
when(request.getHeader("mx-session-key")).thenReturn(Session.current().getId())
164+
}
165+
when(request.getHeaders("Content-Type")).thenReturn(Collections.enumeration([contentType]))
166+
when(request.getHeaders("Accept")).thenReturn(Collections.enumeration([contentType]))
167+
168+
return request
169+
}
129170
}

0 commit comments

Comments
 (0)