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

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

The newest version!
package com.mx.path.model.mdx.web.controller;

import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.Frequency;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.payment.RecurringPayment;

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

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

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

  @RequestMapping(value = "/users/{userId}/recurring_payments", method = RequestMethod.POST, consumes = MDX_MEDIA)
  public final ResponseEntity createRecurringPayment(@RequestBody RecurringPayment recurringPaymentRequest) {
    AccessorResponse response = gateway().payments().recurring().create(recurringPaymentRequest);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }

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

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

  @RequestMapping(value = "/users/{userId}/recurring_payments/{id}", method = RequestMethod.PUT, consumes = MDX_MEDIA)
  public final ResponseEntity updateRecurringPayment(@PathVariable("id") String recurringPaymentId, @RequestBody RecurringPayment recurringPaymentRequest) {
    recurringPaymentRequest.setId(recurringPaymentId);
    AccessorResponse response = gateway().payments().recurring().update(recurringPaymentId, recurringPaymentRequest);
    return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy