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

io.electrum.suv.api.VouchersResource Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package io.electrum.suv.api;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;

import io.electrum.suv.api.models.ErrorDetail;
import io.electrum.suv.api.models.ProvisionRequest;
import io.electrum.suv.api.models.ProvisionResponse;
import io.electrum.suv.api.utils.Paths;
import io.electrum.vas.model.BasicReversal;
import io.electrum.vas.model.TenderAdvice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;

@Path(Paths.BASE_PATH)
@Api(description = "The SUV API Provision operations", authorizations = { @Authorization(value = "httpBasic") })
public abstract class VouchersResource {
   protected abstract IVouchersResource getResourceImplementation();

   @POST
   @Path(Paths.PROVISION_VOUCHER)
   @Consumes({ "application/json" })
   @Produces({ "application/json" })
   @ApiOperation(value = "Request a voucher be provisioned.",
           nickname = Operations.PROVISION_VOUCHER,
           notes = "Requests a voucher from the voucher vendor.",
           response = ProvisionResponse.class)
   @ApiResponses(value = { @ApiResponse(code = 201, message = "Created", response = ProvisionResponse.class),
         @ApiResponse(code = 400, message = "Bad Request", response = ErrorDetail.class),
         @ApiResponse(code = 500, message = "Internal Server Error", response = ErrorDetail.class),
         @ApiResponse(code = 503, message = "Service Unavailable", response = ErrorDetail.class),
         @ApiResponse(code = 504, message = "Gateway Timeout", response = ErrorDetail.class) })
   public final void provisionVoucher(
         @ApiParam(value = "A provision request.", required = true) ProvisionRequest body,
         @Context SecurityContext securityContext,
         @Context Request request,
         @Suspended AsyncResponse asyncResponse,
         @Context HttpHeaders httpHeaders,
         @Context UriInfo uriInfo,
         @Context HttpServletRequest httpServletRequest) {
      getResourceImplementation()
            .provisionVoucher(body, securityContext, request, asyncResponse, httpHeaders, uriInfo, httpServletRequest);
   }

   @POST
   @Path(Paths.CONFIRM_VOUCHER)
   @Consumes({ "application/json" })
   @Produces({ "application/json" })
   @ApiOperation(value = "Confirm a voucher provision request that completed successfully.",
           nickname = Operations.CONFIRM_VOUCHER,
           notes = "Once a consumer has paid for a voucher and received the voucher from the merchant"
         + " the merchant must notify the vendor that the voucher may be redeemed at some point "
         + "in the future as per the voucher vendor's instructions. confirmVoucher must be repeated "
         + "until a final HTTP status code is received (i.e. not HTTP 5xx). confirmVoucher may be "
         + "called repeatedly on the same voucher resource without negative effect.",
           response = TenderAdvice.class)
   @ApiResponses(value = { @ApiResponse(code = 202, message = "Accepted", response = TenderAdvice.class),
         @ApiResponse(code = 400, message = "Bad Request", response = ErrorDetail.class),
         @ApiResponse(code = 404, message = "Not Found", response = ErrorDetail.class),
         @ApiResponse(code = 500, message = "Internal Server Error", response = ErrorDetail.class),
         @ApiResponse(code = 503, message = "Service Unavailable", response = ErrorDetail.class),
         @ApiResponse(code = 504, message = "Gateway Timeout", response = ErrorDetail.class) })
   public final void confirmVoucher(
         @ApiParam(value = "A voucher provision confirmation.", required = true) TenderAdvice body,
         @Context SecurityContext securityContext,
         @Context Request request,
         @Suspended AsyncResponse asyncResponse,
         @Context HttpHeaders httpHeaders,
         @Context UriInfo uriInfo,
         @Context HttpServletRequest httpServletRequest) {
      getResourceImplementation()
            .confirmVoucher(body, securityContext, request, asyncResponse, httpHeaders, uriInfo, httpServletRequest);
   }

   @POST
   @Path(Paths.REVERSE_VOUCHER)
   @Consumes({ "application/json" })
   @Produces({ "application/json" })
   @ApiOperation(value = "Reverse a voucher provision request that failed or timed out.",
           nickname = Operations.REVERSE_VOUCHER,
           notes = "If a voucherProvision request fails with one of the 5xx HTTP statuses code,"
         + " or no response was received within the timeout period, it must be reversed to ensure the vendor "
         + "knows to never expect further messages pertaining to the voucher. reverseVoucher must be "
         + "repeated until a final HTTP status code is received (i.e. not 5xx). reverseVoucher may be "
         + "called repeatedly on the same voucher resource without negative effect.",
           response = BasicReversal.class)
   @ApiResponses(value = { @ApiResponse(code = 202, message = "Accepted", response = BasicReversal.class),
         @ApiResponse(code = 400, message = "Bad Request", response = ErrorDetail.class),
         @ApiResponse(code = 404, message = "Not Found", response = ErrorDetail.class),
         @ApiResponse(code = 500, message = "Internal Server Error", response = ErrorDetail.class),
         @ApiResponse(code = 503, message = "Service Unavailable", response = ErrorDetail.class),
         @ApiResponse(code = 504, message = "Gateway Timeout", response = ErrorDetail.class) })
   public final void reverseVoucher(
         @ApiParam(value = "A voucher provision reversal.", required = true) BasicReversal body,
         @Context SecurityContext securityContext,
         @Context Request request,
         @Suspended AsyncResponse asyncResponse,
         @Context HttpHeaders httpHeaders,
         @Context UriInfo uriInfo,
         @Context HttpServletRequest httpServletRequest) {
      getResourceImplementation()
            .reverseVoucher(body, securityContext, request, asyncResponse, httpHeaders, uriInfo, httpServletRequest);
   }

   public class Operations {
      public final static String PROVISION_VOUCHER = "provisionVoucher";
      public final static String CONFIRM_VOUCHER = "confirmVoucher";
      public final static String REVERSE_VOUCHER = "reverseVoucher";

   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy