Typescript
Our API is RESTful and responds in JSON. Gerencianet uses OAuth to provide authorized access to the API. Our NodeJS SDK is already prepared to perform this authentication automatically.
Below, check out the procedures for installing the Gerencianet SDK in Typescript:
Installing via NPM
$ npm install gn-api-sdk-typescript
Tested with
- Version
4.2.4
Baisc use
Import the module:
import Gerencianet from 'gn-api-sdk-typescript';
Enter your credentials and define whether you want to use the sandbox or not. You can also use the file examples/config.ts as model.
- TypsScript
export = {
// PRODUÇÃO = false
// HOMOLOGAÇÃO = true
sandbox: false,
client_id: 'ClientId',
client_secret: 'ClientSecret',
pix_cert: 'pathtoyourPixcertificate',
};
Instantiate the module passing your options:
- TypsScript
const gerencianet = Gerencianet(options);
Create the charge (transaction):
- TypsScript
var body = {
items: [{
name: 'Product A',
value: 1000,
amount: 2
}]
}
gerencianet
.createCharge({}, body)
.then((resposta: any) => {
console.log(resposta);
})
.catch((error: any) => {
console.log(error);
})
.done();
Examples
To run the examples, clone this repository and install the dependencies:
$ git clone git@github.com:gerencianet/gn-api-sdk-typescript.git
$ cd gn-api-sdk-typescript/examples
$ npm install
Set your oauth keys in the config.ts
file:
export = {
// PRODUÇÃO = false
// HOMOLOGAÇÃO = true
sandbox: false,
client_id: 'ClientId',
client_secret: 'ClientSecret',
pix_cert: 'pathtoyourPixcertificate',
};
Then run the desired example:
$ ts-node createCharge.ts
Tests
To run the test suite, first install the dependencies and then run the npm test:
$ cd gn-api-sdk-node/
$ npm install
$ npm test