-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update capture endpoint to accept intent type string
- Loading branch information
scannillo
committed
Oct 7, 2019
1 parent
431f608
commit 95edd50
Showing
1 changed file
with
7 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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" + | ||
|
@@ -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()); | ||
|