Code Monkey home page Code Monkey logo

payhere-with-netlify-functions's Introduction

Payhere Payment Gateway with Netlify Functions & Fauna DB

Netlify Status

A Node.js app to integrate Payhere.lk payment gateway using Netlify Functions & Fauna DB.

๐Ÿš€ Getting started

  1. Clone the repo & run npm install to install the dependencies.
  2. Setup the Fauna DB connection & create the collection & index.
  3. Add Environment Variables to .env file.

๐Ÿ‘จโ€๐Ÿ’ป Development Environment

To ensure the seamless functioning of the entire funnel, follow these steps:

  • Execute both netlify dev and set up ngrok to examine the complete process. This is necessary as Payhere requires a public-facing URL for the notify_url.
  • If the repository is already linked to a Netlify site, simply run netlify dev --live without the need for ngrok. You can use netlify link to connect the repository and the Netlify site efficiently.

Fauna DB

  • Create a Database in US Region Group.
  • Go to the Database > Security > Create a secret key with the server role.
  • Add the key to the .env file as FAUNA_SECRET_KEY
  • Run below to create the collection payhere-demo-orders & index orders_by_order_id
    node faunadb/faunaSetup.js

Environment Variables

  • Generate .env file from .env.example and add your env variables.
    cp .env.example .env
  • If new keys are added to the .env file, run below command to update the example file with new keys.
    sed 's/=.*/=/' .env > .env.example

FAQ

1. Why Netlify Functions?

  • ๐Ÿ” Security: The Payhere Merchant Secret is required for generating the hash. Performing this operation on the front-end poses security risks. Netlify Functions act as a secure backend for handling the hash generation process.
  • ๐Ÿ“ก Server Callback: Netlify Functions listen to payment notifications from PayHere, facilitating the passing of relevant information to the front-end.

2. Why Fauna DB?

  • ๐Ÿฆ Payment Status Handling: Since PayHere doesn't provide payment status parameters to the return_url during customer redirection, updating the database upon fetching payment status via your notify_url script is crucial.
  • ๐Ÿข Modern Database Solution: Fauna DB is a cloud-native database with a flexible document data model. It seamlessly integrates semi-structured data with powerful relational features, including foreign keys, views, and joins.
  • ๐Ÿ” Efficient Data Retrieval: Integration with Fauna DB allows you to efficiently retrieve payment status & display to customers on the return_url page.

payhere-with-netlify-functions's People

Contributors

prabapro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.