use of org.killbill.billing.util.callcontext.CallContext 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();
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class PaymentGatewayResource method buildComboFormDescriptor.
@TimedResource
@POST
@Path("/" + HOSTED + "/" + FORM)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Combo API to generate form data to redirect the customer to the gateway", response = HostedPaymentPageFormDescriptorJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid data for Account or PaymentMethod") })
public Response buildComboFormDescriptor(final ComboHostedPaymentPageJson json, @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, AccountApiException {
verifyNonNullOrEmpty(json, "ComboHostedPaymentPageJson body should be specified");
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Account account = getOrCreateAccount(json.getAccount(), callContext);
final Iterable<PluginProperty> paymentMethodPluginProperties = extractPluginProperties(json.getPaymentMethodPluginProperties());
final UUID paymentMethodId = getOrCreatePaymentMethod(account, json.getPaymentMethod(), paymentMethodPluginProperties, callContext);
final HostedPaymentPageFieldsJson hostedPaymentPageFields = json.getHostedPaymentPageFieldsJson();
final Iterable<PluginProperty> customFields = extractPluginProperties(hostedPaymentPageFields != null ? hostedPaymentPageFields.getCustomFields() : null);
final HostedPaymentPageFormDescriptor descriptor = paymentGatewayApi.buildFormDescriptorWithPaymentControl(account, paymentMethodId, customFields, pluginProperties, paymentOptions, callContext);
final HostedPaymentPageFormDescriptorJson result = new HostedPaymentPageFormDescriptorJson(descriptor);
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class PaymentResource method chargebackReversalPaymentInternal.
private Response chargebackReversalPaymentInternal(final PaymentTransactionJson json, @Nullable final String paymentIdStr, final List<String> paymentControlPluginNames, final List<String> pluginPropertiesString, final String createdBy, final String reason, final String comment, final UriInfo uriInfo, final HttpServletRequest request) throws PaymentApiException, AccountApiException {
verifyNonNullOrEmpty(json, "PaymentTransactionJson body should be specified");
verifyNonNullOrEmpty(json.getTransactionExternalKey(), "PaymentTransactionJson transactionExternalKey needs to be set");
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Payment initialPayment = getPaymentByIdOrKey(paymentIdStr, json.getPaymentExternalKey(), pluginProperties, callContext);
final Account account = accountUserApi.getAccountById(initialPayment.getAccountId(), callContext);
final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
final Payment payment = paymentApi.createChargebackReversalWithPaymentControl(account, initialPayment.getId(), json.getTransactionExternalKey(), paymentOptions, callContext);
return createPaymentResponse(uriInfo, payment, TransactionType.CHARGEBACK, json.getTransactionExternalKey(), request);
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class InvoiceResource method triggerEmailNotificationForInvoice.
@TimedResource
@POST
@Path("/{invoiceId:" + UUID_PATTERN + "}/" + EMAIL_NOTIFICATIONS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Trigger an email notification for invoice")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid invoice id supplied"), @ApiResponse(code = 404, message = "Account or invoice not found") })
public Response triggerEmailNotificationForInvoice(@PathParam("invoiceId") final String invoiceId, @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 HttpServletRequest request) throws InvoiceApiException, AccountApiException {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), callContext);
if (invoice == null) {
throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId);
}
final Account account = accountUserApi.getAccountById(invoice.getAccountId(), callContext);
// Send the email (synchronous send)
invoiceNotifier.notify(account, invoice, callContext);
return Response.status(Status.OK).build();
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class InvoiceResource method commitInvoice.
@TimedResource
@PUT
@Path("/{invoiceId:" + UUID_PATTERN + "}/" + COMMIT_INVOICE)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Perform the invoice status transition from DRAFT to COMMITTED")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Invoice not found") })
public Response commitInvoice(@PathParam("invoiceId") final String invoiceIdString, @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 HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws InvoiceApiException {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID invoiceId = UUID.fromString(invoiceIdString);
invoiceApi.commitInvoice(invoiceId, callContext);
return Response.status(Response.Status.OK).build();
}
Aggregations