Skip to main content

TypeScript

Learn how to install and configure our TypeScript SDK to use Efí's APIs

Attention!

Requests made to Efí's APIs using the TypeScript SDK require the certificate generated in your Efí account in the .p12 format.


Installation via NPM

npm install sdk-typescript-apis-efi

Installation via Git

Our SDK is also available in our Efí Github repository.

$ git clone https://github.com/efipay/sdk-typescript-apis-efi.git

Tested with

Version 4.2.4


Basic Usage

Import the module:

import EfiPay from 'sdk-typescript-apis-efi';

Enter your credentials and define whether you want to use the sandbox or not.
export = {
// PRODUCTION = false
// SANDBOX = true
sandbox: false,
client_id: 'seuClientId',
client_secret: 'seuClientSecret',
pix_cert: 'caminhoAteOCertificadoPix',
};

Instantiate the module by passing its options:
const efipay = EfiPay(options);

Create the charge (transaction):
var body = {
items: [
{
name: 'Product A',
value: 1000,
amount: 2,
},
],
};

efipay
.createCharge({}, body)
.then((resposta: any) => {
console.log(resposta);
})
.catch((error: Promise<any>) => {
console.log(error);
})
.done();

Examples

To run the examples, clone this repository and install the dependencies:

$ git clone [email protected]:efipay/sdk-typescript-apis-efi.git
$ cd sdk-typescript-apis-efi/examples
$ npm install

Define your oauth keys in the config.ts file:

module.exports = {
// PRODUCTION = false
// SANDBOX = true
sandbox: false,
client_id: 'seuClientId',
client_secret: 'seuClientSecret',
pix_cert: 'caminhoAteOCertificadoPix',
};

Then run the desired example:

$ ts-node createCharge.ts