Search in sources :

Example 1 with GatewayNotificationJson

use of org.killbill.billing.jaxrs.json.GatewayNotificationJson in project killbill by killbill.

the class PaymentGatewayResource method processNotification.

@TimedResource
@POST
@Path("/" + NOTIFICATION + "/{" + QUERY_PAYMENT_PLUGIN_NAME + ":" + ANYTHING_PATTERN + "}")
@Consumes(WILDCARD)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Process a gateway notification", notes = "The response is built by the appropriate plugin")
@ApiResponses(value = {})
public Response processNotification(final String body, @PathParam(QUERY_PAYMENT_PLUGIN_NAME) final String pluginName, @QueryParam(QUERY_PAYMENT_CONTROL_PLUGIN_NAME) final List<String> paymentControlPluginNames, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final String notificationPayload;
    if (Strings.emptyToNull(body) == null && uriInfo.getRequestUri() != null) {
        notificationPayload = uriInfo.getRequestUri().getRawQuery();
    } else {
        notificationPayload = body;
    }
    // Note: the body is opaque here, as it comes from the gateway. The associated payment plugin will know how to deserialize it though
    final GatewayNotification notification = paymentGatewayApi.processNotificationWithPaymentControl(notificationPayload, pluginName, pluginProperties, paymentOptions, callContext);
    final GatewayNotificationJson result = new GatewayNotificationJson(notification);
    // The plugin told us how to build the response
    return result.toResponse();
}
Also used : GatewayNotificationJson(org.killbill.billing.jaxrs.json.GatewayNotificationJson) PluginProperty(org.killbill.billing.payment.api.PluginProperty) GatewayNotification(org.killbill.billing.payment.plugin.api.GatewayNotification) PaymentOptions(org.killbill.billing.payment.api.PaymentOptions) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 GatewayNotificationJson (org.killbill.billing.jaxrs.json.GatewayNotificationJson)1 PaymentOptions (org.killbill.billing.payment.api.PaymentOptions)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1 GatewayNotification (org.killbill.billing.payment.plugin.api.GatewayNotification)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 TimedResource (org.killbill.commons.metrics.TimedResource)1