Skip to main content

Boilerplate Overview

A Boilerplate is a pre-written codebase that speeds development by providing a foundational template for building extensions. Fynd provides a boilerplate that simplifies the development process. This template includes pre-implemented OAuth functionality, necessary API endpoints, and a frontend interface where sellers can enter PG credentials. It is an enhanced version of the General Extension boilerplate with additional configuration to support payment-specific features. Developers should first familiarize themselves with the General Extension boilerplate before working on the Payments boilerplate.

Prerequisite

Download the Payments Boilerplate code from Here.

├── .github
├── .husky
├── app
│ ├── __tests__
│ │ └── aggregator.spec.js
│ │ ├── creds.spec.js
│ │ ├── encrypt.spec.js
│ │ ├── processor.spec.js
│ │ └── signature.spec.js
│ │
│ ├── common
│ │ ├── mongo.init.js
│ │ ├── newrelic.init.js
│ │ └── sentry.init.js
│ │
│ ├── controllers
│ │ ├── credsController.js //Credentials and StatusMapper API controllers
│ │ └── orderController.js //order and payments related API controllers
│ │
│ ├── fdk
│ │ ├── index.js
│ │ └── mongoStorage.js
│ │
│ ├── middleware
│ │ ├── errorHandler.js //error handler middleware that take care to print error.
│ │ └── verifyChecksum.js //checksum middle logic you can implement in this
│ │
│ ├── models
│ │ └── models.js //manage Database schema definations
│ │
│ ├── routes
│ │ ├── creds.router.js //URL manager for credentials and statusMapper APIs
│ │ └── order.router.js //URL manager for Order/payment APIs
│ │
│ ├── services
│ │ ├── aggregators
│ │ │ ├── aggregator.js // Main PG logic file.
│ │ │ └── config.js //Base file that have abstract methods that are required to implemented
│ │ └── processor.js //Contains implementation of database operations. Order API's request and responses pass through this file.
│ │
│ ├── utils
│ │ ├── encryptUtils.js
│ │ ├── errorUtils.js
│ │ └── signatureUtils.js
│ │
│ ├── views
│ │ └── redirector.html
│ │
│ ├── config.js
│ └── server.js

├── frontend
├── .env.example
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .prettierrc
├── Babel.config.js
├── LICENSE
├── README.md
├── coverage_output.js
├── index.js
├── jest.config.js
├── jsconfig.json
├── newrelic.js
├── package-lock.json
└── package.json

The files described below are specific to the Payments Extension. Since the Payments Extension boilerplate is built on the General Extension boilerplate, commonly shared files from the General Extension Boilerplate are not included in the list below.

Go through the General Extension boilerplate for foundational understanding.

The file naming and structure in the boilerplate primarily follow Fynd’s standard conventions. However, some files adhere to custom conventions that are not documented. The boilerplate files are divided into the following categories:

app/tests

It contains unit test files to validate the core functionalities of the payment extension.

  • aggregator.spec.js: Tests the aggregator logic, ensuring proper handling of payment aggregator-related operations.
  • creds.spec.js: Validates credential management, ensuring secure handling of API keys and authentication data.
  • encrypt.spec.js: Tests encryption utilities to verify secure data encoding and decoding.
  • processor.spec.js: Checks the payment processing logic to ensure transactions are handled correctly.
  • signature.spec.js: Verifies the signature generation and validation process for secure communication.

app/utils

It contains various utility modules that provide helper functions to support the main payment processing logic. Here’s an overview of each component:

  • encryptUtils.js: It provides functions for encryption, decryption, or hashing operations.
  • errorUtils.js: It contains utility functions related to error handling.
  • signatureUtils.js: It contains functions related to generating and verifying digital signatures.

app/services

  • processor.js: It is responsible for handling all database operations related to payment processing. It is an intermediary between the application’s order APIs and the database.
  • aggregators/aggregator.js: It contains the main logic for integrating with Payment Gateways (PG).
  • aggregators/config.js: It contains settings and parameters specific to the payment aggregators.

app/views/redirector.html

It redirects users to a specified URL after a payment transaction.

app/middleware

It helps in building a secure and reliable payment extension by addressing error handling and data integrity concerns effectively.

  • errorHandler.js: It manages errors that occur during the request-response cycle.
  • verifyChecksum.js: It verifies the integrity and authenticity of incoming requests by checking their checksums.

app/models/model.js

This file manages database schema definitions and serves as the central place to define and organize the data models used throughout the application.

app/routes

These files collectively define the routing logic for various functionalities within the payment extension, ensuring organized and efficient API endpoint management. The app/routes directory contains two files:

  • creds.router.js: Manages routes related to credentials and status mapper APIs.
  • order.router.js: Manages routes for order and payment APIs, facilitating payment processing.

app/common

  • mongo.init.js: Typically used to initialize MongoDB databases.
  • newrelic.js: Integrates the New Relic monitoring service to track application performance and gather metrics.
  • sentry.js: Configures Sentry for error tracking and monitoring.

app/controllers

These controllers facilitate the application’s core functionalities by processing incoming API requests, interacting with services or models, and returning appropriate responses. This directory contains the following files:

  • creds.controller.js: Manages operations related to credentials and status mapping, handling API requests for credential management and status updates.
  • order.controller.js: Oversees order and payment processing, managing API requests related to order creation, payment initiation, and status tracking.

app/fdk

These files help integrate the payment extension with Fynd’s ecosystem while maintaining structured data storage. Contains two files:

  • index.js: This is an entry point for integrating the Fynd Development Kit (FDK) with the payment extension. It facilitates communication between the extension and the Fynd Commerce.
  • mongoStorage.js: This file manages MongoDB-based storage for the FDK.

config.js

It defines environment settings, server details, database connections, payment gateway credentials, and logging preferences.

server.js

It sets up the Express.js application, configuring middleware for cookie parsing, JSON body parsing, and serving static files. It integrates the FDK extension handler and defines routing for order processing and credential management APIs.


Was this section helpful?