iota-payment-module

Handle IOTA payments and more

View the Project on GitHub iota-pay/iota-payment-module

Table of Contents

getBalance

Returns the balance

Examples

// get payout by txhash
paymentModule.getBalance()
 .then(balance => {
     console.log(balance)
   })
 .catch(err => {
   console.log(err)
 })
//example balance:
15

Returns number balance

generate_address

Parameters

Returns string

generate_addresses

Parameters

Returns Array<any>

createServer

Creates and returns a express server.

Parameters

Examples

// 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

onEvent

This method attaches an event listener. Possible events: -payments: ‘paymentCreated’, ‘paymentPending’, ‘paymentIncoming’, ‘paymentSuccess’ -payouts: ‘payoutCreated’, ‘payoutSent’

Parameters

Examples

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);

createPaymentRequest

Creates and returns a payment.

Parameters

Examples

// 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

getPaidPayments

Returns all payments

Examples

// 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

getPaidPayments

Returns all open (not paid and not too old) payments

Examples

// 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

getPaidPayments

Returns all paid (not open and not too old) payments

Examples

// 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

payment

Returns payment by id

Examples

// 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

sendPayout

Creates and returns a payout.

Parameters

Examples

// 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

payoutValidator

Returns all payouts

Parameters

Examples

// 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 Array<Object> payouts

payoutValidator

Returns open payouts

Parameters

Examples

// 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

payoutValidator

Returns payout by id

Parameters

Examples

// 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

payoutValidator

Returns payout by txhash

Parameters

Examples

// 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