diff --git a/README.md b/README.md index 14ac02d..b3215f3 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ when a barcode is scanned on the Prepaid page. The function is passed one argume containing the raw barcode data. The function shall return boolean `false` if unable or unwilling to handle the barcode. If the barcode is handled by this function, it shall return a TrackingBarcode object. * `addPrepaidBarcode(trackingBarcodeData)`: Add a TrackingBarcode object to the transaction receipt at any time other than `onPrepaidScan`. +* `inject(barcodeData)`: Pass data to the internal barcode event subsystem. The data is handled as if it were just received from a physical barcode scanner. #### Database @@ -127,6 +128,7 @@ PostalPoint uses the Jimp library version 1.6 for creating and manipulating imag * `onReceiptChange(function (receipt) {})`: Add a function to be called whenever the transaction data/receipt is changed. * `onTransactionFinished(function (receipt) {})`: Same as `onReceiptChange` except run when a transaction is completed. * `registerCardProcessor(...)`: Register the plugin as a credit card processor. See examples/payment-processor for details. +* `registerCryptoProcessor(...)`: Register the plugin as a cryptocurrency payment provider. See examples/crypto-processor for details. * `ReceiptItem`: A class representing a sale item in the current transaction. See docs/Receipt.md for details. * `ReceiptPayment`: A class representing a payment entry for the current transaction. See docs/Receipt.md for details. diff --git a/examples/crypto-processor/plugin.js b/examples/crypto-processor/plugin.js new file mode 100644 index 0000000..06e083c --- /dev/null +++ b/examples/crypto-processor/plugin.js @@ -0,0 +1,72 @@ +// This is a sample PostalPoint plugin that adds a card payment processor. + +exports.init = function () { + global.apis.pos.registerCryptoProcessor({ + name: "Demo Crypto", + init: async function () { + // This is run after PostalPoint starts, and before any other crypto functions are called. + }, + checkout: async function ( {amount}) { + // Run the checkout process. + // amount is the amount of USD to collect, in pennies. + + // If an error is encountered during processing, + // display an error message in a dialog and return boolean false. + // If this function returns anything except false or undefined, and doesn't throw an error, + // it is assumed the payment was successful. + + // Adds a line of text visible to the cashier + global.apis.pos.addOnscreenPaymentLog("Getting crypto payment..."); + + // Display a web page (i.e. with a payment QR code) to the customer on the customer-facing display. + global.apis.ui.setCustomerScreen("", "html"); + global.apis.ui.setCustomerScreen("https://postalpoint.app", "raw"); + + // Poll the status of the crypto transaction + var paymentComplete = false; + do { + await global.apis.util.delay(1000); + paymentComplete = true; + } while (paymentComplete != true); + + global.apis.pos.addReceiptPayment( + new global.apis.pos.ReceiptPayment( + (amount / 100).toFixed(2) * 1, + "crypto", // Payment type. + "Bitcoin\n0.00001234 BTC" // Additional text for receipt + ) + ); + global.apis.pos.addOnscreenPaymentLog("Payment successful!"); + global.apis.ui.clearCustomerScreen(); + }, + cancelCheckout: function () { + // The user requested to cancel the payment. + // Reset things accordingly. + global.apis.ui.clearCustomerScreen(); + }, + isConfigured: function () { + // Is this plugin properly setup and able to process payments? If not, return false. + return true; + } + }); +} + +// Plugin settings to display. +exports.config = [ + { + type: "password", + key: "democryproprocessor_apikey", + defaultVal: "", + label: "API Key", + placeholder: "", + text: "API Key" + }, + { + type: "button", + label: "Test Button", + text: "Some text about the button", + onClick: function () { + global.apis.ui.openSystemWebBrowser("https://postalpoint.app"); + } + } +];