{"action":"created","comment":{"url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/comments/68147696","id":68147696,"diff_hunk":"@@ -95,4 +109,21 @@ public Tokeninfo getTokeninfo(CreateFromRefreshTokenParameters params, Tokeninfo\n \t\treturn info;\n \t}\n \n+\t/**\n+\t * Fetches long lived refresh token from authorization code, for future payment use. \n+\t * \n+\t * @param context\n+\t * @param authorizationCode\n+\t * @return\n+\t * @throws PayPalRESTException\n+\t */\n+\tpublic static String fetchRefreshToken(APIContext context, String authorizationCode) throws PayPalRESTException {\n+\t\tCreateFromAuthorizationCodeParameters params = new CreateFromAuthorizationCodeParameters();\n+\t\tparams.setClientID(context.getClientID());\n+\t\tparams.setClientSecret(context.getClientSecret());\n+\t\tparams.setCode(authorizationCode);\n+\t\tTokeninfo info = Tokeninfo.createFromAuthorizationCodeForFpp(context, params);","path":"rest-api-sdk/src/main/java/com/paypal/api/payments/FuturePayment.java","position":131,"original_position":45,"commit_id":"3c85f96b1a56594d6021d25fa80a935f3f3aefd3","original_commit_id":"3c85f96b1a56594d6021d25fa80a935f3f3aefd3","user":{"login":"braebot","id":3358986,"avatar_url":"https://avatars.githubusercontent.com/u/3358986?v=3","gravatar_id":"","url":"https://api.github.com/users/braebot","html_url":"https://github.com/braebot","followers_url":"https://api.github.com/users/braebot/followers","following_url":"https://api.github.com/users/braebot/following{/other_user}","gists_url":"https://api.github.com/users/braebot/gists{/gist_id}","starred_url":"https://api.github.com/users/braebot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/braebot/subscriptions","organizations_url":"https://api.github.com/users/braebot/orgs","repos_url":"https://api.github.com/users/braebot/repos","events_url":"https://api.github.com/users/braebot/events{/privacy}","received_events_url":"https://api.github.com/users/braebot/received_events","type":"User","site_admin":false},"body":"are you missing the `authorization_code` grant type here?  It's in the other method below.  In fact, the code is so similar, you should consider refactoring it so it's not copy/pasted.  :)","created_at":"2016-06-22T22:34:01Z","updated_at":"2016-06-22T22:34:01Z","html_url":"https://github.com/paypal/PayPal-Java-SDK/pull/191#discussion_r68147696","pull_request_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191","_links":{"self":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/comments/68147696"},"html":{"href":"https://github.com/paypal/PayPal-Java-SDK/pull/191#discussion_r68147696"},"pull_request":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191"}}},"pull_request":{"url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191","id":74163886,"html_url":"https://github.com/paypal/PayPal-Java-SDK/pull/191","diff_url":"https://github.com/paypal/PayPal-Java-SDK/pull/191.diff","patch_url":"https://github.com/paypal/PayPal-Java-SDK/pull/191.patch","issue_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/191","number":191,"state":"open","locked":false,"title":"[WIP] Made APIContext better","user":{"login":"jaypatel512","id":1309895,"avatar_url":"https://avatars.githubusercontent.com/u/1309895?v=3","gravatar_id":"","url":"https://api.github.com/users/jaypatel512","html_url":"https://github.com/jaypatel512","followers_url":"https://api.github.com/users/jaypatel512/followers","following_url":"https://api.github.com/users/jaypatel512/following{/other_user}","gists_url":"https://api.github.com/users/jaypatel512/gists{/gist_id}","starred_url":"https://api.github.com/users/jaypatel512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaypatel512/subscriptions","organizations_url":"https://api.github.com/users/jaypatel512/orgs","repos_url":"https://api.github.com/users/jaypatel512/repos","events_url":"https://api.github.com/users/jaypatel512/events{/privacy}","received_events_url":"https://api.github.com/users/jaypatel512/received_events","type":"User","site_admin":false},"body":"This PR makes getting started extremely simple. This is how better it makes:\r\n\r\n## Examples\r\n### BEFORE\r\n```java\r\n\t\tMap<String, String> map = new HashMap<String, String>();\r\n\t\tmap.put(\"mode\", \"sandbox\");\r\n\t\t\r\n\t\tString accessToken = new OAuthTokenCredential(clientId, clientSecret, map).getAccessToken();\r\n\t\t\r\n\t\tAPIContext context = new APIContext(accessToken);\r\n\t\tcontext.setConfigurationMap(map);\r\n\r\n\t\tCreditCard card = new CreditCard();\r\n\t\tcard.setType(\"visa\");\r\n\t\t...\r\n\r\n\t\ttry {\r\n\t\t\tCreditCard result = card.create(context);\r\n\t\t} catch (PayPalRESTException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n```\r\n### AFTER\r\n```java\r\n        APIContext context = new APIContext(clientId, clientSecret, \"sandbox\");\r\n\t\t\r\n\t\tCreditCard card = new CreditCard();\r\n\t\tcard.setType(\"visa\");\r\n\t\t...\r\n\r\n\t\ttry {\r\n\t\t\tCreditCard result = card.create(context);\r\n\t\t} catch (PayPalRESTException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\r\n```\r\n\r\n## THIRD PARTY INVOICING/FUTURE PAYMENTS\r\n\r\n### BEFORE\r\n```java\r\nTokeninfo tokeninfo = null;\r\n// Setup the refresh token params. This will be used to get access token\r\n// from refresh token\r\nClientCredentials credentials = PayPalResource.getCredential();\r\nCreateFromRefreshTokenParameters params = new CreateFromRefreshTokenParameters();\r\nparams.setClientID(credentials.getClientID());\r\nparams.setClientSecret(credentials.getClientSecret());\r\n\r\n// Create a token info object, and call `createFromRefreshToken`\r\nTokeninfo info = new Tokeninfo();\r\ninfo.setRefreshToken(refreshToken);\r\ntokeninfo = info.createFromRefreshToken(params);\r\n\r\n// Set Access Token Appropriately\r\ntokeninfo.setAccessToken(tokeninfo.getTokenType() + \" \" + tokeninfo.getAccessToken());\r\n// Use this accessToken to make any calls to Invoice\r\naccessToken = tokeninfo.getAccessToken();\r\n\r\n// populate Invoice object that we are going to play with\r\nInvoice invoice = new Invoice();\r\n// Load invoice data\r\n// ...\r\n// ...\r\n// Use third party access token retrieved before\r\nInvoice result = invoice.create(accessToken);\r\n```\r\n### AFTER\r\n```java\r\n// Setup APIContext\r\nAPIContext thirdPartyContext = new APIContext(clientID, clientSecret, \"sandbox\").setRefreshToken(refreshToken);\r\nInvoice invoice = new Invoice();\r\n// Load invoice data\r\n// ...\r\n// ...\r\n// Set the third party context instead of standard context object\r\nInvoice result = invoice.create(thirdPartyContext);\r\n```\r\n\r\n## Checklist\r\n- [ ] Update README with newer integration steps\r\n- [x] Enable Refresh Token to be passed into apiContext. (For better third party handling)\r\n- [ ] [Optional] Builder pattern for APIContext\r\n- [ ] [Optional] Add more configurations. E.g. `setHTTPTimeout`, etc.\r\n\r\n## Changes\r\n- Added constructors for APIContext\r\n- Removed BaseAPIContext class and merged it with APIContext\r\n- Enabled setting refresh token inside APIContext/OAuthTokenCredential","created_at":"2016-06-16T22:36:45Z","updated_at":"2016-06-22T22:34:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0397ad6f9f888241133e1b39c6cba2d481a1e616","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191/commits","review_comments_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191/comments","review_comment_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/191/comments","statuses_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/statuses/3c85f96b1a56594d6021d25fa80a935f3f3aefd3","head":{"label":"paypal:apiContext","ref":"apiContext","sha":"3c85f96b1a56594d6021d25fa80a935f3f3aefd3","user":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"repo":{"id":8595333,"name":"PayPal-Java-SDK","full_name":"paypal/PayPal-Java-SDK","owner":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paypal/PayPal-Java-SDK","description":"Java SDK for PayPal RESTful APIs","fork":false,"url":"https://api.github.com/repos/paypal/PayPal-Java-SDK","forks_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/forks","keys_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/teams","hooks_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/hooks","issue_events_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/events{/number}","events_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/events","assignees_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/assignees{/user}","branches_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/branches{/branch}","tags_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/tags","blobs_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/refs{/sha}","trees_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/statuses/{sha}","languages_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/languages","stargazers_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/stargazers","contributors_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/contributors","subscribers_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/subscribers","subscription_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/subscription","commits_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/commits{/sha}","git_commits_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/commits{/sha}","comments_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/comments{/number}","issue_comment_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/comments{/number}","contents_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/contents/{+path}","compare_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/merges","archive_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/downloads","issues_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues{/number}","pulls_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls{/number}","milestones_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/milestones{/number}","notifications_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/labels{/name}","releases_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/releases{/id}","deployments_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/deployments","created_at":"2013-03-06T03:47:44Z","updated_at":"2016-06-22T10:35:25Z","pushed_at":"2016-06-22T21:43:23Z","git_url":"git://github.com/paypal/PayPal-Java-SDK.git","ssh_url":"git@github.com:paypal/PayPal-Java-SDK.git","clone_url":"https://github.com/paypal/PayPal-Java-SDK.git","svn_url":"https://github.com/paypal/PayPal-Java-SDK","homepage":"","size":1795,"stargazers_count":200,"watchers_count":200,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":243,"mirror_url":null,"open_issues_count":8,"forks":243,"open_issues":8,"watchers":200,"default_branch":"master"}},"base":{"label":"paypal:master","ref":"master","sha":"4c4747e6efa29c98b24b0971ba84fcb3f4d797e7","user":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"repo":{"id":8595333,"name":"PayPal-Java-SDK","full_name":"paypal/PayPal-Java-SDK","owner":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paypal/PayPal-Java-SDK","description":"Java SDK for PayPal RESTful APIs","fork":false,"url":"https://api.github.com/repos/paypal/PayPal-Java-SDK","forks_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/forks","keys_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/teams","hooks_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/hooks","issue_events_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/events{/number}","events_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/events","assignees_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/assignees{/user}","branches_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/branches{/branch}","tags_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/tags","blobs_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/refs{/sha}","trees_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/statuses/{sha}","languages_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/languages","stargazers_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/stargazers","contributors_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/contributors","subscribers_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/subscribers","subscription_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/subscription","commits_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/commits{/sha}","git_commits_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/git/commits{/sha}","comments_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/comments{/number}","issue_comment_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/comments{/number}","contents_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/contents/{+path}","compare_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/merges","archive_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/downloads","issues_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues{/number}","pulls_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls{/number}","milestones_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/milestones{/number}","notifications_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/labels{/name}","releases_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/releases{/id}","deployments_url":"https://api.github.com/repos/paypal/PayPal-Java-SDK/deployments","created_at":"2013-03-06T03:47:44Z","updated_at":"2016-06-22T10:35:25Z","pushed_at":"2016-06-22T21:43:23Z","git_url":"git://github.com/paypal/PayPal-Java-SDK.git","ssh_url":"git@github.com:paypal/PayPal-Java-SDK.git","clone_url":"https://github.com/paypal/PayPal-Java-SDK.git","svn_url":"https://github.com/paypal/PayPal-Java-SDK","homepage":"","size":1795,"stargazers_count":200,"watchers_count":200,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":243,"mirror_url":null,"open_issues_count":8,"forks":243,"open_issues":8,"watchers":200,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191"},"html":{"href":"https://github.com/paypal/PayPal-Java-SDK/pull/191"},"issue":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/191"},"comments":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/issues/191/comments"},"review_comments":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191/comments"},"review_comment":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/pulls/191/commits"},"statuses":{"href":"https://api.github.com/repos/paypal/PayPal-Java-SDK/statuses/3c85f96b1a56594d6021d25fa80a935f3f3aefd3"}}}}
{"actor":{"display_login":"braebot"}}