Skip to content

Commit

Permalink
feat: getAccessToken() method
Browse files Browse the repository at this point in the history
  • Loading branch information
0ndras3k committed Jan 19, 2022
1 parent 6ac5f4a commit 2498560
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ gp.getTokens();
}
```

### getAccessToken()

```ts
gp.getAccessToken();
```

Returns only `access_token` for necessary Authorization

## 🙅🏿‍♂️ Used OSS

- Chalk
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fronebdev/gopay-js",
"version": "1.0.3",
"version": "1.0.4",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": {
Expand Down
24 changes: 24 additions & 0 deletions src/factory/goPay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,28 @@ export class goPay {

return res.data;
}

async getAccessToken() {
const params = new URLSearchParams();
params.append("grant_type", "client_credentials");
params.append("scope", "payment-create");

const res = await axios({
url: this.url + "/oauth2/token",
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
Authorization:
"Basic " +
new Buffer(
this.credentials.clientID + ":" + this.credentials.clientSecret
).toString("base64"),
},
data: params,
});

return res.data.access_token;
}

}

0 comments on commit 2498560

Please sign in to comment.