TypeScript
Learn how to install and configure our TypeScript SDK to use Efí's APIs
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
- Efí Pay
npm install sdk-typescript-apis-efi
Installation via Git
Our SDK is also available in our Efí Github repository.
- Efí Pay
$ git clone https://github.com/efipay/sdk-typescript-apis-efi.git
Tested with
Version 4.2.4
Basic Usage
Import the module:
- Efí Pay
import EfiPay from 'sdk-typescript-apis-efi';
Enter your credentials and define whether you want to use the sandbox or not.
- TypeScript
export = {
// PRODUCTION = false
// SANDBOX = true
sandbox: false,
client_id: 'seuClientId',
client_secret: 'seuClientSecret',
pix_cert: 'caminhoAteOCertificadoPix',
};
Instantiate the module by passing its options:
- Efí Pay
const efipay = EfiPay(options);
Create the charge (transaction):
- Efí Pay
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:
- Efí Pay
$ 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