-
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.
Add support for both US and UK test merchants
- Loading branch information
Showing
4 changed files
with
20 additions
and
16 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
TOKEN= Basic QVE4eFlkSnh6SndRNmstMzV5dTFTdVpkWmpfcFVrR1lXNmVKZmhVbDkxRlhNLVRWUEF0TDNFWlBNSTdYVGQ4dHZ1aEtzb2pCRVRPbDNsWG46RU95WXI0d0ZzekJoYkxwQzRPLVkybTFYdWQ3NXVkVmJKeFUwbndLZjV3NTFpMUl6V3R4XzJnZjVWR3FKeVRJTDRsdnRaT1ZaRGstZXpXcXA= | ||
US_AUTH=Basic QVE4eFlkSnh6SndRNmstMzV5dTFTdVpkWmpfcFVrR1lXNmVKZmhVbDkxRlhNLVRWUEF0TDNFWlBNSTdYVGQ4dHZ1aEtzb2pCRVRPbDNsWG46RU95WXI0d0ZzekJoYkxwQzRPLVkybTFYdWQ3NXVkVmJKeFUwbndLZjV3NTFpMUl6V3R4XzJnZjVWR3FKeVRJTDRsdnRaT1ZaRGstZXpXcXA= | ||
UK_AUTH=Basic QVMwVURWUG5PeEpVWjJZbDROY294TWVlMEVRUjFoLUVNMlBhb216b3c0OTAxaHVOM1p1VGVUNHg3QXFiN2VCTnh2THdIVjhTc2gwYmVxNXY6RUVIc0xuWml0XzdBWDJRazVlZk9adHZ6NWJrNzVYMnNadktmVDlfSzNmbWliRlYxeDNaamtpMTRpV1BkTUR3dFYySnZqcnotRjE3a3p6dlM= |
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 |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
|
@@ -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)); | ||
|
||
|
@@ -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); | ||
|
@@ -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("******************************"); | ||
|
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
spring.profiles.active=test | ||
token=test-token | ||
authorization.us=test-us-auth | ||
authorization.uk=test-uk-auth |