From 68efe230a061e3c3d7fce241113506dc1a81e2e2 Mon Sep 17 00:00:00 2001 From: scannillo Date: Fri, 4 Oct 2019 14:41:06 -0500 Subject: [PATCH] Accept payeeEmail and amount query params for v2/checkout/orders call. Update README --- README.md | 9 ++++++--- .../BTRestController.java | 20 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e2201c0..ed04409 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ ## About This repository represents a sample merchant server for a merchant integrating with `BraintreePayPalValidator`. This repository uses sample PayPal merchant staging credentials to create PayPal orderIDs and universal access tokens, and to capture orders. -## Setup -After cloning this repo, add a file called `.env` in the root directory. Add `TOKEN=xxxx` where xxxx is the value found in the Team SDK Heroku dashboard under Settings -> Config Vars. - ## Build and run locally - To build, run `./gradlew clean build`. - To run locally with Heroku, run `heroku local web`. @@ -13,6 +10,12 @@ If everything worked, you should be able to hit `http://localhost:5000/order-val **Note:** This can't be deployed to Heroku at the moment, because we aren't able to hit `/v2/checkout/orders` outside of the PayPal network. +## Switching Merchant Account/ Authentication + +To change the merchant account used on this server, navigate to the `.env` file. Change the `TOKEN= Basic xxxx` where `xxxx` is the value of your new desired authorization credentials. + +After making this change, execute both the build and run steps in the *Build and run locally* section above. + ## Troubleshooting ### PayPal v2/orders Request Limitations diff --git a/src/main/java/com/braintree/braintreep4psamplemerchant/BTRestController.java b/src/main/java/com/braintree/braintreep4psamplemerchant/BTRestController.java index f04500e..91de126 100644 --- a/src/main/java/com/braintree/braintreep4psamplemerchant/BTRestController.java +++ b/src/main/java/com/braintree/braintreep4psamplemerchant/BTRestController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.client.RestTemplate; +import org.springframework.web.bind.annotation.RequestParam; import java.util.Collections; @@ -38,7 +39,8 @@ String hello() { } @RequestMapping("/order-validation-info") - OrderValidationInfo getOrderValidationInfo() { + OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", required = false) String payeeEmail, + @RequestParam(value = "amount", required = false) String amount) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", token); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); @@ -57,6 +59,10 @@ OrderValidationInfo getOrderValidationInfo() { orderHeaders.add("Authorization", "Bearer " + uat); orderHeaders.setContentType(MediaType.APPLICATION_JSON); + // Set order request param defaults + payeeEmail = (payeeEmail == null) ? "sample@email.com" : payeeEmail; // this request needs an email or it doesn't work + amount = (amount == null) ? "10.00" : amount; + String orderBody = "{\n" + " \"intent\":\"CAPTURE\",\n" + " \"purchase_units\":[\n" + @@ -68,11 +74,11 @@ OrderValidationInfo getOrderValidationInfo() { " \"soft_descriptor\":\"SOFT1001\",\n" + " \"amount\":{\n" + " \"currency_code\":\"USD\",\n" + - " \"value\":\"125.00\",\n" + + " \"value\":\"" + amount + "\",\n" + " \"breakdown\":{\n" + " \"item_total\":{\n" + " \"currency_code\":\"USD\",\n" + - " \"value\":\"125.00\"\n" + + " \"value\":\"" + amount + "\"\n" + " },\n" + " \"shipping\":{\n" + " \"currency_code\":\"USD\",\n" + @@ -103,7 +109,7 @@ OrderValidationInfo getOrderValidationInfo() { " \"sku\": \"259483234816\",\n" + " \"unit_amount\": {\n" + " \"currency_code\": \"USD\",\n" + - " \"value\": \"125.00\"\n" + + " \"value\": \"" + amount + "\"\n" + " },\n" + " \"tax\": {\n" + " \"currency_code\": \"USD\",\n" + @@ -128,7 +134,7 @@ OrderValidationInfo getOrderValidationInfo() { " }\n" + " ],\n" + " \"payee\": {\n" + - " \"email_address\": \"rtimoschuk-us-bus-onb-ppcp-approve-seller15@paypal.com\"\n" + + " \"email_address\": \"" + payeeEmail + "\"\n" + " },\n" + " \"shipping\":{\n" + " \"address\":{\n" + @@ -150,6 +156,8 @@ OrderValidationInfo getOrderValidationInfo() { System.out.println("******************************"); System.out.println("\nREQUEST to /v2/checkout/orders:"); System.out.println("Headers: " + orderHeaders.toString()); + System.out.println("Payee Email: " + payeeEmail); + System.out.println("Amount: " + amount); HttpEntity orderRequest = new HttpEntity<>(orderBody, orderHeaders); ResponseEntity orderResponse = restTemplate.postForEntity(url + "/v2/checkout/orders", orderRequest, Order.class); @@ -167,7 +175,7 @@ OrderCaptureInfo captureOrder(@PathVariable String orderId) { orderHeaders.setContentType(MediaType.APPLICATION_JSON); System.out.println("******************************"); - System.out.println("\nREQUEST to /v2/checkout/orders//capture:"); + System.out.println("\nREQUEST to /v2/checkout/orders/" + orderId + "/capture:"); System.out.println("Headers: " + orderHeaders.toString()); HttpEntity orderRequest = new HttpEntity<>(null, orderHeaders);