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

com.mx.path.model.mdx.web.controller.PayeesController 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.payment.Payee;

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 PayeesController extends BaseController {

  @RequestMapping(value = "/payees", method = RequestMethod.POST, consumes = BaseController.MDX_MEDIA)
  public final ResponseEntity addPayee(@RequestBody Payee payeeRequest) {
    AccessorResponse accessorResponse = gateway().payments().payees().create(payeeRequest);
    HttpStatus status = accessorResponse.getStatus() != null ? HttpStatus.valueOf(accessorResponse.getStatus().value()) : HttpStatus.OK;
    return new ResponseEntity<>(accessorResponse.getResult().wrapped(), createMultiMapForResponse(accessorResponse.getHeaders()), status);
  }

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

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

  @RequestMapping(value = "/payees/{id}", method = RequestMethod.DELETE)
  public final ResponseEntity deletePayee(@PathVariable("id") String payeeId) {
    AccessorResponse response = gateway().payments().payees().delete(payeeId);
    return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy