diff --git a/README.md b/README.md index 7b6c64d..17860bb 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,14 @@ gp.getTokens(); } ``` +### getAccessToken() + +```ts +gp.getAccessToken(); +``` + +Returns only `access_token` for necessary Authorization + ## 🙅🏿‍♂️ Used OSS - Chalk diff --git a/package.json b/package.json index d338935..c602067 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/factory/goPay.ts b/src/factory/goPay.ts index 45d4d32..7202f35 100644 --- a/src/factory/goPay.ts +++ b/src/factory/goPay.ts @@ -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; + } + }