Skip to content

Instantly share code, notes, and snippets.

@berndruecker
Last active April 24, 2017 08:15
Show Gist options
  • Save berndruecker/b815b0fcb698ce88350fcb458afa7bc0 to your computer and use it in GitHub Desktop.
Save berndruecker/b815b0fcb698ce88350fcb458afa7bc0 to your computer and use it in GitHub Desktop.
public class RetrievePaymentRestAdapter implements JavaDelegate {
@Inject private OrderRepository orderRepository; // e.g. using Spring
@Inject private RestTemplate rest; // e.g. using Spring
public void execute(DelegateExecution context) throws Exception {
// Input mapping
String orderId = context.getVariable("orderId");
Order o = orderRepository.findOrder(orderId);
CreateChargeRequest request = new CreateChargeRequest();
request.setAmount( o.getAmount() );
// Service call by technology of choice (e.g. Spring RestTemplate)
CreateChargeResponse response = rest.postForObject("https://api.stripe.com",
request, CreateChargeResponse.class);
// Output mapping
context.setVariable("stripeTransactionId", response.getBalanceTransaction());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment