Handle IOTA payments and more
Returns the balance
// get payout by txhash
paymentModule.getBalance()
.then(balance => {
console.log(balance)
})
.catch(err => {
console.log(err)
})
//example balance:
15
Returns number balance
Returns string
Returns Array<any>
Creates and returns a express server.
// creates a simple server
var paymentModule = require('iota-payment')
var app = require('express')()
let server = paymentModule.createServer(app, {api: true})
// Start server with iota-payment api on '/iotapay/api'
server.listen(3000, function () {
console.log(`Server started on http://localhost:3000 `)
})
Returns object an http server
This method attaches an event listener. Possible events: -payments: ‘paymentCreated’, ‘paymentPending’, ‘paymentIncoming’, ‘paymentSuccess’ -payouts: ‘payoutCreated’, ‘payoutSent’
const paymentModule = require('iota-payment')
//Create an event handler which is called, when a payment was successfull
let onPaymentSuccess = function (payment) {
console.log('payment success!', payment);
}
//Assign the event handler to an event:
paymentModule.onEvent('paymentSuccess', onPaymentSuccess);
Creates and returns a payment.
paymentInput
object data for the payment
// create a payment with the value option
paymentModule.createPaymentRequest({value: 1, data: { "test": "123" }})
.then(payment => {
console.log(payment)
})
.catch(err => {
console.log(err)
})
//example payment:
{ data: '',
paid: false,
txInfo: null,
type: 'value',
value: 1,
address:
'IDEAVKKGLZUCAZJEWOUXVCUYGPSINKJR9UVBEOXRNIOBJFAKUN9GVBDGVEVOOK9HVMMMFMDLZ9G9YFHPWULQWCXYVW',
index: 49,
id: '1575750004195'}
// create a payment with the timeUntilConfirmation option
paymentModule.createPaymentRequest({timeUntilConfirmation: 180, data: { "test": "123" }})
.then(payment => {
console.log(payment)
})
.catch(err => {
console.log(err)
})
//example payment:
{ data: { test: '123' },
paid: false,
txInfo: null,
type: 'time',
confirmationTime: 1575750870,
address:
'BQGQONEUNQYDDEUFDZIJDTVTFUBSIQECBLPU9BNNDVPMXMKFCWYODBGSPHA9TYCFFSYGUH9OIZYDIGBMCXHRBEIIAX',
index: 50,
id: '1575750690816' }
Returns object payment
Returns all payments
// get payments
paymentModule.getPayments()
.then(payments => {
console.log(payments)
})
.catch(err => {
console.log(err)
})
//example payments:
[ { address:
'CLHNILYEPUQYJWRSGPQGA9BVVKHFHQMDM9ENNSGAHJXJIOLMBARZNHKWZZVGXSSQITOHPD9JXQGVQJJJBKMVRFWSNW',
index: 10,
value: '0',
data: 'test',
paid: true,
id: '1570466750915',
lastTime: 1570466754629 },
{ address:
'CLTDMWYNTKMPSISD9CBLH9MGATUZQXDALPZQBMHPJQLTKDTWDKFRJQYDKUCPYQFTFPNJBEIHHJRBKQMXXHNSUYEXJC',
index: 12,
value: 1,
paid: false,
id: '1570564499942' } ]
Returns Array<Object> payments
Returns all open (not paid and not too old) payments
// get open payments
paymentModule.getPayments()
.then(payments => {
console.log(payments)
})
.catch(err => {
console.log(err)
})
//example payments:
[ { address:
'QXHAEPJSEIUAMMOUWDGYJD9MPPIGBYOPAQSPOZK9VZSGDVVV9SUJEYVXYRFL9KRRBWSDNIFGBDLH9DBADGABSCFTFD',
index: 11,
value: 1,
data: { test: '123' },
paid: false,
id: '1570554460662' },
{ address:
'CLTDMWYNTKMPSISD9CBLH9MGATUZQXDALPZQBMHPJQLTKDTWDKFRJQYDKUCPYQFTFPNJBEIHHJRBKQMXXHNSUYEXJC',
index: 12,
value: 1,
paid: false,
id: '1570564499942' } ]
Returns Array<Object> open payments
Returns all paid (not open and not too old) payments
// get open payments
paymentModule.getPaidPayments()
.then(payments => {
console.log(payments)
})
.catch(err => {
console.log(err)
})
//example payments:
[ { address:
'QXHAEPJSEIUAMMOUWDGYJD9MPPIGBYOPAQSPOZK9VZSGDVVV9SUJEYVXYRFL9KRRBWSDNIFGBDLH9DBADGABSCFTFD',
index: 11,
value: 1,
data: { test: '123' },
paid: true,
id: '1570554460662' },
{ address:
'CLTDMWYNTKMPSISD9CBLH9MGATUZQXDALPZQBMHPJQLTKDTWDKFRJQYDKUCPYQFTFPNJBEIHHJRBKQMXXHNSUYEXJC',
index: 12,
value: 1,
paid: true,
id: '1570564499942' } ]
Returns Array<Object> paid payments
Returns payment by id
// get payment by id
paymentModule.getPaymentByID('1570564499942')
.then(payment => {
console.log(payment)
})
.catch(err => {
console.log(err)
})
//example payment:
{ address:
'CLTDMWYNTKMPSISD9CBLH9MGATUZQXDALPZQBMHPJQLTKDTWDKFRJQYDKUCPYQFTFPNJBEIHHJRBKQMXXHNSUYEXJC',
index: 12,
value: 1,
paid: false,
id: '1570564499942' }
Returns Object payment
Creates and returns a payout.
payoutData
object data for the payout
payoutData.address
address 90 trytes iota address (with checksum)payoutData.amount
number amount of iotaspayoutData.message
string? message which will be send with the transactionpayoutData.tag
string? tryte tagpayoutData.data
any? additional data, is only stored locallypayoutData.startIndex
number? custom start index to search for inputaddressespayoutData.endIndex
number? custom end index to search for inputaddresses// create a payout
let payoutObject = {
//required
address: 'HW99PKRDWBUCCWLEQDONQXW9AXQHZAABYEKWSEFYAUIQWWCLVHAUJEQAZJACAGPZBZSQJIOUXRYYEXWZCXXOAJMZVY',
value: 1,
//optional
message: 'Example message',
tag: 'TRYTETAG',
data: {test: 27},
//indexes for input addresses, only required in special cases
// startIndex: 0,
// endIndex: 1
}
paymentModule.sendPayout(payoutObject)
.then(payout => {
console.log(payout)
})
.catch(err => {
console.log(err)
})
//example payout:
{ address:
'HW99PKRDWBUCCWLEQDONQXW9AXQHZAABYEKWSEFYAUIQWWCLVHAUJEQAZJACAGPZBZSQJIOUXRYYEXWZCXXOAJMZVY',
value: 1,
message: 'Example message',
tag: 'TRYTETAG',
data: {test: 27},
paid: false,
id: '1570619992125' }
Returns object payout
Returns all payouts
$0
Object (optional, default {}
)
$0.address
$0.value
$0.message
$0.tag
$0.data
$0.startIndex
$0.endIndex
// get payouts
paymentModule.getPayouts()
.then(payouts => {
console.log(payouts)
})
.catch(err => {
console.log(err)
})
//example payouts:
[
{
"address": "USKSGFKPWVXD9EUOJXWNLVWG9FDTIPGBUYB9BQNMMUWIEOMFNDCCUKCJMEPRICBHZNRAIZFGNPK9GCGBYQAEWNJRMC",
"value": 1,
"message": "Example message",
"paid": true,
"id": "1570616325073",
"txhash": "XKLLL9B9AUN9EASCAQAQHEYDLLEUDDUCOTJVNTJUSZVTNWUTDPHZUFUJAHFZJOSQYYEPJSWRDXDJ99999"
},
{
"address": "HW99PKRDWBUCCWLEQDONQXW9AXQHZAABYEKWSEFYAUIQWWCLVHAUJEQAZJACAGPZBZSQJIOUXRYYEXWZCXXOAJMZVY",
"value": 1,
"message": "Example message",
"paid": false,
"id": "1570616561382"
}
]
Returns open payouts
$0
Object (optional, default {}
)
$0.address
$0.value
$0.message
$0.tag
$0.data
$0.startIndex
$0.endIndex
// get open payouts
paymentModule.getOpenPayouts()
.then(payouts => {
console.log(payouts)
})
.catch(err => {
console.log(err)
})
//example payouts:
[
{
"address": "HW99PKRDWBUCCWLEQDONQXW9AXQHZAABYEKWSEFYAUIQWWCLVHAUJEQAZJACAGPZBZSQJIOUXRYYEXWZCXXOAJMZVY",
"value": 1,
"message": "Example message",
"paid": false,
"id": "1570616561382"
}
]
Returns Array<Object> open payouts
Returns payout by id
$0
Object (optional, default {}
)
$0.address
$0.value
$0.message
$0.tag
$0.data
$0.startIndex
$0.endIndex
// get payout by id
paymentModule.getPayoutByID('1570611186704')
.then(payout => {
console.log(payout)
})
.catch(err => {
console.log(err)
})
//example payout:
{ address:
'USKSGFKPWVXD9EUOJXWNLVWG9FDTIPGBUYB9BQNMMUWIEOMFNDCCUKCJMEPRICBHZNRAIZFGNPK9GCGBYQAEWNJRMC',
value: 1,
message: 'Example message',
paid: false,
id: '1570611186704' }
Returns Object payment
Returns payout by txhash
$0
Object (optional, default {}
)
$0.address
$0.value
$0.message
$0.tag
$0.data
$0.startIndex
$0.endIndex
// get payout by txhash
paymentModule.getPayoutByTxhash('XKLLL9B9AUN9EASCAQAQHEYDLLEUDDUCOTJVNTJUSZVTNWUTDPHZUFUJAHFZJOSQYYEPJSWRDXDJ99999')
.then(payout => {
console.log(payout)
})
.catch(err => {
console.log(err)
})
//example payout:
{ address:
'USKSGFKPWVXD9EUOJXWNLVWG9FDTIPGBUYB9BQNMMUWIEOMFNDCCUKCJMEPRICBHZNRAIZFGNPK9GCGBYQAEWNJRMC',
value: 1,
message: 'Example message',
paid: true,
id: '1570616325073',
txhash:
'XKLLL9B9AUN9EASCAQAQHEYDLLEUDDUCOTJVNTJUSZVTNWUTDPHZUFUJAHFZJOSQYYEPJSWRDXDJ99999' }
Returns Object payment
##
WebSockets with socket.io
backend: https://github.com/machineeconomy/iota-payment/blob/master/examples/06_websockets.js
frontend: https://github.com/machineeconomy/iota-payment/blob/master/examples/06_websocket.html