Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. @RequestMapping(path = "requestToken")
  2. void requestToken(HttpServletResponse response) throws IOException {
  3. RequestPermissionsResponse requestPermissionsResponse = requestPermissions();
  4. requestPermissionsResponse.getToken();
  5. response.sendRedirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=" + requestPermissionsResponse.getToken());
  6. }
  7.  
  8. @RequestMapping(method = GET, path = "callback")
  9. void oauthCallback(String request_token, String verification_code, HttpServletResponse response) throws IOException, ClientActionRequiredException, InterruptedException, MissingCredentialException, SSLConfigurationException, OAuthException, InvalidResponseDataException, InvalidCredentialException, HttpErrorException {
  10. logger.info("action=oauth_callback, request_token={}, verification_code={}", request_token, verification_code);
  11.  
  12. GetAccessTokenResponse accessToken = getAccessToken(request_token, verification_code);
  13. ThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(accessToken.getToken(), accessToken.getTokenSecret());
  14.  
  15. // Construct a payment from a customer to 2 vendors.
  16. PayRequest payRequest = new PayRequest();
  17.  
  18. List<Receiver> receivers = new ArrayList<>();
  19. Receiver secondaryReceiver = new Receiver();
  20. secondaryReceiver.setAmount(1.00);
  21. secondaryReceiver.setEmail("vendor_1@example.com");
  22. receivers.add(secondaryReceiver);
  23.  
  24. Receiver primaryReceiver = new Receiver();
  25. primaryReceiver.setAmount(2.00);
  26. primaryReceiver.setEmail("vendor_2@example.com");
  27. primaryReceiver.setPrimary(true);
  28. receivers.add(primaryReceiver);
  29. ReceiverList receiverList = new ReceiverList(receivers);
  30.  
  31. payRequest.setReceiverList(receiverList);
  32. payRequest.setSenderEmail("customer_1@example.com");
  33.  
  34. RequestEnvelope requestEnvelope = new RequestEnvelope("en_US");
  35. payRequest.setRequestEnvelope(requestEnvelope);
  36. payRequest.setActionType("PAY");
  37. payRequest.setCancelUrl("https://devtools-paypal.com/guide/ap_chained_payment?cancel=true");
  38. payRequest.setReturnUrl("https://devtools-paypal.com/guide/ap_chained_payment?success=true");
  39. payRequest.setCurrencyCode("USD");
  40. payRequest.setIpnNotificationUrl("https://example.com/events");
  41.  
  42. // Make the payment
  43. AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(sdkConfig);
  44. String username = sdkConfig.get("acct1.UserName");
  45. String password = sdkConfig.get("acct1.Password");
  46. String signature = sdkConfig.get("acct1.Signature");
  47. String applicationId = sdkConfig.get("acct1.AppId");
  48.  
  49. SignatureCredential credential = new SignatureCredential(username, password, signature);
  50. credential.setThirdPartyAuthorization(thirdPartyAuthorization);
  51. credential.setApplicationId(applicationId);
  52.  
  53. String authorizationHeader = OAuthSignature.getFullAuthString(username, password, accessToken.getToken(), accessToken.getTokenSecret(), OAuthSignature.HTTPMethod.POST, "https://api.sandbox.paypal.com/nvp", null);
  54. logger.info("X-PAYPAL-AUTHORIZATION={}", authorizationHeader);
  55.  
  56. PayResponse payResponse = adaptivePaymentsService.pay(payRequest, credential);
  57. }
  58.  
  59. 2016-03-07 10:38:21.983 INFO 41378 --- [nio-8080-exec-6] com.paypal.core.APIService:
  60. responseEnvelope.timestamp=2016-03-07T09%3A38%3A21.955-08%3A00&
  61. responseEnvelope.ack=Failure&
  62. responseEnvelope.correlationId=50b62800b3a0f&
  63. responseEnvelope.build=20420247&
  64. error(0).errorId=520003&
  65. error(0).domain=PLATFORM&
  66. error(0).subdomain=Application&
  67. error(0).severity=Error&
  68. error(0).category=Application&
  69. error(0).message=Authentication+failed.+API+credentials+are+incorrect.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement