ArtifactPaymentBuilder

ArtifactPaymentBuilder

A payment builder that calculates exchange rates, balances, conversion costs, and which coin to use for payment




Constructor

new ArtifactPaymentBuilder(wallet, artifact, amount, type, coinopt, fiatopt)

Create a new ArtifactPaymentBuilder

Parameters:
Name Type Attributes Default Description
wallet Wallet

A live OIP-HDMW logged in wallet

artifact Artifact

The Artifact related to the Payment you wish to make

amount ArtifactFile | number

The amount you wish to pay (tip), or the ArtifactFile you wish to pay for (view & buy)

type string

The type of the purchase, either tip, view, or buy

coin string <optional>

The Coin you wish to pay with

fiat string <optional>
"usd"

The Fiat you wish to tip in (if amount was a number and NOT an ArtifactFile) default: "usd"

Source:

Methods




_swapCoinTickerName(coins, from_type, to_type) → {String|Array.<String>}

Internal function used for both nameToTicker and tickerToName

Parameters:
Name Type Description
coins String | Array.<String>

The Coins names/tickers you would like to swap

from_type String

Either "ticker" or "name"

to_type String

Either "ticker" or "name"

Source:
Returns:

Returns the converted tickers/names

Type:
String | Array.<String>



coinPicker(coin_balances, conversion_costs, preferred_coinopt) → {string|Object}

Picks a coin with enough balance in our wallet to spend (default to flo, then litecoin, then bitcoin last)

Parameters:
Name Type Attributes Description
coin_balances object

Key value pairs [coin][balance]. See: getBalances()

conversion_costs object

Key value pairs [coin][conversion cost]. See: convertCosts()

preferred_coin string <optional>

Preferred coin to pay with

Source:
Example
let APB = new ArtifactPaymentBuilder(wallet, artifact, artifactFile, "view")
APB.coinPicker(coin_balances, conversion_costs)

//returns
"bitcoin" || {error: true, response: "function coinPicker could not get coin with sufficient balance"}
Returns:
  • A string with the selected coin that has enough balance to pay with or an object containing an error status and response
Type:
string | Object



fiatToCrypto(exchange_rates, fiat_amount) → {Object}

Convert fiat price to crypto price using live exchange_rates

Parameters:
Name Type Description
exchange_rates Object

The exchange rates retreived from the Wallet

fiat_amount number

The amount you wish to get the conversion cost for

Source:
Example
let exchange_rates = await APB.getExchangeRates(wallet)
 let conversion_costs = await APB.fiatToCrypto(exchange_rates, .00012);
//returns
{
     "coin_name": expect.any(Number),
     ...
}
Returns:

conversion_costs

Type:
Object



getPaymentAddress(coins, artifactopt) → {Object}

Get Artifact Payment Address

Parameters:
Name Type Attributes Description
coins string | Array.<string>

A string or array of strings you wish to get the payment addresses for

artifact Artifact <optional>

Get the payment addresses of a given artifact... if no artifact is given, it will use the artifact given in the constructor

Source:
Example
let APB = new ArtifactPaymentBuilder(undefined, artifact)
APB.getPaymentAddress(["bitcoin"])

//returns
{ bitcoin: "19HuaNprtc8MpG6bmiPoZigjaEu9xccxps" }
Returns:
Type:
Object



(async) getPaymentAddressAndAmount(coinopt) → {Promise.<Object>}

This function is used to get the proper payment address, payment amount (in crypto cost), and the coin to use to pay.

Parameters:
Name Type Attributes Description
coin string <optional>

The coin you want to pay with

Source:
Returns:

Returns a Promise that resolves to the payment address, payment amount, and payment coin. If it fails, it will return an object with success: false, and the error.

Type:
Promise.<Object>



getPaymentAddresses(artifactopt) → {Object}

Get Artifact Payment Addresses (to know what coins are supported)

Parameters:
Name Type Attributes Description
artifact Artifact <optional>

Get the payment addresses of a given artifact... if no artifact is given, it will use the artifact given in the constructor

Source:
Example
let APB = new ArtifactPaymentBuilder(wallet, artifact, artifactFile, "view")
APB.getPaymentAddresses()

//returns
{ bitcoin: "19HuaNprtc8MpG6bmiPoZigjaEu9xccxps" }
Returns:
Type:
Object



getPaymentAmount() → {Number}

Get Payment Amount. Uses constructor variables to get payment amount based off ArtifactFile or amount parameter.

Source:
Returns:

payment_amount

Type:
Number



getSupportedCoins(preferred_coinsopt, artifactopt) → {string|Array.<string>}

getSupportedCoins retrieves the coins the Artifact accepts as payment

Parameters:
Name Type Attributes Description
preferred_coins string | Array.<string> <optional>

An array of coins you would prefer to use

artifact Artifact <optional>

An Artifact to get the addresses from. If nothing is passed in, it will attempt to use the constructor's Artifact.

Source:
Returns:

An array of coins that the Artifact accepts as payment. If Artifact does not support coin input, an empty array will be returned

Type:
string | Array.<string>



nameToTicker(coin_names) → {string|Array.<string>}

Name to Ticker (only supports bitcoin, litecoin, and flo currently

Parameters:
Name Type Description
coin_names string | Array.<string>

Names of coins

Source:
Returns:
Type:
string | Array.<string>



(async) pay() → {Promise.<string>}

The pay function is used to do the final sending of a payment. If the processing has been preformed (i.e. if getPaymentAddressAndAmount has been called), it will send the payment using the already looked up information

Source:
Returns:

Returns a Promise that will resolve to the txid of the sent payment.

Type:
Promise.<string>



(async) sendPayment(payment_address, amount_to_pay, selected_coinopt) → {Promise}

Send the Payment to the Payment Addresses using the selected coin from coinPicker() for the amount calculated

Parameters:
Name Type Attributes Description
payment_address string

The addresses you wish to send money to

amount_to_pay number

The amount you wish to pay in crypto

selected_coin string <optional>

The coin you wish to spend with. If no coin is given, function will try to match address with a coin.

Source:
Returns:

A promise that resolves to a txid if the tx went through or an error if it didn't

Type:
Promise



tickerToName(coin_tickers) → {string|Array.<string>}

Ticker to name (only supports btc, ltc, and flo currently

Parameters:
Name Type Description
coin_tickers string | Array.<string>

Coin tickers

Source:
Returns:
Type:
string | Array.<string>