All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mx.path.model.mdx.web.controller.PaymentsController Maven / Gradle / Ivy

There is a newer version: 16.0.0
Show newest version
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.account.Account;
import com.mx.path.model.mdx.model.payment.Enrollment;
import com.mx.path.model.mdx.model.payment.Payment;
import com.mx.path.model.mdx.model.payment.Settings;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
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}/users/{user_id}", produces = BaseController.MDX_MEDIA)
public class PaymentsController extends BaseController {

  @RequestMapping(value = "/payments/enrollment", method = RequestMethod.GET)
  public final ResponseEntity getPaymentEnrollment() {
    AccessorResponse response = gateway().payments().enrollment();
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/payments/enrollment", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA)
  public final ResponseEntity setPaymentEnrollment(@RequestBody Enrollment enrollmentRequest) {
    AccessorResponse response = gateway().payments().updateEnrollment(enrollmentRequest);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/payments/settings", method = RequestMethod.GET)
  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);
  }

  @RequestMapping(value = "/payments", method = RequestMethod.POST, consumes = BaseController.MDX_MEDIA)
  public final ResponseEntity createPayment(@RequestBody Payment paymentRequest) {
    AccessorResponse response = gateway().payments().create(paymentRequest);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/payments", method = RequestMethod.GET)
  public final ResponseEntity> getPaymentList() {
    AccessorResponse> response = gateway().payments().list();
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/payments/{id}", method = RequestMethod.GET)
  public final ResponseEntity getPayment(@PathVariable("id") String paymentId) {
    AccessorResponse response = gateway().payments().get(paymentId);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/payments/{id}/cancel", method = RequestMethod.PUT)
  public final ResponseEntity cancelPayment(@PathVariable("id") String paymentId) {
    AccessorResponse response = gateway().payments().cancel(paymentId);
    return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
  }

  @RequestMapping(value = "/payments/{id}", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA)
  public final ResponseEntity updatePayment(@PathVariable("id") String paymentId, @RequestBody Payment paymentRequest) {
    paymentRequest.setId(paymentId);
    AccessorResponse response = gateway().payments().update(paymentId, paymentRequest);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/accounts/payment", method = RequestMethod.GET)
  public final ResponseEntity> getAccountsUsedForPayments() {
    AccessorResponse> response = gateway().payments().accounts();
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy