# Ninjapay Plugin Development Guide

## Introduction

Welcome to the Ninjapay Plugin Development Guide! This guide aims to provide all the necessary information for developers to create, test, and deploy plugins for the Ninjapay platform. Ninjapay plugins allow you to extend the functionality of the Ninjapay system, offering custom features and integrations to enhance user experience.

## Getting Started

Before you dive into plugin development, there are a few prerequisites:

* **Familiarity with Node.js**: Since Ninjapay is built on Node.js, a good grasp of Node.js and JavaScript is essential.
* **Development Environment**: Ensure Node.js is installed on your development machine.
* **Ninjapay Setup**: Clone a version of Ninjapay example plugin project for building your plugin.
* **Database Knowledge**: Understanding of basic database operations and SQL, as your plugin might need to interact with the Ninjapay database.

## Plugin Structure

A standard Ninjapay plugin should follow a specific structure for consistency and compatibility:

* `migrations.js`: Contains all database migration files for setting up and tearing down database tables specific to your plugin.
* `index.js`: The main entry point of your plugin. This is where you define your plugin's logic, routes, and middleware.
* `requirements.txt`: Describes your plugin's metadata, dependencies, scripts, etc.
* `README.md`: Documentation for your plugin, explaining its features, installation process, and any other necessary information for users and developers.

### Step 1: Setting Up Your Plugin Project

1. **Fork the Example Project:** Start by forking the [Ninjapay example plugin project](https://github.com/) on GitHub. This project serves as a template and demonstrates how to structure your plugin and interact with the Ninjapay app.
2. **Clone Your Forked Repository:** Clone the forked repository to your local machine to begin development.

   ```bash
   git clone <https://github.com/yourusername/your-forked-repo.git>
   ```
3. **Or Create a New Directory** for your plugin and initialize a new Node.js project:

   ```bash
   mkdir my-ninjapay-plugin
   cd my-ninjapay-plugin
   npm init -y
   ```
4. **Set Up the Plugin Structure** as described above if needed. Create the necessary directories and files.

### Step 2: Developing Your Plugin

* **Understand the Plugin Structure:** Familiarize yourself with the structure of the example project. Your plugin should include:
* **Only Use the Ninjapay Other Plugin APIs:** Integrate the existing Ninjapay Plugin APIs to allow your own plugin to communicate within the Ninjapay app. Refer to the Ninjapay "P2P Payment Link Plugin" API documentation for details on available APIs and how to use them.
* **Implement Database Operations:** Use the provided DB helper class to perform database operations such as creating tables, inserting data, and deleting tables upon uninstallation. Your plugin's database schema should be defined in a separate file, checkout `migrations.js` in the example project.

1. **Implement Your Plugin Logic** in `index.js`. This includes defining routes, middleware, and other functionalities your plugin offers.
2. **Use Core API’s Only,** mainly P2P Payment Links Plugin Api’s. This includes creating, linking of payment link url’s into your own plugin flow.
3. **Use the DB Helper Class** for database interactions. Create migration scripts in the `migrations.js` to define how your plugin's database tables are created and removed.
4. **Follow Best Practices** in coding, such as keeping your code clean, commenting where necessary, and adhering to security practices.&#x20;
5. **API Public Endpoints:** Define RESTful API endpoints of your new plugin, that Ninjapay app users/developers can interact with it programmatically.

**Adding new dependencies**

DO NOT ADD NEW DEPENDENCIES. Try to use the dependencies that are available in `requirements.txt` of the example project. Getting the Ninjapay project to accept a new dependency is time consuming and uncertain, and may result in your extension NOT being made available to others.

If for some reason your plugins must have a new npm package to work, and its needs are not met in `requirements.txt`, you can add a new package using `npm`:

```
$ npm install [package-name]@[version-number]
```

**But we need an extra step to make sure Ninjapay doesn't break in production.** Dependencies need to be added to `requirements.txt`, then tested by running on `npm` compatibility, can be tested with `nix build .#checks.x86_64-linux.vmTest`.

### Step 3: Testing Your Plugin

1. **Test Locally** by integrating your plugin with a local instance of Ninjapay. Ensure all functionalities work as expected and that there are no conflicts with the main application.
2. **Write Unit and Integration Tests** to automate the testing process. This helps in identifying issues early in the development process.

### Step 4: Documenting Your Plugin

1. **Write Comprehensive Documentation** in your `README.md`. Include installation instructions, features, usage examples, and any other relevant information.
2. **Document API Endpoints** if your plugin exposes any APIs. Provide details on request and response formats, HTTP methods, and endpoint URLs.

### Step 5: Publishing Your Plugin

1. **Version Your Plugin** using semantic versioning. This helps users understand the compatibility and changes in each release.
2. **Host Your Plugin on GitHub** or another source control platform. This makes it accessible to other developers and users.
3. **Submit Your Plugin to Ninjapay** for review. Provide a link to your plugin's repository. Once approved, your plugin will be listed in the Ninjapay plugin directory.

#### Conclusion

Developing plugins for Ninjapay allows you to contribute to the ecosystem and provide valuable features to users. Follow this guide to ensure your plugin development process is smooth and meets the standards required for integration with Ninjapay. We look forward to seeing the innovative solutions our developer community will bring to Ninjapay.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ninjapay.gitbook.io/ninjapay-api-docs/how-to/api-reference-upi/plugins/build-your-own-plugin/ninjapay-plugin-development-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
