diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/PaymentsController.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/PaymentsController.java index 56774ff3..b6c68e4f 100644 --- a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/PaymentsController.java +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/PaymentsController.java @@ -34,12 +34,22 @@ public final ResponseEntity setPaymentEnrollment(@RequestBody Enroll @RequestMapping(value = "/payments/settings", method = RequestMethod.GET, consumes = BaseController.MDX_MEDIA) public final ResponseEntity getPaymentSettings() { AccessorResponse response = gateway().payments().settings(); + Settings result = response.getResult(); + // Return 202 returning challenge questions + if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) { + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED); + } return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); } @RequestMapping(value = "/payments/settings", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA) public final ResponseEntity setPaymentSettings(@RequestBody Settings settingsRequest) { AccessorResponse response = gateway().payments().updateSettings(settingsRequest); + Settings result = response.getResult(); + // Return 202 returning challenge questions + if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) { + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED); + } 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/PaymentsControllerTest.groovy b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/PaymentsControllerTest.groovy index 76a23c59..108e8b2a 100644 --- a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/PaymentsControllerTest.groovy +++ b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/PaymentsControllerTest.groovy @@ -8,7 +8,9 @@ import com.mx.path.gateway.api.Gateway import com.mx.path.gateway.api.payment.PaymentGateway import com.mx.path.model.mdx.model.MdxList import com.mx.path.model.mdx.model.account.Account +import com.mx.path.model.mdx.model.challenges.Challenge import com.mx.path.model.mdx.model.payment.Payment +import com.mx.path.model.mdx.model.payment.Settings import org.mockito.Mockito import org.springframework.http.HttpStatus @@ -124,4 +126,76 @@ class PaymentsControllerTest extends Specification { response.getBody() == accounts verify(paymentGateway).accounts() || true } + + def "getPaymentSettings interacts with gateway - 202"() { + given: + BaseController.setGateway(gateway) + + def settings = new Settings().tap { + setChallenges(new ArrayList().tap { + add(new Challenge()) + }) + } + + when: + Mockito.doReturn(new AccessorResponse().withResult(settings)).when(paymentGateway).settings() + def response = subject.getPaymentSettings() + + then: + HttpStatus.ACCEPTED == response.getStatusCode() + response.getBody() == settings + verify(paymentGateway).settings() || true + } + + def "getPaymentSettings interacts with gateway - 200"() { + given: + BaseController.setGateway(gateway) + + def settings = new Settings() + + when: + Mockito.doReturn(new AccessorResponse().withResult(settings)).when(paymentGateway).settings() + def response = subject.getPaymentSettings() + + then: + HttpStatus.OK == response.getStatusCode() + response.getBody() == settings + verify(paymentGateway).settings() || true + } + + def "setPaymentSettings interacts with gateway - 202"() { + given: + BaseController.setGateway(gateway) + + def settings = new Settings().tap { + setChallenges(new ArrayList().tap { + add(new Challenge()) + }) + } + + when: + Mockito.doReturn(new AccessorResponse().withResult(settings)).when(paymentGateway).updateSettings(settings) + def response = subject.setPaymentSettings(settings) + + then: + HttpStatus.ACCEPTED == response.getStatusCode() + response.getBody() == settings + verify(paymentGateway).updateSettings(settings) || true + } + + def "setPaymentSettings interacts with gateway - 200"() { + given: + BaseController.setGateway(gateway) + + def settings = new Settings() + + when: + Mockito.doReturn(new AccessorResponse().withResult(settings)).when(paymentGateway).updateSettings(settings) + def response = subject.setPaymentSettings(settings) + + then: + HttpStatus.OK == response.getStatusCode() + response.getBody() == settings + verify(paymentGateway).updateSettings(settings) || true + } }