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 @@ -194,6 +194,17 @@ public AccessorResponse<MdxList<Payment>> list() {
throw new AccessorMethodNotImplementedException();
}

/**
* List all payments - Version 20260427
*
* @return
*/
@GatewayAPI
@API(description = "List all payments version 20260427")
public AccessorResponse<MdxList<Payment>> list20260427() {
throw new AccessorMethodNotImplementedException();
}

/**
* Accessor for bill operations
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public AccessorResponse<MdxList<Frequency>> frequencies() {
throw new AccessorMethodNotImplementedException();
}

/**
* List all recurring payments - Version 20260427
*
* @return
*/
@GatewayAPI
@API(description = "List all recurring payments verion 20260427")
public AccessorResponse<MdxList<RecurringPayment>> list20260427() {
throw new AccessorMethodNotImplementedException();
}

/**
* List all recurring payments
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,19 @@ public final ResponseEntity<Payment> createPayment(@RequestBody Payment paymentR
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}

@SuppressWarnings("MagicNumber")
@RequestMapping(value = "/payments", method = RequestMethod.GET)
public final ResponseEntity<MdxList<Payment>> getPaymentList() {
AccessorResponse<MdxList<Payment>> response = gateway().payments().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
public final ResponseEntity<?> getPaymentList(HttpServletRequest request) {
return versioned(request)
.defaultVersion(MdxList.class, MdxList.class, payments -> {
AccessorResponse<MdxList<Payment>> response = gateway().payments().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
})
.version(20260427, MdxList.class, MdxList.class, payments -> {
AccessorResponse<MdxList<Payment>> response = gateway().payments().list20260427();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
})
.execute();
}

@RequestMapping(value = "/payments/{id}", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA)
public class RecurringPaymentsController extends BaseController {
Expand All @@ -23,10 +25,19 @@ public final ResponseEntity<MdxList<Frequency>> getRecurringPaymentFrequencies()
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}

@SuppressWarnings("MagicNumber")
@RequestMapping(value = "/users/{userId}/recurring_payments", method = RequestMethod.GET)
public final ResponseEntity<MdxList<RecurringPayment>> getRecurringPayments() {
AccessorResponse<MdxList<RecurringPayment>> response = gateway().payments().recurring().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
public final ResponseEntity<?> getRecurringPayments(HttpServletRequest request) {
return versioned(request)
.defaultVersion(MdxList.class, MdxList.class, recurringPayments -> {
AccessorResponse<MdxList<RecurringPayment>> response = gateway().payments().recurring().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
})
.version(20260427, MdxList.class, MdxList.class, recurringPayments -> {
AccessorResponse<MdxList<RecurringPayment>> response = gateway().payments().recurring().list20260427();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
})
.execute();
}

@RequestMapping(value = "/users/{userId}/recurring_payments", method = RequestMethod.POST, consumes = MDX_MEDIA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,35 @@ class PaymentsControllerTest extends Specification {
BaseController.setGateway(gateway)

def payment = new Payment()
def payments = new MdxList<>().tap { add(payment) }
def payments = new MdxList<Payment>().tap { add(payment) }

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

then:
HttpStatus.OK == response.getStatusCode()
response.getBody() == payments
verify(paymentGateway).list() || true
}

def "getPayments v20260427 interacts with gateway"() {
given:
BaseController.setGateway(gateway)

def payment = new Payment()
def payments = new MdxList<Payment>().tap { add(payment) }

when:
Mockito.doReturn(new AccessorResponse<MdxList<Payment>>().withResult(payments)).when(paymentGateway).list20260427()
def response = subject.getPaymentList(buildRequest(null, "application/vnd.mx.mdx.v6+json;version=20260427"))

then:
HttpStatus.OK == response.getStatusCode()
response.getBody() == payments
verify(paymentGateway).list20260427() || true
}

def "createPayment interacts with gateway"() {
given:
BaseController.setGateway(gateway)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
package com.mx.path.model.mdx.web.controller

import static org.mockito.Mockito.mock
import static org.mockito.Mockito.spy
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.mx.path.core.context.Session
import com.mx.path.gateway.accessor.AccessorResponse
import com.mx.path.gateway.api.Gateway
import com.mx.path.gateway.api.payment.PaymentGateway
import com.mx.path.gateway.api.payment.RecurringPaymentGateway
import com.mx.path.model.mdx.model.Frequency
import com.mx.path.model.mdx.model.MdxList
import com.mx.path.model.mdx.model.Resources
import com.mx.path.model.mdx.model.payment.RecurringPayment

import org.mockito.Mockito
import org.springframework.http.HttpStatus

import spock.lang.Specification

import jakarta.servlet.http.HttpServletRequest

class RecurringPaymentsControllerTest extends Specification {
RecurringPaymentsController subject
Gateway gateway
PaymentGateway paymentGateway
RecurringPaymentGateway recurringPaymentGateway
Gson gson

def setup() {
subject = new RecurringPaymentsController()
recurringPaymentGateway = spy(RecurringPaymentGateway.builder().build())
paymentGateway = PaymentGateway.builder().recurring(recurringPaymentGateway).build()
gateway = Gateway.builder().payments(paymentGateway).build()

GsonBuilder builder = new GsonBuilder()
Resources.registerResources(builder)
gson = builder.create()
}

def cleanup() {
Expand Down Expand Up @@ -58,13 +71,29 @@ class RecurringPaymentsControllerTest extends Specification {

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

then:
verify(recurringPaymentGateway).list() || true
response.getBody() == recurringPayments
}

def "index recurring payments v20260427 invokes gateway"() {
given:
RecurringPayment recurringPayment = new RecurringPayment()
MdxList<RecurringPayment> recurringPayments = new MdxList<>()
recurringPayments.add(recurringPayment)
BaseController.setGateway(gateway)

when:
Mockito.doReturn(new AccessorResponse<MdxList<RecurringPayment>>().withResult(recurringPayments)).when(recurringPaymentGateway).list20260427()
def response = subject.getRecurringPayments(buildRequest(null, "application/vnd.mx.mdx.v6+json;version=20260427"))

then:
verify(recurringPaymentGateway).list20260427() || true
response.getBody() == recurringPayments
}

def "get recurring payment invokes gateway"() {
given:
RecurringPayment recurringPayment = new RecurringPayment()
Expand Down Expand Up @@ -126,4 +155,16 @@ class RecurringPaymentsControllerTest extends Specification {
verify(recurringPaymentGateway).cancel(recurringPayment.id) || true
HttpStatus.NO_CONTENT == response.getStatusCode()
}

def buildRequest(Object body, String contentType) {
HttpServletRequest request = mock(HttpServletRequest.class)
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(gson.toJson(body))))
if (Session.current() != null) {
when(request.getHeader("mx-session-key")).thenReturn(Session.current().getId())
}
when(request.getHeaders("Content-Type")).thenReturn(Collections.enumeration([contentType]))
when(request.getHeaders("Accept")).thenReturn(Collections.enumeration([contentType]))

return request
}
}
Loading