com.braintreegateway.Result Java Examples

The following examples show how to use com.braintreegateway.Result. 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: BraintreeResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Path("/refund")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response refund(String transactionId) throws Exception {
    String api = BraintreeApiCollection.getCollection().getApiName(TransactionGatewayApiMethod.class).getName();
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelBraintree.id", transactionId);
    headers.put("CamelBraintree.amount", new BigDecimal("99.00"));

    Result<Transaction> result = producerTemplate.requestBodyAndHeaders("braintree:" + api + "/refund", null, headers,
            Result.class);

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

    return Response.status(Response.Status.OK).entity(objectBuilder.build()).build();
}
 
Example #3
Source File: BraintreeAction.java    From pizzeria with MIT License 3 votes vote down vote up
public String chargeCustomer(String nonce, MonetaryAmount orderCost, MonetaryAmount deliveryCost) {
    BigDecimal amount = orderCost.add(deliveryCost).getNumber().numberValue(BigDecimal.class);

    TransactionRequest transactionRequest = new TransactionRequest().paymentMethodNonce(nonce)
            .amount(amount).options().submitForSettlement(true).done();


    Result<Transaction> transactionResult = braintreeGateway.transaction().sale(transactionRequest);

    return transactionResult.isSuccess() ? transactionResult.getTarget().getId() : StringUtils.EMPTY;
}