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

com.mx.path.model.mdx.web.controller.RecurringTransfersController 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.transfer.RecurringTransfer;
import com.mx.path.model.mdx.model.transfer.options.RecurringTransferListOptions;
import com.mx.path.model.mdx.web.model.transfer.RecurringTransferListQueryParameters;

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}", produces = BaseController.MDX_MEDIA)
public class RecurringTransfersController extends BaseController {

  @RequestMapping(value = "/users/{userId}/recurring_transfers", method = RequestMethod.GET)
  public final ResponseEntity> list(RecurringTransferListQueryParameters queryParameters) {
    RecurringTransferListOptions options = new RecurringTransferListOptions();
    options.setTransferType(queryParameters.getTransfer_type());
    AccessorResponse> response = gateway().transfers().recurring().list(options);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/users/{userId}/recurring_transfers", method = RequestMethod.POST, consumes = MDX_MEDIA)
  public final ResponseEntity postRecurringTransfers(@RequestBody RecurringTransfer recurringTransferRequest) {
    AccessorResponse response = gateway().transfers().recurring().create(recurringTransferRequest);
    RecurringTransfer result = response.getResult();
    HttpStatus status = HttpStatus.OK;
    if (result.getChallenges() != null && result.getChallenges().size() > 0) {
      status = HttpStatus.ACCEPTED;
    }
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status);
  }

  @RequestMapping(value = "/users/{userId}/recurring_transfers/{id}/cancel", method = RequestMethod.PUT)
  public final ResponseEntity deleteRecurringTransfer(@PathVariable("id") String recurringTransferId) {
    AccessorResponse response = gateway().transfers().recurring().delete(recurringTransferId);
    return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
  }

  @RequestMapping(value = "/users/{userId}/recurring_transfers/{id}", method = RequestMethod.GET)
  public final ResponseEntity getRecurringTransfer(@PathVariable("id") String recurringTransferId) {
    AccessorResponse response = gateway().transfers().recurring().get(recurringTransferId);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/users/{userId}/recurring_transfers/{id}/skip_next", method = RequestMethod.PUT)
  public final ResponseEntity skipNextRecurringTransfer(@PathVariable("id") String recurringTransferId) {
    AccessorResponse response = gateway().transfers().recurring().skipNext(recurringTransferId);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

  @RequestMapping(value = "/users/{userId}/recurring_transfers/{id}", method = RequestMethod.PUT, consumes = MDX_MEDIA)
  public final ResponseEntity updateRecurringTransfer(@PathVariable("id") String recurringTransferId, @RequestBody RecurringTransfer recurringTransferRequest) {
    recurringTransferRequest.setId(recurringTransferId);
    AccessorResponse response = gateway().transfers().recurring().update(recurringTransferId, recurringTransferRequest);
    RecurringTransfer result = response.getResult();
    HttpStatus status = HttpStatus.OK;
    if (result.getChallenges() != null && result.getChallenges().size() > 0) {
      status = HttpStatus.ACCEPTED;
    }
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy