NodeJS
Learn how to install and configure our Node.js SDK to use Efí APIs
Requests made to Efí APIs using the Node.js SDK require the certificate generated in your Efí account in .p12 format.
Installation via NPM
- Efí Pay
npm install sdk-node-apis-efi
Installation via Git
Our SDK is also available in our repository on the Efí Github.
- Efí Pay
$ git clone https://github.com/efipay/sdk-node-apis-efi.git
Tested with
Node 0.12.7
, 4.4.0
e 4.4.4
Basic Usage
Reference the module:
- Efí Pay
const EfiPay = require('sdk-node-apis-efi')
Define your credentials and whether you want to use sandbox or not:
- NodeJS
module.exports = {
// PRODUCTION = false
// SANDBOX = true
sandbox: false,
client_id: 'seuClientId',
client_secret: 'seuClientSecret',
certificate: 'caminho/Ate/O/Certificado/Pix',
}
Instantiate the module passing your options:
- Efí Pay
const efipay = new EfiPay(options)
Create the charge (transaction):
- Efí Pay
let chargeInput = {
items: [
{
name: 'Product A',
value: 1000,
amount: 2,
},
],
}
efipay.createCharge({}, chargeInput)
.then((resposta) => {
console.log(resposta)
})
.catch((error) => {
console.log(error)
})
Examples
To run the examples, clone this repository and install the dependencies:
- Efí Pay
$ git clone [email protected]:efipay/sdk-node-apis-efi.git
$ cd sdk-node-apis-efi/examples
$ npm install
Define your OAuth keys in the credentials.js
file:
module.exports = {
// PRODUCTION = false
// SANDBOX = true
sandbox: false,
client_id: 'seuClientId',
client_secret: 'seuClientSecret',
pix_cert: 'caminhoAteOCertificadoPix',
};
Then run the desired example:
$ node createCharge.js