Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(path = "requestToken")
- void requestToken(HttpServletResponse response) throws IOException {
- RequestPermissionsResponse requestPermissionsResponse = requestPermissions();
- requestPermissionsResponse.getToken();
- response.sendRedirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=" + requestPermissionsResponse.getToken());
- }
- @RequestMapping(method = GET, path = "callback")
- void oauthCallback(String request_token, String verification_code, HttpServletResponse response) throws IOException, ClientActionRequiredException, InterruptedException, MissingCredentialException, SSLConfigurationException, OAuthException, InvalidResponseDataException, InvalidCredentialException, HttpErrorException {
- logger.info("action=oauth_callback, request_token={}, verification_code={}", request_token, verification_code);
- GetAccessTokenResponse accessToken = getAccessToken(request_token, verification_code);
- ThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(accessToken.getToken(), accessToken.getTokenSecret());
- // Construct a payment from a customer to 2 vendors.
- PayRequest payRequest = new PayRequest();
- List<Receiver> receivers = new ArrayList<>();
- Receiver secondaryReceiver = new Receiver();
- secondaryReceiver.setAmount(1.00);
- secondaryReceiver.setEmail("vendor_1@example.com");
- receivers.add(secondaryReceiver);
- Receiver primaryReceiver = new Receiver();
- primaryReceiver.setAmount(2.00);
- primaryReceiver.setEmail("vendor_2@example.com");
- primaryReceiver.setPrimary(true);
- receivers.add(primaryReceiver);
- ReceiverList receiverList = new ReceiverList(receivers);
- payRequest.setReceiverList(receiverList);
- payRequest.setSenderEmail("customer_1@example.com");
- RequestEnvelope requestEnvelope = new RequestEnvelope("en_US");
- payRequest.setRequestEnvelope(requestEnvelope);
- payRequest.setActionType("PAY");
- payRequest.setCancelUrl("https://devtools-paypal.com/guide/ap_chained_payment?cancel=true");
- payRequest.setReturnUrl("https://devtools-paypal.com/guide/ap_chained_payment?success=true");
- payRequest.setCurrencyCode("USD");
- payRequest.setIpnNotificationUrl("https://example.com/events");
- // Make the payment
- AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(sdkConfig);
- String username = sdkConfig.get("acct1.UserName");
- String password = sdkConfig.get("acct1.Password");
- String signature = sdkConfig.get("acct1.Signature");
- String applicationId = sdkConfig.get("acct1.AppId");
- SignatureCredential credential = new SignatureCredential(username, password, signature);
- credential.setThirdPartyAuthorization(thirdPartyAuthorization);
- credential.setApplicationId(applicationId);
- String authorizationHeader = OAuthSignature.getFullAuthString(username, password, accessToken.getToken(), accessToken.getTokenSecret(), OAuthSignature.HTTPMethod.POST, "https://api.sandbox.paypal.com/nvp", null);
- logger.info("X-PAYPAL-AUTHORIZATION={}", authorizationHeader);
- PayResponse payResponse = adaptivePaymentsService.pay(payRequest, credential);
- }
- 2016-03-07 10:38:21.983 INFO 41378 --- [nio-8080-exec-6] com.paypal.core.APIService:
- responseEnvelope.timestamp=2016-03-07T09%3A38%3A21.955-08%3A00&
- responseEnvelope.ack=Failure&
- responseEnvelope.correlationId=50b62800b3a0f&
- responseEnvelope.build=20420247&
- error(0).errorId=520003&
- error(0).domain=PLATFORM&
- error(0).subdomain=Application&
- error(0).severity=Error&
- error(0).category=Application&
- error(0).message=Authentication+failed.+API+credentials+are+incorrect.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement