Payment Components
This package contains a plug and play front end component that any developer can include in its website.
Trying it out
Usage
Server (with express)
- Create project
yarn init
- Install dependencies
yarn add express body-parser dotenv
yarn add @requestnetwork/payments-server
- Create a
server.js
file
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config();
const request = require('@requestnetwork/payments-server')(process.env.API_KEY);
const app = express();
app.use(bodyParser.json());
app.use(express.static('public'));
app.post('/request', request.handler(process.env.ETH_ADDRESS));
app.use(function(err, req, res, next) {
res.status(500);
res.render('error', { error: err });
});
const listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});
-
Create a
.env
file, and fill in your dataYou can get your API Key by creating a free Request Account
# Your Request Accounts API key
API_KEY=xxxx-xxxx-xxxx-xxxx
# The wallet where you want to receive the money
ETH_ADDRESS=0x000000YOUR0ADDRESS
- create
public/index.html
Add the Request Payments button
<div
id="request-payment"
data-amount="7"
data-currency="EUR"
data-endpoint="/request"
data-style-button-variant="dark"
></div>
- Import the library and run it
<script src="https://unpkg.com/@requestnetwork/payments@0.2.0-alpha.5/dist/payments.iife.production.js"></script>
<script>
RequestPayments.init('#request-payment');
</script>
- Run!
node server.js