@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 = 200, message = "Successful"),*/ @ApiResponse(code = 404, message = "Account not found")}) public Response buildFormDescriptor(@PathParam("accountId") final UUID accountId, final HostedPaymentPageFieldsJson json, @QueryParam(QUERY_PAYMENT_METHOD_ID) final UUID inputPaymentMethodId, @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.createCallContextWithAccountId(accountId, createdBy, reason, comment, request); final Account account = accountUserApi.getAccountById(accountId, callContext); final UUID paymentMethodId = inputPaymentMethodId == null ? account.getPaymentMethodId() : inputPaymentMethodId; validatePaymentMethodForAccount(accountId, paymentMethodId, callContext); final Iterable<PluginProperty> customFields = extractPluginProperties(json.getFormFields()); 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(); }
final GatewayNotification notification = paymentGatewayApi.processNotificationWithPaymentControl(notificationPayload, pluginName, pluginProperties, paymentOptions, callContext); final GatewayNotificationJson result = new GatewayNotificationJson(notification);
@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 = 200, message = "Successful"),*/ @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.createCallContextNoAccountId(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.getHostedPaymentPageFields(); final Iterable<PluginProperty> customFields = extractPluginProperties(hostedPaymentPageFields != null ? hostedPaymentPageFields.getFormFields() : 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(); }
@Test(groups = "fast") public void testBuildFormDescriptorWithPaymentControlAbortedPayment() throws PaymentApiException { plugin.setAborted(true); // Set a random UUID to verify the plugin will successfully override it try { paymentGatewayApi.buildFormDescriptorWithPaymentControl(account, UUID.randomUUID(), ImmutableList.<PluginProperty>of(), ImmutableList.<PluginProperty>of(), paymentOptions, callContext); Assert.fail(); } catch (PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_PLUGIN_API_ABORTED.getCode()); } }
@Test(groups = "fast") public void testBuildFormDescriptorWithPaymentControl() throws PaymentApiException { final List<PluginProperty> initialProperties = new ArrayList<PluginProperty>(); initialProperties.add(new PluginProperty("keyA", "valueA", true)); initialProperties.add(new PluginProperty("keyB", "valueB", true)); initialProperties.add(new PluginProperty("keyC", "valueC", true)); final List<PluginProperty> priorNewProperties = new ArrayList<PluginProperty>(); priorNewProperties.add(new PluginProperty("keyD", "valueD", true)); final List<PluginProperty> priorRemovedProperties = new ArrayList<PluginProperty>(); priorRemovedProperties.add(new PluginProperty("keyA", "valueA", true)); plugin.setPriorCallProperties(priorNewProperties, priorRemovedProperties); final List<PluginProperty> onResultNewProperties = new ArrayList<PluginProperty>(); onResultNewProperties.add(new PluginProperty("keyE", "valueE", true)); final List<PluginProperty> onResultRemovedProperties = new ArrayList<PluginProperty>(); onResultRemovedProperties.add(new PluginProperty("keyB", "valueB", true)); plugin.setOnResultProperties(onResultNewProperties, onResultRemovedProperties); final List<PluginProperty> expectedPriorCallProperties = new ArrayList<PluginProperty>(); expectedPriorCallProperties.add(new PluginProperty("keyB", "valueB", true)); expectedPriorCallProperties.add(new PluginProperty("keyC", "valueC", true)); expectedPriorCallProperties.add(new PluginProperty("keyD", "valueD", true)); validationPlugin.setExpectedPriorCallProperties(expectedPriorCallProperties); final List<PluginProperty> expectedProperties = new ArrayList<PluginProperty>(); expectedProperties.add(new PluginProperty("keyC", "valueC", true)); expectedProperties.add(new PluginProperty("keyD", "valueD", true)); expectedProperties.add(new PluginProperty("keyE", "valueE", true)); validationPlugin.setExpectedProperties(expectedProperties); // Set a random UUID to verify the plugin will successfully override it paymentGatewayApi.buildFormDescriptorWithPaymentControl(account, UUID.randomUUID(), ImmutableList.<PluginProperty>of(), initialProperties, paymentOptions, callContext); }