twc-wishlist-scanner
v1.2.5
Published
You can install the library using the following commands: - Using npm: ` npm install twc-wishlist-scanner` - Using yarn: ` yarn add twc-wishlist-scanner`
Downloads
3
Readme
How to install
You can install the library using the following commands:
- Using npm:
npm install twc-wishlist-scanner
- Using yarn:
yarn add twc-wishlist-scanner
Getting started
- First, add some
<div>
elements to your markup where you want to initialize the scanner. Here’s an example:
<div id="reader-wrapper">
<div id="reader"></div>
</div>
IMPORTANT: The id
attributes of the elements must match the example above.
- Import the BarcodeScanner class in your JavaScript code:
import { BarcodeScanner } from "wishlist-scanner";
- Initialize the scanner by creating an object with the required parameters:
const accessToken = "YOUR_ACCESS_TOKEN";
const tenant = "YOUR_TENANT";
const customerRef = "YOUR_CUSTOMER_REF";
const scanner = new BarcodeScanner(accessToken, tenant, customerRef);
4 . To start scanning, use the following method:
scanner.scanBarcode();
Example of usage
Here’s an example of how you can use the scanner in your index.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Barcode Scanner</title>
</head>
<body>
<button id="reader-init">Scan</button>
<div id="reader-wrapper">
<div id="reader"></div>
</div>
<script type="module" src="main.js"></script>
</body>
</html>
And in your main.js
:
import { BarcodeScanner } from "wishlist-scanner";
const accessToken = "YOUR_ACCESS_TOKEN";
const tenant = "YOUR_TENANT";
const customerRef = "YOUR_CUSTOMER_REF";
const scanner = new BarcodeScanner(accessToken, tenant, customerRef);
document.getElementById("reader-init").addEventListener("click", async () => {
scanner.scanBarcode();
});