Skip to content

Commit

Permalink
Update capture endpoint to accept intent type string
Browse files Browse the repository at this point in the history
  • Loading branch information
scannillo committed Oct 7, 2019
1 parent 431f608 commit 95edd50
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ String hello() {
}

@RequestMapping("/order-validation-info")
OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", required = false) String payeeEmail,
@RequestParam(value = "amount", required = false) String amount,
@RequestParam(value = "intent", required = false) String intent) {
OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", required = false, defaultValue = "[email protected]") String payeeEmail,
@RequestParam(value = "amount", required = false, defaultValue = "10.00") String amount,
@RequestParam(value = "intent", required = false, defaultValue = "CAPTURE") String intent) {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", token);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
Expand All @@ -60,11 +60,6 @@ OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", r
orderHeaders.add("Authorization", "Bearer " + uat);
orderHeaders.setContentType(MediaType.APPLICATION_JSON);

// Set order request param defaults
payeeEmail = (payeeEmail == null) ? "[email protected]" : payeeEmail; // this request needs an email or it doesn't work
amount = (amount == null) ? "10.00" : amount;
intent = (intent == null) ? "CAPTURE" : intent;

String orderBody = "{\n" +
" \"intent\":\"" + intent + "\",\n" +
" \"purchase_units\":[\n" +
Expand Down Expand Up @@ -173,18 +168,18 @@ OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", r

@RequestMapping("/capture-order/{orderId}")
OrderCaptureInfo captureOrder(@PathVariable String orderId,
@RequestParam(value = "authorize", required = false, defaultValue = "0") String authorize) {
@RequestParam(value = "intent", required = false, defaultValue = "capture") String intent) {
HttpHeaders orderHeaders = new HttpHeaders();
orderHeaders.add("Authorization", token);
orderHeaders.setContentType(MediaType.APPLICATION_JSON);
String intent = authorize == "1" ? "authorize" : "capture";

System.out.println("******************************");
System.out.println("\nREQUEST to /v2/checkout/orders/" + orderId + "/" + intent);
System.out.println("\nREQUEST to /v2/checkout/orders/" + orderId + "/" + intent.toLowerCase());
System.out.println("Intent: " + intent.toLowerCase());
System.out.println("Headers: " + orderHeaders.toString());

HttpEntity<String> orderRequest = new HttpEntity<>(null, orderHeaders);
ResponseEntity<Order> orderResponse = restTemplate.postForEntity(url + "/v2/checkout/orders/" + orderId + "/" + intent, orderRequest, Order.class);
ResponseEntity<Order> orderResponse = restTemplate.postForEntity(url + "/v2/checkout/orders/" + orderId + "/" + intent.toLowerCase(), orderRequest, Order.class);

System.out.println("OrderID: " + orderResponse.getBody().getId());
System.out.println("HTTP status code: " + orderResponse.getStatusCode());
Expand Down

0 comments on commit 95edd50

Please sign in to comment.