Coder Social home page Coder Social logo

nanosales's Introduction

Nano Sales - Payment Gateway Helper

WARNING: this project requires yarn sudo npm install -g yarn

This payment gateway helper is configured with three files:

wallet.seed is this server's private key, it is used to generate addresses for the address pool and to sign transactions for settling. If file is not provided it will generate a random seed at startup.

settle.pub is the shop's settlement address, it is where this server will send the collected funds when addresses are released. If one is not provided the server will refuse to start.

config.json is a file with the follwing structure:

{
    "minPoolAddresses": 5, //minimum number of addresses to be generated by the pool
    "nodeWs": "wss://yournode",
    "nodeRpc": "http://yournode",
    "workRpc": "http://workserver" // OPTIONAL work server url
}

Three simple http endpoints:

POST /sales

This endpoint creates/allocates an address for the payment, registering a callback url and a desired amount.

The shop receives back the address.

Once any block is confirmed for that address the callback is called via GET, no payload.

Input:

{
    "callback": "my.shop/update-payment/123", // unique url for updating a payment status
    "amount": 1e+30 // amount in RAW (1 nano) same as 1000000000000000000000000000000
}

Output:

{
    "url": "nano:nano_3oneTimeDepositAddressToDisplayAtTheCheckoutPage111111111111?amount=1000000000000000000000000000000",
    "address": "nano_3oneTimeDepositAddressToDisplayAtTheCheckoutPage111111111111"
}

or in case the url has already been used and paid for:

{
    "paid": true
}

GET /sales/nano_3oneTimeDepositAddressToDisplayAtTheCheckoutPage111111111111

This endpoint informs the shop about the payment status, it is meant to be called right after the shop receives a callback. Meaning the shop must store the address for that order on their side.

Output:

{
    "paid": false, // boolean that indicates if paid amount is greater or equal than requested amount
    "price": 1000000000000000000000000000000,
    "balance": 990000000000000000000000000000
}

DELETE /sales/nano_3oneTimeDepositAddressToDisplayAtTheCheckoutPage111111111111

Once payment is confirmed on the shop it can release the address and settle the balance on their main address. It is recommended that uppon settlement the address is removed from the shop's order information to avoid mix ups. Each settlement is recorded in a separate json file in data/settlements, the filename being the md5sum of the shop callback url to avoid double pay.

BUILDING

yarn install yarn build

RUNNING

yarn serve

DONATION

If it works for you, throw me a bone:

nano_3ntf6crkan6114rfb39d51udqdw4mrbt1x7n8uphx44ojhxcjo3exhk6dsme

nano_3ntf6crkan6114rfb39d51udqdw4mrbt1x7n8uphx44ojhxcjo3exhk6dsme

nanosales's People

Contributors

spark-cruz avatar

Stargazers

 avatar Okke avatar  avatar Vinicius Emidio Bosi avatar Dirk Heinke avatar  avatar Tom Bertrand avatar Eduardo T Borges avatar SanN avatar Roger Pinho avatar Mateus Oliveira avatar Claxvii avatar Matheus Bach avatar Gabriel Scaramal avatar Walter von Gabain avatar  avatar Andrew Copeland avatar qwahzi avatar  avatar

Watchers

James Cloos avatar  avatar Eduardo T Borges avatar  avatar

Forkers

imtheunix

nanosales's Issues

State-blocks exchange queue

Instead of directly calling the routines to fetch and publish blocks they should be added to a queue and processed by a worker.
If a block fails to be fetched or published it should be scheduled for a retry on said queue.

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.