@fluidcoins/pay.js

0.1.15 • Public • Published

Documentation

Fluidcoins Pay.js

Fluidcoins Pay.js is quick and secure way to receive crypto payments in your application. It works with all Javascript frameworks

Requirement

Nodejs version > 10

Getting Started

1: Register a merchant account on Fluidcoins and get your public API key

Installation

You can install the package via NPM or Yarn;

npm install @fluidcoins/pay.js

OR

yarn add @fluidcoins/pay.js

Usage

Parameters

  • key
  • amount
  • email
  • onSuccess
  • onLoad (optional)
  • onClose (optional)
  • onError (optional)
  • name (optional)
  • phone (optional)
  • metadata (optional)
  • callback_url (optional)
  • currency (optional)
  • reference (optional)

key

REQUIRED

This is your Fluidcoins public API key from the Fluidcoins dashboard.

new Fluidcoins({key: 'fluidcoins_public_api_key'})

amount

REQUIRED

This is amount in the smallest unit of currency you'd want to receive from the customer.

NOTE: The minimum amounts are

  • 500 NGN for the Nigerian Naira
  • 1 USD for the United State Dollars
new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 50000 // or 100 for 1 USD
})

email

REQUIRED

This is the email address of the customer

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com'
})

onSuccess

REQUIRED

This is function that will be called when a successful transaction occurs.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})}
})

A JSON payload is passed as argument with the structure below;

{ 
    reference: TRANS_REFERENCE,
    coin: 'BTC',
    human_readable_amount: 1000,
    payment_status: 'underpaid | overpaid | paid_in_full'
}

Payment status could be overpaid, underpaid or paid_in_full

onLoad

OPTIONAL

This closure is called once the Fluidcoins PaySDK loads

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')}
})

onClose

OPTIONAL

This optional closure is called when a user closes the Fluidcoins Widget. It takes no argument

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')}
})

onError

OPTIONAL

This optional closure is called when an error occurs. Error such as session expired, etc.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
})

A JSON payload is passed as argument with the structure below;

{ 
    type: 'expired',
}

Error type could be;

  • expired : Payment session for the initiated transaction expired

name

OPTIONAL

This optional parameter; which is the name of customer who want to initiate the transaction. It reflects on the Fluidcoins dashboard.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni'
})

phone

OPTIONAL

This optional parameter; which is the phone number of customer who want to initiate the transaction. It reflects on the Fluidcoins dashboard.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni',
    phone: '+2348090909090',
})

reference

OPTIONAL

This optional parameter; which is used to identify the initiated transaction.

NOTE : It must be unique per transaction

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni',
    phone: '+2348090909090',
    reference: 'random-identifier'
})

metadata

OPTIONAL

This optional parameter, which is should contain data you will like to be passed via webhooks about the transaction. NOTE: The metadata must be an OBJECT

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni',
    phone: '+2348090909090',
    metadata: {
        key: 1
    }
})

callback_url

OPTIONAL

This optional parameter is used to open a new window tab when a successful [ underpaid, overpaid, paid_in_full ] payment occurs. NOTE: The callback_url must be a valid URL with a HTTPS scheme . Also, it DOES NOT override the onSuccess() event.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni',
    phone: '+2348090909090',
    metadata: {
        key: 1
    },
    callback_url: 'https://www.google.com/'
})

currency

OPTIONAL

Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar"

NOTE: It defaults to default currency set on your Fluidcoins dashboard.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni',
    phone: '+2348090909090',
    metadata: {
        key: 1
    },
    callback_url: 'https://www.google.com/',
    currency: 'USD'
})

reference

OPTIONAL

This optional parameter is used as a reference instead of the Fluidcoins auto-generated reference. We recommended random string.

new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onLoad: () => { console.log('Loaded sdk successfully')},
    onClose: () => { console.log('User closed widget')},
    onError: (error) => { console.log({error})},
    name: 'Seun Akanni',
    phone: '+2348090909090',
    metadata: {
        key: 1
    },
    callback_url: 'https://www.google.com/',
    currency: 'USD',
    reference: 'REF_random_reference'
})

API References

setup()

This method is used to load the widget unto the DOM, the widget remains hidden after invoking this function until the open() method is called.

const fluidcoins = new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
})
fluidcoins.setup()

open()

This method makes the widget visible to the user.

const fluidcoins = new Fluidcoins({
    key: 'fluidcoins_public_api_key',
    amount: 100000,
    email: 'customer@test.com',
    onSuccess: (data) => { console.log({data})},
})
fluidcoins.setup()
fluidcoins.open()

More on Documentations

Fluidcoins Developer's section

Readme

Keywords

none

Package Sidebar

Install

npm i @fluidcoins/pay.js

Weekly Downloads

9

Version

0.1.15

License

MIT

Unpacked Size

17.6 kB

Total Files

4

Last publish

Collaborators

  • adelowo