Example Workflow Execution

Script to give visibility into an example workflow integration

alfred Transaction

Description

This Node.js script is used to interact with a third-party API. It performs several operations such as initiating a transaction, logging in, uploading documents, verifying the phone, and sending a transaction.

Configuration

The script uses environment variables to configure various aspects of its operation. These variables can be set in a .env file in the root directory of the project.

URL=https://api-dev-services.alfredpay.app/api/v1
API_KEY=your_api_key
API_SECRET=your_api_secret
COUNTRY_WITHDRAWAL=MEX
BUSINESS_TO=your_business_to
METHOD_WITHDRAWAL=BANK
TYPE=your_type
ID_CARD_FRONT_PATH=path_to_id_card_front
ID_CARD_BACK_PATH=path_to_id_card_back
SELFIE_PATH=path_to_selfie
DRIVER_DOC_FRONT_PATH=path_to_driver_doc_front
DRIVER_DOC_BACK_PATH=path_to_driver_doc_back

Functions

getHeaders(token)

Generates and returns the necessary headers for requests to the API.

makeRequest(method, url, body, token)

Makes a request to the API with the provided method, URL, body, and token.

getInitTransaction()

Initiates a transaction with the API and returns the transaction ID.

loginSofKyc(initialTransaction)

Logs in to the API using the provided initial transaction.

uploadDocument(token, docPath, docType)

Uploads a document to the API using the provided token, document path, and document type.

paymentMethod(initTransaction)

Sets the payment method using the provided initial transaction.

verificationPhone()

Verifies the phone number with the API.

submitTransaction(initTransaction, exchangeFactor)

Submits a transaction to the API using the provided initial transaction and exchange factor.

updateBankUser()

Updates the user's bank information in the API.

updateInvoice(invoice)

Updates the status of the invoice in the API. The invoice status can only be changed to 'approved'.

getInvoice(invoice)

Gets the invoice information from the API.

main()

Main function that coordinates all the above operations.

Usage

To run the script, first install the dependencies with npm install and then run the script with node script.js.

Dependencies

  • dotenv: To load environment variables from a .env file

  • axios: To make HTTP requests.

  • fs: To read files from the file system.

  • form-data: To create multipart/form-data forms.

Package.Json

Index.js


Download Example Script zip here:

5KB
Open

Last updated