Presents payment information in any JavaScript-based templating language (frontend of backend). See the Functions section below. The code is pretty simple, the main value is the unit tests.
var paymentTemplateHelpers = require('payment-template-helpers');
You'd typically add it to the helper methods to your templating system. For example, using ractive.js:
Ractive.defaults.data.paymentTemplateHelpers = paymentTemplateHelpers
getProRatedPrice()
now returns results in minor rather than major units- Agave is now used to add helper methods to Numbers and simplify code.
currencyToSymbol
returns a symbol to reflect the currency.
- currency String, required. A currency, in upperase. Eg, 'GBP', 'USD'.
- countryCode String, optional. An ISO3166-alpha-2 country code. Used to show 'USD' in countries which use '$' for their local currency.
amountToDollarsCents
returns a string representation of some amount of money. If the amount ends in 00, it will just show the major units. If the amount is less than or equal to 0, it will return 'FREE'. It has the following options:
- amount Number, required. Amount of money in minor units (cents, Eurocents, etc)
percentOff
returns a discounted amount, never less than 0.
- percentageDiscount Number, required. A percentage, in whole number.
- amount Number, required. Amount of money in minor units (cents, Eurocents, etc)
getProRatedPrice
returns a discounted amount, based on a yearly rate, for a product with an expiry date
- yearlyPrice Number, required. A yearly price in minor units (cents, Eurocents, etc)
- expiry Date, required. Date when the product will expire.
- multiplier Number, optional. For amount of products. Defaults to 1.
amountOff
returns a discounted amount, never less than 0.
- percentageDiscount Number, required. Discount in minor units (cents, Eurocents, etc)
- amount Number, required. Amount of money in minor units (cents, Eurocents, etc)
Support currencies with more than two digits for minor units.
Run mocha