/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
// Global Variables
var askRate = 0;
var btcAmount = 0;
var purchaseAmount = 0;
var btcWallet = "";
var btcSymbol = "";
// var recID = "";
var orderID = "";
var phone = "";
var fee = 0;
var netAmount = 0;
var entrydate = "";
var email = "";
var availamt = "";
var maxamt = "";
var loginStatus = "";
// jQuery codes
$(document).ready(function() {
//
// Update password field to required
//
$(document).on('click', '#lblUpdatePassword', function(){
$("#updatePassword").collapse("toggle");
});
$(document).on('shown.bs.collapse', '#updatePassword', function(){
$("#password").prop('required',true);
$("#confirmpassword").prop('required',true);
});
$(document).on('hidden.bs.collapse', '#updatePassword', function(){
//$("#password").removeAttr("required");
$("#password").prop('required',false);
$("#confirmpassword").prop('required',false);
});
$(document).on('input', '#phone', function() {
$(this).val(function(i, text) {
var tmp = text.replace(/[^0-9]/g, '');
var input = tmp.substring(0,10); // First ten digits of input only
var zip = input.substring(0,3);
var middle = input.substring(3,6);
var last = input.substring(6,10);
var value = "";
if(input.length > 6) { value = zip + "-" + middle + "-" + last; }
else if(input.length > 3) { value = zip + "-" + middle; }
else if(input.length > 0) { value = zip; }
return value;
});
});
// show create account / registration
$(document).on('click', '#sign_up', function(){
var html = `
Create New Account
`;
clearResponse();
$('#content').html(html);
});
//Reset Password Trigger
$(document).on('click', "#btnResetPassword", function() {
var _email = $('#email').val();
if ( _email === "" ) {
alert('Please enter your email address.');
} else {
resetPassword(_email);
}
});
// Trigger when reset button is
$(document).on('click', "#btnSignUpReset", function() {
$('#pwd').val('');
$("#pwd").trigger("keyup");
});
// When the user starts to type something inside the password field
$(document).on('keyup', "#pwd", function(e) {
// var c = String.fromCharCode(e.which);
var c = $('#pwd').val();
// Validate lowercase letters
var lowerCaseLetters = /[a-z]/g;
if (c.match(lowerCaseLetters) ) {
$("#letter").removeClass("invalid");
$("#letter").addClass("valid");
} else {
$("#letter").removeClass("valid");
$("#letter").addClass("invalid");
}
// Validate capital letters
var upperCaseLetters = /[A-Z]/g;
if( c.match(upperCaseLetters) ) {
$("#capital").removeClass("invalid");
$("#capital").addClass("valid");
} else {
$("#capital").removeClass("valid");
$("#capital").addClass("invalid");
}
// Validate numbers
var numbers = /[0-9]/g;
if( c.match(numbers) ) {
$("#number").removeClass("invalid");
$("#number").addClass("valid");
} else {
$("#number").removeClass("valid");
$("#number").addClass("invalid");
}
// Validate length
if( c.length >= 8) {
$("#length").removeClass("invalid");
$("#length").addClass("valid");
} else {
$("#length").removeClass("valid");
$("#length").addClass("invalid");
}
});
// Trigger when reset button is
$(document).on('click', "#btnUpdateAccountReset", function() {
$('#password').val('');
$("#password").trigger("keyup");
});
// When the user starts to type something inside the password field
$(document).on('keyup', "#password", function(e) {
// var c = String.fromCharCode(e.which);
var c = $('#password').val();
// Validate lowercase letters
var lowerCaseLetters = /[a-z]/g;
if (c.match(lowerCaseLetters) ) {
$("#letter").removeClass("invalid");
$("#letter").addClass("valid");
} else {
$("#letter").removeClass("valid");
$("#letter").addClass("invalid");
}
// Validate capital letters
var upperCaseLetters = /[A-Z]/g;
if( c.match(upperCaseLetters) ) {
$("#capital").removeClass("invalid");
$("#capital").addClass("valid");
} else {
$("#capital").removeClass("valid");
$("#capital").addClass("invalid");
}
// Validate numbers
var numbers = /[0-9]/g;
if( c.match(numbers) ) {
$("#number").removeClass("invalid");
$("#number").addClass("valid");
} else {
$("#number").removeClass("valid");
$("#number").addClass("invalid");
}
// Validate length
if( c.length >= 8) {
$("#length").removeClass("invalid");
$("#length").addClass("valid");
} else {
$("#length").removeClass("valid");
$("#length").addClass("invalid");
}
});
// trigger when list is selected
$(document).on('click', '#order, #homeArrowRight, #listorderArrowLeft, #btnMenuOrder', function(){
showOrderPage();
// return false;
});
// Cancel order
$(document).on('click', '#btnCancelOrder', function(){
var btn_order=$(this);
var s_orderid = btn_order.val();
var question = "Continue with order cancellation?";
$.when( confirmation(question) )
.done ( function() { cancel_order(s_orderid); })
.fail(function() {;} )
;
});
// trigger list order page
$(document).on('click', '#listorder , #orderArrowRight, #updateaccountArrowLeft, #btnMenuListOrder', function(){
// validate jwt to verify accessS
var jwt = getCookie('jwt');
// Create a form to handle post data
var listorder_form = $("", { action:'' });
// get form data
var listorder_form_obj = listorder_form.serializeObject();
// add jwt on the object
listorder_form_obj.jwt = jwt;
listorder_form_obj.email = email;
// convert object to json string
var form_data = JSON.stringify(listorder_form_obj);
listOrder(form_data);
return false;
});
// trigger when list is selected
$(document).on('click', '#invoice', function(){
// validate jwt to verify access
var jwt = getCookie('jwt');
// Create a form to handle post data
var listinvoice_form = $("", { action:'' });
// get form data
var listinvoice_form_obj = listinvoice_form.serializeObject();
// add jwt on the object
listinvoice_form_obj.jwt = jwt;
// listinvoice_form_obj.orderid = "";
// convert object to json string
var form_data = JSON.stringify(listinvoice_form_obj);
// listOrder(form_data);
$.when( showInvoicePage() ).done ( listInvoice(form_data) );
return false;
});
// Print Receipt
$(document).on('click', '#btnPrintReceipt', function(){
var header = `
Monster Dollar
`;
var col1 = '
Monster Dollar
';
var col2 = '
33720 9th Avenue South Suite 7, Federal Way, WA 98003
';
var col3 = '
253-344-1408
';
var colr = '
Receipt
';
var col4 = '
Date: '+entrydate+'
';
var col5 = '
Customer:
';
var col6 = '
Order no.: '+orderID+'
';
var col7 = '
Amount: $'+purchaseAmount+'
';
var col8 = '
'+btcSymbol+': We received your trade and sent you '+btcAmount+' '+btcSymbol+'.
';
var col9 = '
Fee: $'+fee+'
';
var col10 = '
Bitcoin Price: $'+askRate+'
';
var col11 = '
Wallet Address: '+btcWallet+'
';
var footer = `
`;
var data = header+col1+col2+col3+colr+col4+col5+col6+col7+col8+col9+col10+col11+footer;
var myWindow = window.open("", "MsgWindow", "resizable=yes,top=100,left=300,width=800,height=600");
myWindow.document.write(data);
myWindow.print();
myWindow.close();
return false;
});
// To enable row trigger: '#listRecords tbody tr'
$(document).on('click', '#btnPrintPreOrder', function(){
var header = `
Monster Dollar
`;
var footer = `
`;
var currentRow=$(this).closest("tr");
var col1=currentRow.find("td:eq(0)").text(); // get current row 1st TD value
var col2=currentRow.find("td:eq(1)").text(); // get current row 2nd TD
var col3=currentRow.find("td:eq(2)").text(); // get current row 3rd TD
var col4=currentRow.find("td:eq(3)").text(); // get current row 1st TD value
var col5=currentRow.find("td:eq(4)").text(); // get current row 2nd TD
var col6=currentRow.find("td:eq(5)").text(); // get current row 3rd TD
var col7=currentRow.find("td:eq(6)").text(); // get current row 1st TD value
var col8=currentRow.find("td:eq(7)").text(); // get current row 2nd TD
var col9=currentRow.find("td:eq(8)").text(); // get current row 3rd TD
var t_head = `
Date
Phone
Order ID
Crypto
Amount
Email
Wallet
`;
var t_footer = `
`;
var tr = '
';
tr += '
' + col1 + '
';
tr += '
' + col2 + '
';
tr += '
' + col3 + '
';
tr += '
' + col5 + '
';
tr += '
' + col6 + '
';
tr += '
' + col8 + '
';
tr += '
' + col9 + '
';
var data="
"+col1+"
"+col2+"
"+col3+"
";
data += "
"+header+t_head+tr+t_footer+footer;
var myWindow = window.open("", "MsgWindow", "resizable=yes,top=100,left=300,width=800,height=600");
myWindow.document.write(data);
myWindow.print();
myWindow.close();
return false;
});
// Trigger when the btnPrintInvoice is clicked
$(document).on('click', '#btnPrintInvoice', function(){
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
var currentRow=$(this).closest("tr");
var date=currentRow.find("td:eq(0)").html(); // get current row 1st TD value
var orderid=currentRow.find("td:eq(1)").html(); // get current row 2nd TD
var custinfo=currentRow.find("td:eq(2)").html(); // get current row 3rd TD
var crypto=currentRow.find("td:eq(3)").html(); // get current row 1st TD value
var usdamount=currentRow.find("td:eq(4)").html(); // get current row 2nd TD
var fee=currentRow.find("td:eq(5)").html(); // get current row 3rd TD
var debitfee=currentRow.find("td:eq(6)").html(); // get current row 1st TD value
var digamount=currentRow.find("td:eq(7)").html(); // get current row 2nd TD
var rate=currentRow.find("td:eq(8)").html(); // get current row 3rd TD
var wallet=currentRow.find("td:eq(9)").html(); // get current row 3rd TD
var header = `
33720 9th Avenue South Suite 7 Federal Way, WA 98003 Phone: (253)344-1408 FAX: (253)344-1507 Email: info@monsterdollar.net
INVOICE
Invoice #:
` + orderid + `
Invoice Date:
` + date + `
Due Date:
` + date + `
To
` + custinfo + `
Terms (Cash/Debit Card):
Debit Card
Shipped via (Will call/Pick up):
Pick Up
F.O.B.:
N/A
Prepaid or Collect:
Collect
Discount code:
None
Percent Discount:
0.00 %
` + t_head + t_body + t_footer + `
Invoice Notes
SubTotal:
` + formatter.format(usdamount) + `
Credit:
` + formatter.format('0.0') + `
Tax:
` + ('0.0') + ` %
Total Amount Paid:
` + formatter.format(usdamount) + `
Balance Due:
` + formatter.format('0.00') + `
`;
var footer = `
`;
// data += "
"+header+t_head+tr+t_footer+footer;
var data = header + body + footer;
var myWindow = window.open("", "MsgWindow", "resizable=yes,top=100,left=300,width=800,height=600");
myWindow.document.write(data);
myWindow.print();
myWindow.close();
return false;
});
// trigger when btnListOrder is clicked
$(document).on('submit', '#listorder_form', function() {
// validate jwt to verify access
var jwt = getCookie('jwt');
// get form data
var listorder_form=$(this);
// get form data
var listorder_form_obj = listorder_form.serializeObject();
// add jwt on the object
listorder_form_obj.jwt = jwt;
listorder_form_obj.email = email;
var form_data = JSON.stringify(listorder_form_obj);
listOrder(form_data);
return false;
});
// trigger when btnGetInvoice is clicked
$(document).on('submit', '#listinvoice_form', function() {
// validate jwt to verify access
var jwt = getCookie('jwt');
// get form data
var listinvoice_form=$(this);
// get form data
var listinvoice_form_obj = listinvoice_form.serializeObject();
// add jwt on the object
listinvoice_form_obj.jwt = jwt;
var form_data=JSON.stringify(listinvoice_form_obj);
$.when( showInvoicePage() ).done ( listInvoice(form_data) );
return false;
});
// trigger when registration form is submitted here
$(document).on('submit', '#sign_up_form', function() {
if ( $('#pwd').val() !== $('#confirmsignuppassword').val()) {
$('#response').html("
Password mismatch.
");
return false;
}
// get form data
var sign_up_form=$(this);
var form_data=JSON.stringify(sign_up_form.serializeObject());
// submit form data to api
$.ajax({
url: "/mdstore/api/create_user.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result) {
if ( result.message === "Failed") {
$('#response').html("
Unable to create the account. " + result.reason + "
");
} else {
// if response is a success, tell the user it was a successful creation & empty the input boxes
$('#response').html("
" + result.message + "
");
sign_up_form.find('input').val('');
}
},
error: function(xhr, resp, text){
// on error, tell the user created failed
$('#response').html("
Unable to create the account. " + text + "
");
}
});
return false;
});
// show login form trigger will be here
$(document).on('click', '#login', function(){
// alert('test');
showLoginPage();
});
// trigger when login form is submitted
$(document).on('submit', '#login_form', function() {
loginStatus = "";
$("#loginProgressModal").modal({
backdrop: 'static',
keyboard: false
});
var intervalId = "";
updateProgressModal(function(i_id) {
intervalId = i_id;
});
// get form data
var login_form=$(this);
var form_data=JSON.stringify(login_form.serializeObject());
// submit form data to api
$.ajax({
url: "/mdstore/api/login.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result){
var jwt = result.jwt;
// Set Global Variable after succesful authentication
email = result.email;
phone = result.phone;
// store jwt to cookie
setCookie("jwt", jwt, 1);
loginStatus = true;
// alert('loginStatus: ' + loginStatus);
// $('#response').html("
Successful login.
");
// $('#cfLogin').html("
Successful login.
");
},
// error response will be here
error: function(xhr, resp, text){
loginStatus = false;
// on error, tell the user login has failed & empty the input boxes
// $('#response').html("
Login failed. Email or password is incorrect.
");
$('#cfLogin').html("
Login failed. Email or password is incorrect.
");
// login_form.find('input').val('');
}
});
$.when( showLoginProgress(intervalId) )
.done ( function() {
// Submit the from data to process function
clearInterval(intervalId);
$('#loginProgressModal').modal('hide');
showLoggedInMenu();
showHomePage();
$("#loginProgressModal").removeData('bs.modal');
})
.then(function() {
; // alert('being notified'); // to recieved notification
})
.fail(function() {
//alert("Recieved reject from confirmation function.");
// alert('fail reject');
$('#loginProgressModal').modal('hide');
// $("#loginProgressModal").removeData('bs.modal');
})
;
return false;
});
function showLoginProgress(i_id) {
// alert('showLoginProgress id: ' + i_id);
var displayDone = false;
var timer;
$(document).on('shown.bs.modal', '#loginProgressModal', function() {
displayDone = true;
});
function checkLoginStatus() {
// alert(loginStatus);
return loginStatus;
}
var deferred = $.Deferred();
timer = setInterval( function() {
var _loginstatus = checkLoginStatus();
if ( displayDone && _loginstatus !== "" ) {
if ( _loginstatus ) {
clearInterval(timer);
deferred.resolve();
} else {
clearInterval(timer);
deferred.reject();
}
} else {
deferred.notify();
}
}, 500);
// default timeout
setTimeout(function() {
clearInterval(timer);
deferred.reject();
}, 10000);
return deferred.promise();
}
function updateProgressModal(callback) {
var percentVal = 0;
let intervalId = window.setInterval(frame, 20);
function frame() {
if (percentVal === 100)
{
// clearInterval(intervalId);
} else {
percentVal++;
$('.progress-bar').css("width", percentVal+ '%').attr("aria-valuenow", (percentVal)+ '%');
}
}
callback(intervalId);
}
$(document).on('hidden.bs.modal', '#loginProgressModal', function() {
var percentVal = 0;
$('.progress-bar').css("width", percentVal+ '%').attr("aria-valuenow", (percentVal)+ '%');
// alert('reset bar');
});
$(document).on('hidden.bs.modal', '#orderProgressModal', function() {
var percentVal = 0;
$('.progress-bar').css("width", percentVal+ '%').attr("aria-valuenow", (percentVal)+ '%');
// alert('reset bar');
});
// trigger when order form is submitted
$(document).on('submit', '#order_form', function() {
$("#orderProgressModal").modal({
backdrop: 'static',
keyboard: false
});
var intervalId = "";
updateProgressModal(function(i_id) {
intervalId = i_id;
});
// handle for order_form
var order_form=$(this);
// validate jwt to verify access
var jwt = getCookie('jwt');
// get form data and jwt here
// get form data
var order_form_obj = order_form.serializeObject();
// add jwt on the object
order_form_obj.jwt = jwt;
order_form_obj.phone = phone;
order_form_obj.email = email;
order_form_obj.maxamt = maxamt;
order_form_obj.availamt = availamt;
// convert object to json string
var form_data = JSON.stringify(order_form_obj);
//alert (form_data);
// http request will be here
// submit form data to api
$.ajax({
url: "/mdstore/api/order.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result){
// store jwt to cookie
setCookie("jwt", result.jwt, 1);
order_form.find('input').val('');
updateOrderPageFooter();
$('#cbOrderPage').prop('checked', false);
$('#response').html("
" + result.message + " Your order id is:
" + result.orderid + "
");
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
" + text + ": Order is greater than you avaiable limit for today.
");
order_form.find('input').val('');
}
});
$.when( showOrderProgress(intervalId) )
.done ( function() {
// Submit the from data to process function
clearInterval(intervalId);
$('#orderProgressModal').modal('hide');
})
.then(function() {
// alert('being notified'); // to recieved notification
})
.fail(function() {
//alert("Recieved reject from confirmation function.");
})
;
return false;
});
function showOrderProgress(i_id) {
// alert('showLoginProgress id: ' + i_id);
var displayDone = false;
var timer;
$(document).on('shown.bs.modal', '#orderProgressModal', function() {
displayDone = true;
});
var deferred = $.Deferred();
timer = setInterval( function() {
if (displayDone) {
clearInterval(timer);
deferred.resolve();
}
deferred.notify();
}, 1000);
setTimeout(function() {
clearInterval(timer);
deferred.resolve();
}, 10000);
return deferred.promise();
}
// trigger when enter key is pressed
$(document).on('keyup keypress', '#process_form', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
$('#btnProcessOrder').focus();
return false;
}
});
// trigger when process form button is clicked
$(document).on('submit', '#process_form', function() {
if (purchaseAmount == 0 || btcSymbol === "" ) {
$('#response').html("
Please pull order before processing.
");
return false;
}
// handle for order_form
var process_form=$(this);
// validate jwt to verify access
var jwt = getCookie('jwt');
// get form data
var process_form_obj = process_form.serializeObject();
// Add form properties
process_form_obj.orderid = orderID;
process_form_obj.btcsymbol = btcSymbol;
// add jwt on the object
process_form_obj.jwt = jwt;
// convert object to json string
var form_data = JSON.stringify(process_form_obj);
// alert("process_form:" + form_data);
var question = "Please collect the funds (cash or debit) and click continue.";
$.when( confirmation(question) )
.done ( function() {
// Submit the from data to process function
processForm(form_data);
})
.fail(function() {
//alert("Recieved reject from confirmation function.");
})
;
return false;
});
// trigger when show home page link
$(document).on('click', '#home , #orderArrowLeft, #btnResetOrder', function(){
showHomePage();
});
// trigger when show update account form
$(document).on('click', '#update_account, #listorderArrowRight, #btnMenuUpdateAccount', function(){
showUpdateAccountForm();
});
// trigger when 'update account' form is submitted
$(document).on('submit', '#update_account_form', function(){
// handle for update_account_form
var update_account_form=$(this);
const attr = $('#password').attr('required');
if (typeof attr !== 'undefined' && attr !== false && $('#password').val() !== $('#confirmpassword').val() ) {
$('#response').html("
Password doesn't match.
");
return false;
}
// validate jwt to verify access
var jwt = getCookie('jwt');
// get form data and jwt here
// get form data
var update_account_form_obj = update_account_form.serializeObject();
// add jwt on the object
update_account_form_obj.jwt = jwt;
//alert("password: " + update_account_form_obj.password);
// convert object to json string
var form_data=JSON.stringify(update_account_form_obj);
// send data to api here
// submit form data to api
$.ajax({
url: "/mdstore/api/update_user.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result) {
// tell the user account was updated
$('#response').html("
Account was updated.
");
// store new jwt to coookie
setCookie("jwt", result.jwt, 1);
},
// errors will be handled here
// show error message to user
error: function(xhr, resp, text){
if(xhr.responseJSON.message=="Unable to update user."){
$('#response').html("
");
});
// trigger when btcamount changes
$(document).on('change', '#btcamount', function() {
_btcamount = $(this).val();
updateDialog("btc", _btcamount);
});
// trigger when purchase amount changes
$(document).on('change', '#amount', function() {
_amount = $(this).val();
updatePurchase();
updateDialog("amount", _amount);
});
// trigger when purchase amount changes
$(document).on('change', '#pctfee', function() {
_pctfee = $(this).val();
updatePurchase();
updateDialog("null", _pctfee);
});
//////////////////////////////////////////////
//
// FUNCTIONS
//
/////////////////////////////////////////////
// update the dialog box when changes occurs
function updateDialog(key, value) {
switch (key) {
case "title":
title = value;
break;
case "amount":
purchaseAmount = value;
break;
case "btc":
btcAmount = value;
break;
case "symbol":
btcSymbol = value;
break;
case "wallet":
btcWallet = value;
break;
default:
}
// $('#modaltitle').html('
' + title + '
');
$('#modalbody').html('' + title + '');
// $('#modalbody').append(' BTC Amount: ' + btcAmount);
// $('#modalbody').append(' Crypto: ' + btcSymbol);
// $('#modalbody').append(' Wallet: ' + btcWallet);
}
// Process onder when dialog box return true
function processForm(form_data) {
// alert(form_data);
// http request will be here
// submit form data to api
$.when( process_order(form_data) )
.done (process_withdrawal)
.fail(function() {
// alert( "Failed to process your order. Check status log.");
});
return false;
}
// trigger when process_button is pressed
// Get response from dialog box
function confirmation(question) {
updateDialog('title', question);
return $.Deferred( function() {
var self = this;
const modal = new Promise(function(resolveFunc, rejectFunc){
$('#modalDialog').modal('show');
$(document).on('click', '#btnYes', function(){
//resolveFunc("User clicked");
self.resolve();
});
$(document).on('click', '#btnNo', function(){
//rejectFunc("User clicked cancel");
self.reject();
});
});
return false;
});
}
// Reset user passwrod
//
function resetPassword(_email) {
var reset_form = $("", { action:'' });
// get form data
var reset_form_obj = reset_form.serializeObject();
// add jwt on the object
reset_form_obj.email = _email;
var form_data=JSON.stringify(reset_form_obj);
$.ajax({
url: "/mdstore/api/resetpasswd.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result) {
$('#response').html("
Your reset link has been sent. Please check your inbox.
");
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
Error: " + "You've entered an email that is missing or inactive." + "
");
}
});
// $('#login_form').find('input').val('');
$('#email').val('');
$('#password').val('');
$('#cbAck').prop('checked', false);
return false;
}
// triggered when customer id is pulled from database
// Get the Balance from account
function getBalance() {
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
$.ajax({
url: "api/get_balance.php",
type : "GET",
contentType : 'application/json',
success : function(result) {
$.each(result, function () {
switch ( this.currencySymbol ) {
case "BTC":
$('#btcbal').html("BTC Balance: " + this.available);
break;
case "USD":
var value = parseFloat(this.available);
var amount = formatter.format(value);
$('#usdbal').html("USD Avail: " + amount);
break;
case "ETH":
$('#ethbal').html("ETH Balance: " + this.available);
}
// $('#btcrate').html("
BTC Exchange Rate: " + result.crypto + "
");
});
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
Order number is incorrect or missing.
");
$('#order_form').find('input').val('');
}
});
return false;
}
// Set deferred function for getRate
function getBTCRate() {
return $.Deferred(function() { // <-- see returning Deferred object
var self = this;
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
$.ajax({
url: "api/get_rate.php?symbol=" + btcSymbol,
type : "GET",
contentType : 'application/json',
success : function(result) {
askRate = result.askRate;
var value = parseFloat(result.askRate);
var amount = formatter.format(value);
btcAmount = amount; // Assign to Global variable to process_form
$('#btcrate').html("Exch Rate: " + amount);
self.resolve(); // <-- call resolve method once async is done
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
Problem retreiving Exchange Rate.
");
// order_form.find('input').val('');
success = false;
self.reject();
}
});
return false;
});
}
// Calcaute the fees and btc
function updatePurchase() {
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
var storefee = 1.50;
var amount = $("#amount").val();
var _pctfee = $("#pctfee").val();
var _numfee = parseFloat(_pctfee).toFixed(2);
var pctfee = _numfee / 100.0;
var feeamount = (amount * pctfee) + storefee; // 0.075 for percentage
var netamount = amount - feeamount;
var btcamount = netamount / askRate;
btcAmount = btcamount.toFixed(8); // Assign to Global variable to process_form
fee = feeamount; // Assing to global variable
netAmount = netamount; // Assign to global variable
$('#pctfee').val(_numfee + " %");
$('#pctamount').html(formatter.format(feeamount));
$('#netamount').html(formatter.format(netamount));
$('#btcamount').val(btcAmount);
}
// Function to process order
function process_order(form_data) {
return $.Deferred(function() { // <-- see returning Deferred object
var self = this;
// http request will be here
// submit form data to api
$.ajax({
url: "api/create_order.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result){
// store jwt to cookie
// setCookie("jwt", result.jwt, 1);
if ( typeof result.code !== "undefined" ) {
$('#response').html("
");
self.reject();
}
});
return false;
});
}
// Cancel Order
function cancel_order(i_orderid) {
// validate jwt to verify access
var jwt = getCookie('jwt');
// get form data
// var btn_order=$(this);
var btn_order_form = $("", { action:'' });
// get form data
var btn_order_form_obj = btn_order_form.serializeObject();
// add jwt on the object
btn_order_form_obj.jwt = jwt;
btn_order_form_obj.orderid = i_orderid;
var form_data=JSON.stringify(btn_order_form_obj);
$.ajax({
url: "/mdstore/api/cancel_order.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result) {
// if response is a success, tell the user it was a successful creation & empty the input boxes
$('#response').html("
" + result.message + "
");
//$('#listorder').click();
display_order();
},
error: function(xhr, resp, text){
// on error, tell the user created failed
$('#response').html("
Unable to cancel the order. Please contact admin.
");
}
});
}
// Display Order
function display_order() {
// validate jwt to verify access
var jwt = getCookie('jwt');
// Create a form to handle post data
var listorder_form = $("", { action:'' });
// get form data
var listorder_form_obj = listorder_form.serializeObject();
// add jwt on the object
listorder_form_obj.jwt = jwt;
listorder_form_obj.email = email;
var form_data = JSON.stringify(listorder_form_obj);
/*
// Create a deferred object;
var defShowList = $.Deferred();
$.when( defShowList ).done ( listOrder );
// Call the resolved
defShowList.resolve( showListPage(form_data) );
*/
listOrder(form_data);
return false;
}
// Function for withdrawal
function process_withdrawal() {
alert('Continue with widrawal process');
var postInfo = {
"currencySymbol": btcSymbol,
"quantity": btcAmount,
"cryptoAddress": btcWallet
};
// validate jwt to verify access
var jwt = getCookie('jwt');
// Create a form to handle post data
var withdrawal_form = $("", { action:'' });
// get form data and jwt here
// get form data
var withdrawal_form_obj = withdrawal_form.serializeObject();
// Add form variabled for post
withdrawal_form_obj.currencySymbol = postInfo.currencySymbol;
withdrawal_form_obj.quantity = postInfo.quantity;
//withdrawal_form_obj.quantity = "0.0";
withdrawal_form_obj.cryptoAddress = postInfo.cryptoAddress;
withdrawal_form_obj.orderID = orderID;
withdrawal_form_obj.askRate = askRate;
withdrawal_form_obj.btcAmount = btcAmount;
withdrawal_form_obj.purchaseAmount = purchaseAmount;
withdrawal_form_obj.btcWallet = btcWallet;
withdrawal_form_obj.phone = phone;
withdrawal_form_obj.fee = fee;
withdrawal_form_obj.netAmount = netAmount;
withdrawal_form_obj.entrydate = entrydate;
// add jwt on the object
withdrawal_form_obj.jwt = jwt;
// convert object to json string
var form_data = JSON.stringify(withdrawal_form_obj);
$.ajax({
url: "api/withdraw_crypto.php",
type : "POST",
contentType : 'application/json',
data : form_data,
success : function(result){
// store jwt to cookie
// setCookie("jwt", result.jwt, 1);
// alert('success withdrawal');
if ( typeof result.code != "undefined" ) {
$('#response').html("
");
}
// show home page & tell the user it was a successful login
// showHomePage();
//$('#response').html("");
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
Failed to submit order." + text + "
");
process_form.find('input').val('');
}
});
}
// List Order Funciton
function listOrder(in_form_data) {
// http request will be here
// submit form data to api
$.ajax({
url: "/mdstore/api/list_order.php",
type : "POST",
contentType : 'application/json',
data : in_form_data,
success : function(result){
var tr_body = "";
$.each(result, function () {
//alert(this.orderid);
if ( typeof this.orderid !== "undefined" ) {
var tr = '
';
// $("#listRecords tbody").append(tr);
tr_body = tr_body + tr;
}
// alert(this.orderid);
});
showListPage(tr_body);
// alert(result[1].jwt);
// store jwt to cookie
setCookie("jwt", result[1].jwt, 1);
// show home page & tell the user it was a successful login
// showHomePage();
// $('#response').html("
" + result[0].message + "
");
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
" + text + "
");
// alert(text);
}
});
return false;
}
// List Order Funciton
//
function listInvoice(in_form_data) {
// http request will be here
// submit form data to api
$.ajax({
url: "api/list_invoice.php",
type : "POST",
contentType : 'application/json',
data : in_form_data,
success : function(result){
$.each(result, function () {
if ( typeof this.orderid !== "undefined" ) {
var tr = '
';
$("#listInvoices tbody").append(tr);
}
// alert(this.orderid);
});
// alert(result[1].jwt);
// store jwt to cookie
setCookie("jwt", result[1].jwt, 1);
// show home page & tell the user it was a successful login
// showHomePage();
$('#response').html("
" + result[0].message + "
");
},
// error response will be here
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("
" + text + "
");
// alert(text);
}
});
return false;
}
// clearResponse() will be here
// remove any prompt messages
function clearResponse(){
$('#response').html('');
}
// showLoginPage() will be here
// show login page
function showLoginPage(){
// remove jwt
setCookie("jwt", "", 1);
// login page html
var html = `
Logging in...
Login Page
`;
clearResponse();
$('#content').html(html);
showLoggedOutMenu();
return false;
}
// setCookie() will be here
// function to set cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
// showLoggedInMenu() will be here
// if the user is logged in
function showLoggedInMenu(){
// hide login and create account from navbar & show logout button
$("#login").hide();
$("#sign_up").hide();
$("#products").hide();
$("#services").hide();
$("#about").hide();
$("#contact").hide();
$("#logout, #order, #listorder, #update_account").show();
}
// showLoggedOutMenu() will be here
// if the user is logged out
function showLoggedOutMenu(){
// show login and create account from navbar & hide logout button
$("#login").show();
$("#sign_up").show();
$("#products").show();
$("#services").show();
$("#about").show();
$("#contact").show();
$("#logout, #order, #listorder, #update_account").hide();
}
$(document).on('click', '#goBack', function () {
parent.history.back();
return false;
});
// showOrder Page will be here
// if the user is logged out
function showOrderPage(){
// validate jwt to verify access
var jwt = getCookie('jwt');
$.post("/mdstore/auth/api/validate_token.php", JSON.stringify({jwt:jwt })).done(function(result) {
var html = `
");
});
return false;
}
// showHomePage() function will be here
// show home page
function showHomePage(){
// validate jwt to verify access
var jwt = getCookie('jwt');
// location.reload(true);
$.post("/mdstore/auth/api/validate_token.php", JSON.stringify({jwt:jwt })).done(function(result) {
var _fname = result.data.firstname;
var _lname = result.data.lastname;
var _email = result.data.email;
// login page html
var html = `
Home Page
Quick Access
Create Order
List Orders
Account Update
Our Products
Party Store
Airsoft and Accesories
Cell Phones and Accesories
Dollar Items
Our Services
Comcast Pre-paid Internet Sevice
Need internet access without having the hassle of being on a contract. Try Comcast Internet pre-paid. No need for any rental equipment or credit check.
Pre-paid Cell Phone Sevice
If your bills are ggetting to much every phone, take alook how to can save on pre-paid services. We carry Verizon, Ultra Mobile, H2O, Go-Smart, Net10, and Simple Mobile.
Digital Assets Service
If you want to own your first digital currency, come by we will guide you through the process. You will have your first digital currency before you leave our store.
Disclaimer: We do not provide investment advice and any information contained herein is not intended to be a source of advice or investment analysis with respect to the information presented, and the information and/or documents contained in this website do not constitute investment advice.
Who we are?
History
We have been in business since 2014 and continues to strive to provide better quality products and services. You will find party items, helium balloons, greetings cards, household goods and other dollar items. In addition, we are Authorize provider for Verizon, Ultra Mobile, and TracFone owned pre-paid services like Net10, Simple Mobile, Page Plus and GoSmart. We accept payment for all your services needs and long distance through Boss Revolution. And if you need to trade any Crypto-currency, come down to our store and we will assist and guide you to the process and owning your first Digital Currency.
The Future
Be part of our future and growth and we will changed the world one transaction at a time
Contact Us
Company Information
33720 9th Ave. S., Suite 7, Federal Way, Washington. 98003.
Phone: 253-344-1408 | FAX: 253-344-1537 | Email: info@monsterdollar.net
You can leave us a message or comment below. Thank you.
");
});
return false;
}
// getCookie() will be here
// get or read cookie
function getCookie(cname){
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i
Account Page
`;
clearResponse();
$('#content').html(html);
showLoggedInMenu();
})
// error message when jwt is invalid will be here
// on error/fail, tell the user he needs to login to show the account page
.fail(function(result){
showLoginPage();
$('#response').html("
Please login to access the account page.
");
});
// return false;
}
// serializeObject will be here
// function to make form values to json format
$.fn.serializeObject = function(){
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
});