org.apache.camel.component.braintree.BraintreeComponent Java Examples

The following examples show how to use org.apache.camel.component.braintree.BraintreeComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BraintreeResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Path("/sale")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response sale() throws Exception {
    String api = BraintreeApiCollection.getCollection().getApiName(TransactionGatewayApiMethod.class).getName();
    TransactionRequest transaction = new TransactionRequest()
            .amount(new BigDecimal("100.00"))
            .paymentMethodNonce("fake-valid-nonce")
            .options()
            .submitForSettlement(true)
            .done();
    Result<Transaction> result = producerTemplate.requestBody("braintree:" + api + "/sale?inBody=request", transaction,
            Result.class);

    CamelContext camelContext = producerTemplate.getCamelContext();
    BraintreeComponent component = camelContext.getComponent("braintree", BraintreeComponent.class);
    BraintreeGateway gateway = component.getGateway(component.getConfiguration());
    gateway.testing().settle(result.getTarget().getId());

    JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
    objectBuilder.add("success", result.isSuccess());
    objectBuilder.add("transactionId", result.getTarget().getId());

    return Response.status(Response.Status.OK).entity(objectBuilder.build()).build();
}
 
Example #2
Source File: BraintreeRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Always disable the {@link org.apache.camel.component.braintree.internal.BraintreeLogHandler}.
 *
 * It's not desirable to configure this where an existing JUL - SLF4J bridge exists on the classpath.
 */
public RuntimeValue<BraintreeComponent> configureBraintreeComponent() {
    BraintreeComponent component = new BraintreeComponent();
    BraintreeConfiguration configuration = new BraintreeConfiguration();
    configuration.setLogHandlerEnabled(false);
    component.setConfiguration(configuration);
    return new RuntimeValue<>(component);
}
 
Example #3
Source File: BraintreeComponentAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean(name = "braintree-component")
@ConditionalOnMissingBean(BraintreeComponent.class)
public BraintreeComponent configureBraintreeComponent() throws Exception {
    BraintreeComponent component = new BraintreeComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, component,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (ComponentCustomizer<BraintreeComponent> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.braintree.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.braintree.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure component {}, with customizer {}",
                        component, customizer);
                customizer.customize(component);
            }
        }
    }
    return component;
}
 
Example #4
Source File: BraintreeIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testBraintreeClientTokenGateway() throws Exception {

    Map<String, Object> braintreeOptions = createBraintreeOptions();

    Assume.assumeTrue("[#1679] Enable Braintree testing in Jenkins",
            braintreeOptions.size() == BraintreeOption.values().length);

    final CountDownLatch latch = new CountDownLatch(1);
    final CamelContext camelctx = new DefaultCamelContext();
    final BraintreeConfiguration configuration = new BraintreeConfiguration();
    configuration.setHttpLogLevel(Level.WARNING);
    IntrospectionSupport.setProperties(configuration, braintreeOptions);

    // add BraintreeComponent to Camel context
    final BraintreeComponent component = new BraintreeComponent(camelctx);
    component.setConfiguration(configuration);
    camelctx.addComponent("braintree", component);

    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("timer://braintree?repeatCount=1")
                .to("braintree:clientToken/generate")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        latch.countDown();
                    }})
                .to("mock:result");
        }
    });

    camelctx.start();
    try {
        Assert.assertTrue("Countdown reached zero", latch.await(5, TimeUnit.MINUTES));
    } finally {
        camelctx.close();
    }
}
 
Example #5
Source File: BraintreeProcessor.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelBeanBuildItem configureBraintreeComponent(BraintreeRecorder recorder) {
    return new CamelBeanBuildItem("braintree", BraintreeComponent.class.getName(),
            recorder.configureBraintreeComponent());
}