Skip to content

Commit

Permalink
Add support for both US and UK test merchants
Browse files Browse the repository at this point in the history
  • Loading branch information
sestevens committed Oct 28, 2019
1 parent 4fa8122 commit 271375d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TOKEN= Basic QVE4eFlkSnh6SndRNmstMzV5dTFTdVpkWmpfcFVrR1lXNmVKZmhVbDkxRlhNLVRWUEF0TDNFWlBNSTdYVGQ4dHZ1aEtzb2pCRVRPbDNsWG46RU95WXI0d0ZzekJoYkxwQzRPLVkybTFYdWQ3NXVkVmJKeFUwbndLZjV3NTFpMUl6V3R4XzJnZjVWR3FKeVRJTDRsdnRaT1ZaRGstZXpXcXA=
US_AUTH=Basic QVE4eFlkSnh6SndRNmstMzV5dTFTdVpkWmpfcFVrR1lXNmVKZmhVbDkxRlhNLVRWUEF0TDNFWlBNSTdYVGQ4dHZ1aEtzb2pCRVRPbDNsWG46RU95WXI0d0ZzekJoYkxwQzRPLVkybTFYdWQ3NXVkVmJKeFUwbndLZjV3NTFpMUl6V3R4XzJnZjVWR3FKeVRJTDRsdnRaT1ZaRGstZXpXcXA=
UK_AUTH=Basic QVMwVURWUG5PeEpVWjJZbDROY294TWVlMEVRUjFoLUVNMlBhb216b3c0OTAxaHVOM1p1VGVUNHg3QXFiN2VCTnh2THdIVjhTc2gwYmVxNXY6RUVIc0xuWml0XzdBWDJRazVlZk9adHZ6NWJrNzVYMnNadktmVDlfSzNmbWliRlYxeDNaamtpMTRpV1BkTUR3dFYySnZqcnotRjE3a3p6dlM=
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
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;

@RestController
public class BTRestController {

private RestTemplate restTemplate;
private String token;
private String usAuth;
private String ukAuth;
private String url;
private String uat;

@Autowired
public BTRestController(RestTemplate restTemplate, @Value("${token}") String token, @Value("${url}") String url) {
public BTRestController(RestTemplate restTemplate, @Value("${authorization.us}") String usAuth, @Value("${authorization.uk}") String ukAuth, @Value("${url}") String url) {
this.restTemplate = restTemplate;
this.token = token;
this.usAuth = usAuth;
this.ukAuth = ukAuth;
this.url = url;
}

Expand All @@ -41,9 +41,10 @@ String hello() {
@RequestMapping("/order-validation-info")
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) {
@RequestParam(value = "intent", required = false, defaultValue = "CAPTURE") String intent,
@RequestParam(value = "partnerCountry", required = false, defaultValue = "US") String partnerCountry) {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", token);
headers.add("Authorization", "US".equals(partnerCountry) ? usAuth : ukAuth);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

Expand All @@ -54,7 +55,6 @@ OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", r
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(body, headers);
ResponseEntity<UniversalAccessToken> response = restTemplate.postForEntity(url + "/v1/oauth2/token", request, UniversalAccessToken.class);
String uat = response.getBody().getToken();
this.uat = uat;

HttpHeaders orderHeaders = new HttpHeaders();
orderHeaders.add("Authorization", "Bearer " + uat);
Expand Down Expand Up @@ -167,10 +167,11 @@ OrderValidationInfo getOrderValidationInfo(@RequestParam(value = "payeeEmail", r
}

@RequestMapping("/process-order/{orderId}")
OrderCaptureInfo captureOrder(@PathVariable String orderId,
@RequestParam(value = "intent", required = false, defaultValue = "capture") String intent) {
OrderCaptureInfo processOrder(@PathVariable String orderId,
@RequestParam(value = "intent", required = false, defaultValue = "capture") String intent,
@RequestParam(value = "partnerCountry", required = false, defaultValue = "US") String partnerCountry) {
HttpHeaders orderHeaders = new HttpHeaders();
orderHeaders.add("Authorization", token);
orderHeaders.add("Authorization", "US".equals(partnerCountry) ? usAuth : ukAuth);
orderHeaders.setContentType(MediaType.APPLICATION_JSON);

System.out.println("******************************");
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ server.port=${PORT:5000}
spring.profiles.active=production
logging.level.org.springframework=INFO

token=${TOKEN}
authorization.us=${US_AUTH}
authorization.uk=${UK_AUTH}
url=https://api.ppcpn.stage.paypal.com
3 changes: 2 additions & 1 deletion src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spring.profiles.active=test
token=test-token
authorization.us=test-us-auth
authorization.uk=test-uk-auth

0 comments on commit 271375d

Please sign in to comment.