From 12de8be4465118bdc017fec7625e6876020e55d0 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 7 Mar 2021 00:40:34 -0700 Subject: [PATCH] Add loyalty points --- www/assets/js/loyalty.js | 52 +++++++++++++++ www/index.html | 1 + www/pages/loyalty.html | 135 +++++++++++++++++++++++++++++++++++++++ www/routes.js | 37 +++++++++-- www/settings.js | 3 +- 5 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 www/assets/js/loyalty.js create mode 100644 www/pages/loyalty.html diff --git a/www/assets/js/loyalty.js b/www/assets/js/loyalty.js new file mode 100644 index 0000000..7b3c64c --- /dev/null +++ b/www/assets/js/loyalty.js @@ -0,0 +1,52 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +function displayLoyaltyPoints() { + $("#loyalty-balance-box").addClass("display-none"); + $("#loyalty-error").html(""); + if (inStorage("phonenumber")) { + var phone = getStorage("phonenumber"); + } else { + $("#loyalty-error").text("Error: No phone number saved."); + } + app.dialog.preloader("Checking points balance..."); + apirequest(SETTINGS.apis.loyalty, {phone: phone}, function (success) { + app.dialog.close(); + if (success.status == "OK") { + $("#loyalty-credit-balance").text(success.credits + " points"); + $("#loyalty-balance-box").removeClass("display-none"); + + var canvas = document.createElement('canvas'); + + bwipjs.toCanvas(canvas, { + bcid: 'code128', // Barcode type + text: success.phone, // Text to encode + scaleX: 5, + scaleY: 1, + includetext: false, // Show human-readable text + textxalign: 'center', // Always good to set this + eclevel: 'M' + }); + document.getElementById("loyalty-barcode").src = canvas.toDataURL('image/png'); + } else { + $("#loyalty-balance-box").addClass("display-none"); + $("#loyalty-error").text("Error: " + success.message); + } + }, function (error) { + $("#loyalty-error").text("Error: Couldn't check your points balance. Try again later."); + }, "GET"); +} + +function savePhoneNumber() { + var phone = $("#phonenumber").val().replace(/\D/g, ''); + if (phone.length < 10) { + app.dialog.alert("Please enter a full 10-digit phone number.", "Oops!"); + return; + } + setStorage("phonenumber", phone); + router.refreshPage(); +} \ No newline at end of file diff --git a/www/index.html b/www/index.html index 90537f3..da06ebe 100644 --- a/www/index.html +++ b/www/index.html @@ -53,6 +53,7 @@ + \ No newline at end of file diff --git a/www/pages/loyalty.html b/www/pages/loyalty.html new file mode 100644 index 0000000..9a1f5c4 --- /dev/null +++ b/www/pages/loyalty.html @@ -0,0 +1,135 @@ + + +
+ + + + +
+
+
+
+
+ {{#if hasphone}} +
+
You have earned a total of
+

...

+ + +
+ +
+
36 Points
+
+
+
+ Postcard stamp +
+
+
+ +
+
50 Points
+
+
+
+ Forever stamp +
+
+
+
+
100 Points
+
+
+
+ $1 pickup discount +
+
+
+
+
500 Points
+
+
+
+
$5 pickup discount
+
+
+
Sheet of Forever stamps
+
+
+
+
+
800 Points
+
+
+
+ Postage for a Priority Mail envelope or small flat rate box +
+
+
+
+
2500 Points
+
+
+
+ Postage for a Priority Mail Express envelope +
+
+
+
+
+
+ {{else}} +
+ Save your phone number to start earning points! +
+
+
    +
  • +
    +
    Phone Number
    +
    + + +
    +
    +
  • +
+
+
+
Save Number
+
+ {{/if}} +
+
+
+ Loyalty points have no cash value. All points and associated discounts + are offered as a courtesy by and at the discretion of Helena Express + and may be revoked, canceled, or modified at any time for any reason. +
+
+
+
+ + + +
\ No newline at end of file diff --git a/www/routes.js b/www/routes.js index 56b69a3..86e6367 100644 --- a/www/routes.js +++ b/www/routes.js @@ -26,24 +26,30 @@ var routes = [ icon: "fad fa-search", text: "Find the latest location and updates about any shipment." }, - { - title: "Get Rates", - href: "/rates", - icon: "fad fa-calculator", - text: "Calculate postage and prices for your item." - }, { title: "Pick Up and Redeliver", href: "/noticeslip", icon: "fad fa-sticky-note", text: "Take a picture of your pink postal notice slip and we'll go get your missed delivery." }, + { + title: "Loyalty Points", + href: "/loyalty", + icon: "fad fa-badge-dollar", + text: "Earn free stamps and discounts." + }, { title: "Express Pickup", href: "/addresscode", icon: "fal fa-qrcode", text: "Get a faster pickup and a discount by pre-typing the destination address here." }, + { + title: "Get Rates", + href: "/rates", + icon: "fad fa-calculator", + text: "Calculate postage and prices for your item." + }, ] } }); @@ -130,6 +136,25 @@ var routes = [ }); } }, + { + path: '/loyalty', + name: 'loyalty', + async: function (routeTo, routeFrom, resolve, reject) { + var hasPhone = inStorage("phonenumber"); + var phone = getStorage("phonenumber"); + resolve({ + templateUrl: './pages/loyalty.html' + }, { + context: { + hasphone: hasPhone, + phone: phone + }, + on: { + pageAfterIn: displayLoyaltyPoints + } + }); + } + }, { path: '/track/:code', name: 'trackresult', diff --git a/www/settings.js b/www/settings.js index 206dd5b..3c3a5f4 100644 --- a/www/settings.js +++ b/www/settings.js @@ -8,7 +8,8 @@ var SETTINGS = { apis: { track: "https://helena.express/tracker/api.php", rates: "https://helena.express/rateapi.php", - pickuprequest: "https://helena.express/pspickup.php" + pickuprequest: "https://helena.express/pspickup.php", + loyalty: "https://helena.express/loyalty.php" }, stripe_pubkey: "pk_live_RgpadCo1LIIkfyUsY47VhUq6", appointmenturl: "https://appointments.netsyms.com/index.php?service=19&hlnexp=1&embed=1&only=1",