Skip to content

Version of Efi node SDK to run on AWS Lambda using Serverless platform

Notifications You must be signed in to change notification settings

coutoluizf/sdk-node-apis-efi-lambda

 
 

Repository files navigation

sdk-node-apis-efi-lambda - Fork of the Efí SDK Node.js, with less boilarplate, and to execute on AWS Lambda using serverless platform

This is not a SDK, it is a full example of how to call Efi Payment API

Stack

axios implementation (inspired by Efí SDK node.js lib )

aws lambda

aws s3 (to store the file certificate)

serverless platform to handle and upload the aws lambda

lambda-api lib to create a small node api under the aws lambda using the event proxy

Config

In serverless.yml Change YOUR_BUCKET to you AWS S3 Bucket Name:

  • "arn:aws:s3:::YOUR_BUCKET/*"

Add your Efi credencials change certificate-name.p12 by your certificate name

//  On efiServices.js change the following parameters:
const options = {
    sandbox: false,
    client_id: 'your_Client_Id',
    client_secret: 'your_Client_Secret',
    certificate: '/tmp/certificate-name.p12', // put your certificate name here
}

// TODO: add your AWS credencials
AWS.config.update({
    "accessKeyId": "XYXYXYXYXYXYXYXYX",
    "secretAccessKey": "XXXXXXXXXXXXXXXXXXXXXXX"
})

// don't forget to add the file cert on your own bucket
const fileName = 'YOUR_FILE_CERTIFICATE_NAME_ON_AWS_S3_BUCKET' // TODO: CHANGE HERE

let params = {
    Bucket: 'YOUR_BUCKET_SAME_NAME_IN_serverless.yml', // TODO: CHANGE HERE
    Key:    fileName
}

The rest of the efiServices.js file is the normal api flow, like create a Pix charge with amount, expiration and so one.

Deploy with Serverless platform

# dev
$ sls deploy
# tail logs
$ sls logs -f service -t

# prod
$ sls deploy --stage prod --region us-east-1
# tail logs
$ sls logs -f service -t --stage prod --region us-east-1

Simple test

Get the url returned by serverless / aws lambda Example: https://xyxyxyxyxy.execute-api.us-east-1.amazonaws.com/prod/

# Add lambda api context (located on handler) and the api path (rest api using lambda-api), here "billing" is the context name, full example:
https://xyxyxyxyxy.execute-api.us-east-1.amazonaws.com/prod/billing/efi

Full Efí Docs

https://dev.sejaefi.com.br/.

About

Version of Efi node SDK to run on AWS Lambda using Serverless platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%