Search in sources :

Example 1 with HostedPaymentPageFormDescriptor

use of org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor in project killbill by killbill.

the class PaymentGatewayProcessor method buildFormDescriptor.

public HostedPaymentPageFormDescriptor buildFormDescriptor(final boolean shouldDispatch, final Account account, final UUID paymentMethodId, final Iterable<PluginProperty> customFields, final Iterable<PluginProperty> properties, final CallContext callContext, final InternalCallContext internalCallContext) throws PaymentApiException {
    final String pluginName = getPaymentMethodById(paymentMethodId, true, internalCallContext).getPluginName();
    final PaymentPluginApi plugin = getPaymentPluginApi(pluginName);
    if (shouldDispatch) {
        return dispatchWithExceptionHandling(account, pluginName, new Callable<PluginDispatcherReturnType<HostedPaymentPageFormDescriptor>>() {

            @Override
            public PluginDispatcherReturnType<HostedPaymentPageFormDescriptor> call() throws PaymentApiException {
                try {
                    final HostedPaymentPageFormDescriptor result = plugin.buildFormDescriptor(account.getId(), customFields, properties, callContext);
                    return PluginDispatcher.createPluginDispatcherReturnType(result == null ? new DefaultNoOpHostedPaymentPageFormDescriptor(account.getId()) : result);
                } catch (final RuntimeException e) {
                    throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, MoreObjects.firstNonNull(e.getMessage(), ""));
                } catch (final PaymentPluginApiException e) {
                    throw new PaymentApiException(e, ErrorCode.PAYMENT_PLUGIN_EXCEPTION, e.getErrorMessage());
                }
            }
        }, paymentPluginFormDispatcher);
    } else {
        try {
            return plugin.buildFormDescriptor(account.getId(), customFields, properties, callContext);
        } catch (final PaymentPluginApiException e) {
            throw new PaymentApiException(e, ErrorCode.PAYMENT_PLUGIN_EXCEPTION, e.getErrorMessage());
        }
    }
}
Also used : PaymentPluginApi(org.killbill.billing.payment.plugin.api.PaymentPluginApi) PluginDispatcherReturnType(org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType) DefaultNoOpHostedPaymentPageFormDescriptor(org.killbill.billing.payment.provider.DefaultNoOpHostedPaymentPageFormDescriptor) HostedPaymentPageFormDescriptor(org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor) DefaultNoOpHostedPaymentPageFormDescriptor(org.killbill.billing.payment.provider.DefaultNoOpHostedPaymentPageFormDescriptor) PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException)

Example 2 with HostedPaymentPageFormDescriptor

use of org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor in project killbill by killbill.

the class PaymentGatewayResource method buildFormDescriptor.

@TimedResource
@POST
@Path("/" + HOSTED + "/" + FORM + "/{" + QUERY_ACCOUNT_ID + ":" + UUID_PATTERN + "}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Generate form data to redirect the customer to the gateway", response = HostedPaymentPageFormDescriptorJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid accountId supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response buildFormDescriptor(final HostedPaymentPageFieldsJson json, @PathParam("accountId") final String accountIdString, @QueryParam(QUERY_PAYMENT_METHOD_ID) final String paymentMethodIdStr, @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 {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID accountId = UUID.fromString(accountIdString);
    final Account account = accountUserApi.getAccountById(accountId, callContext);
    final UUID paymentMethodId = paymentMethodIdStr == null ? account.getPaymentMethodId() : UUID.fromString(paymentMethodIdStr);
    validatePaymentMethodForAccount(accountId, paymentMethodId, callContext);
    final Iterable<PluginProperty> customFields = extractPluginProperties(json.getCustomFields());
    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();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) HostedPaymentPageFormDescriptorJson(org.killbill.billing.jaxrs.json.HostedPaymentPageFormDescriptorJson) HostedPaymentPageFormDescriptor(org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor) PaymentOptions(org.killbill.billing.payment.api.PaymentOptions) UUID(java.util.UUID) 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)

Example 3 with HostedPaymentPageFormDescriptor

use of org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor 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();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) HostedPaymentPageFormDescriptorJson(org.killbill.billing.jaxrs.json.HostedPaymentPageFormDescriptorJson) HostedPaymentPageFormDescriptor(org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor) PaymentOptions(org.killbill.billing.payment.api.PaymentOptions) UUID(java.util.UUID) HostedPaymentPageFieldsJson(org.killbill.billing.jaxrs.json.HostedPaymentPageFieldsJson) 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

HostedPaymentPageFormDescriptor (org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 UUID (java.util.UUID)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Account (org.killbill.billing.account.api.Account)2 HostedPaymentPageFormDescriptorJson (org.killbill.billing.jaxrs.json.HostedPaymentPageFormDescriptorJson)2 PaymentOptions (org.killbill.billing.payment.api.PaymentOptions)2 PluginProperty (org.killbill.billing.payment.api.PluginProperty)2 CallContext (org.killbill.billing.util.callcontext.CallContext)2 TimedResource (org.killbill.commons.metrics.TimedResource)2 HostedPaymentPageFieldsJson (org.killbill.billing.jaxrs.json.HostedPaymentPageFieldsJson)1 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)1 PluginDispatcherReturnType (org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType)1 PaymentPluginApi (org.killbill.billing.payment.plugin.api.PaymentPluginApi)1 PaymentPluginApiException (org.killbill.billing.payment.plugin.api.PaymentPluginApiException)1 DefaultNoOpHostedPaymentPageFormDescriptor (org.killbill.billing.payment.provider.DefaultNoOpHostedPaymentPageFormDescriptor)1