Skip to content

Nano cryptocurrency payment gateway helper for e-commerce

License

Notifications You must be signed in to change notification settings

SparK-Cruz/nanosales

Repository files navigation

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

About

Nano cryptocurrency payment gateway helper for e-commerce

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published