Skip to content

Commit

Permalink
Accept payeeEmail and amount query params for v2/checkout/orders call…
Browse files Browse the repository at this point in the history
…. Update README
  • Loading branch information
scannillo committed Oct 4, 2019
1 parent 12eb25c commit 68efe23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -57,6 +59,10 @@ OrderValidationInfo getOrderValidationInfo() {
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;

String orderBody = "{\n" +
" \"intent\":\"CAPTURE\",\n" +
" \"purchase_units\":[\n" +
Expand All @@ -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" +
Expand Down Expand Up @@ -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" +
Expand All @@ -128,7 +134,7 @@ OrderValidationInfo getOrderValidationInfo() {
" }\n" +
" ],\n" +
" \"payee\": {\n" +
" \"email_address\": \"[email protected]\"\n" +
" \"email_address\": \"" + payeeEmail + "\"\n" +
" },\n" +
" \"shipping\":{\n" +
" \"address\":{\n" +
Expand All @@ -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<String> orderRequest = new HttpEntity<>(orderBody, orderHeaders);
ResponseEntity<Order> orderResponse = restTemplate.postForEntity(url + "/v2/checkout/orders", orderRequest, Order.class);
Expand All @@ -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/<order-id>/capture:");
System.out.println("\nREQUEST to /v2/checkout/orders/" + orderId + "/capture:");
System.out.println("Headers: " + orderHeaders.toString());

HttpEntity<String> orderRequest = new HttpEntity<>(null, orderHeaders);
Expand Down

0 comments on commit 68efe23

Please sign in to comment.