This boilerplate provides a starting point for integrating payment gateways with the Fynd Platform, enabling merchants to process payments seamlessly. The integration facilitates the installation and activation of payment extensions, allowing for a smooth transaction process for both merchants and customers.
Relation of Extensions with Fynd Platform.
| π Fynd Platform | π€ Fynd Partners | π Documentation |
Before setting up the extension, make sure you have the following installed:
- Node.js : >= v16.x.x
This guide provides a step-by-step process for building and setting up a payment extension, with two main approaches depending on your preferred technology stack.
- Approach to Building Your Payment Extension
- Setting Up in the Fynd Partners Panel
- How It Works
- Security and Best Practices
For those using Node and React, a pre-implemented template is available, which includes:
- OAuth support for authentication
- Required endpoints for processing requests
- Frontend code for collecting payment gateway credentials from merchants
- Register on the Fynd Partners Panel.
- After registration, you can join an existing Partner Organization or create a new one.
- Once you're part of an organization, navigate to Extension > Create Extension.
- Choose Start from scratch, select Extension Type as Payments, fill in the required details, and click Create Extension.
- Go to Sales Channel > Settings > Cart & Payments > Payments > General Settings > Payment Options > Add Payment Gateway.
- Find your new extension under Add Payment Gateway, select it, and install it.
- In the Payment Options section, click on your extension.
- Configure the extension for web, iOS, or Android as per your requirements.
- Click the three dots in the top-right corner (near the save button) and select Credentials from the dropdown.
- The extension UI will appear, allowing you to input the necessary credentials.
- Fill in the required credentials.
- After the extension is set up successfully, the payment settings page will display it as inactive.
- Click on your extension.
- Activate the payment mode for your preferred device.
- π Your payment extension is now fully configured and ready for use! π
Merchants can easily install and activate the payment extension on their Fynd Platform. During checkout, customers will see the payment options provided by the extension. Currently, the Fynd Platform supports a standard checkout flow where customers are redirected to the payment gateway's hosted page to complete their transactions.
- Verifying API Calls: Use checksums generated with your Extension API Secret to secure communications between the Fynd Platform and your payment extension.
- Idempotency: Ensure your extension supports idempotency to prevent duplicate transactions and provide a consistent experience for buyers.
For more detailed examples and additional languages, refer to the provided guides.
You have successfully set up your payment extension on the Fynd platform.
-
π Use Git to clone the repository to your local machine and navigate into the project directory.
git clone https://github.com/gofynd/payment-extension-boilerplate.git
-
π¦ Install Backend Dependencies.
Ensure you have Node.js (v16.x.x or above) installed.
npm install
-
π¦ Install Frontend Dependencies.
cd web npm install -
π§ Create build of frontend React project.
npm run build
-
π οΈ Configure Environment Variables.
Open the
app/config.jsfile in your project directory. Update theEXTENSION_API_KEYandEXTENSION_API_SECRETenvironment variables inapi_keyandapi_secretwith the values obtained from the Partners Panel. These should be set as the default values for theconfigvariables.This table includes the top-level keys and their subkeys, along with their properties, descriptions, formats, default values, environment variables.
| Field | Documentation | Format | Default Value | Environment Variable |
|---|---|---|---|---|
| enable_cors | cors toggle | Boolean | true | ENABLE_CORS |
| env | node env | String | development | NODE_ENV |
| environment | env | String | fynd | ENV |
| sentry.dsn | sentry url | String | <sentry_url> | SENTRY_DSN |
| sentry.environment | sentry environment | String | development | SENTRY_ENVIRONMENT |
| newrelic.app_name | new relic app name | String | mock | NEW_RELIC_APP_NAME |
| newrelic.license_key | new relic license key | String | <newrelic_license_key> | NEW_RELIC_LICENSE_KEY |
| port | The port to bind | port | 5050 | PORT |
| log_level | log level for logger | String | info | LOG_LEVEL |
| mode | app mode | String | server | MODE |
| API_KEY | Partners API Key | String | <api_key> | API_KEY |
| API_SECRET | Partners API Secret | String | <api_secret> | API_SECRET |
api_key: {
doc: 'extension api key',
default: 'Your API Key',
env: 'EXTENSION_API_KEY',
},
api_secret: {
doc: 'extension api secret',
default: 'Your API Secret',
env: 'EXTENSION_API_SECRET',
},-
π Secure Tunnel Setup.
Install ngrok or a similar cross-platform application to create secure tunnels, enabling your locally hosted web server to be accessible over the internet.
-
π Launch ngrok to forward the port used by your local server.
ngrok http 3000
Replace
3000with the actual port number your server is using. This will generate a public URL that securely tunnels to your local server. -
π Update default env value for
EXTENSION_BASE_URLwith this URL.
base_url: {
doc: 'Host Main URL',
format: String,
default: 'https://your-ngrok-url',
env: 'MOCK_MAIN_DOMAIN',
arg: 'mock_main_domain',
},-
π οΈ Navigate to your extension in the Partner Panel and update the Extension URL field with the generated ngrok URL.
-
π» Run local server.
npm start
-
π You are ready to go.
After you have completed the local setup, you can run the test cases to ensure everything is working as expected. Follow these steps to execute the tests:
-
π Navigate to the Project Directory.
If you're not already there, switch to your project's root directory in your terminal.
cd path/to/your/project -
π§ͺ Run Backend Tests.
Execute the backend test cases using the following command:
npm test
- π Register on our Platform panel.
- π₯ After registration, either join an existing Platform Organization or create a new one.
- π’ Upon registration completion, find your organization's ID in the URL, such as
https://platform.fynd.com/company/:company-id/home/. - π For a private extension, navigate to Extension > Private Extension. Private extensions are recommended for development purposes.
- π For a public extension, navigate to Extension > Extension Marketplace.
- π Locate your extension in the list and click the
Installbutton. - π₯ For private extensions, add the company ID as a subscriber for the extension in the Partner's Panel. Navigate to your extension in the Partner's Panel, click on the
Add Subscribersbutton, enter yourcompany-idin theSubscriber Idfield, and clickAdd Subscriber. - π After installation, your extension will be listed under your organization's extensions.
- π Click on your extension to open it.
- π Your changes from local development will be reflected here.
This project enforces code quality and consistency using ESLint and Prettier. Please ensure you've addressed any linting errors and test failures before pushing your commits.
Merchants can easily install and activate the payment extension on their Fynd Platform. During checkout, customers will be presented with the payment options provided by the extension. Currently, the Fynd Platform supports standard checkout, where customers are redirected to the payment gateway's hosted page to complete their transactions.