function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
$(function () {
$("#submit-order, #submit-order1").click(function () {
if (!$("#agree").prop('checked')) {
alert("You must check \"I agree to the Prestige Time Policies & Terms & Conditions\"");
} else {
// submit and redirect to checkout flow
affirm.checkout.post();
}
})
});
if (typeof (watch_price) !== 'undefined') {
var _affirm_config = {
public_api_key: getParameterByName("preowned") == "1" ? "9XXSO9352YLD61BG" : "V6AOKPR6P97798J6",
script: "https://cdn1.affirm.com/js/v2/affirm.js",
mode: 'modal',
};
(function (l, g, m, e, a, f, b) {
var d, c = l[m] || {}, h = document.createElement(f), n = document.getElementsByTagName(f)[0], k = function (a, b, c) {
return function () {
a[b]._.push([c, arguments])
}
};
c[e] = k(c, e, "set");
d = c[e];
c[a] = {};
c[a]._ = [];
d._ = [];
c[a][b] = k(c, a, b);
a = 0;
for (b = "set add save post open empty reset on off trigger ready setProduct".split(" "); a < b.length; a++)d[b[a]] = k(c, e, b[a]);
a = 0;
for (b = ["get", "token", "url", "items"]; a < b.length; a++)d[b[a]] = function () {
};
h.async = !0;
h.src = g[f];
n.parentNode.insertBefore(h, n);
delete g[f];
d(g);
l[m] = c
})(window, _affirm_config, "affirm", "checkout", "ui", "script", "ready");
affirm.ui.ready(function () {
updateAffirmAsLowAs(watch_price)
}); // change to your template value for product or cart price
function updateAffirmAsLowAs(amount) {
if ((amount == null) || (amount < 1000)) {
return;
} // Only display as low as for items over $10 CHANGE FOR A DIFFERENT LIMIT
// payment estimate options
var options = {
apr: "0.10", // percentage assumed APR for loan
months: 18, // can be 3, 6, or 12
amount: amount // USD cents
};
try {
typeof affirm.ui.payments.get_estimate;
/* try and access the function */
}
catch (e) {
return;
/* stops this function from going any further - affirm functions are not loaded and will throw an error */
}
// use the payment estimate response
function handleEstimateResponse(payment_estimate) {
// the payment comes back in USD cents
var dollars = ((payment_estimate.payment + 99) / 100) | 0; // get dollars, round up, and convert to int
// Set affirm payment text
var a = document.getElementById('learn-more');
var iText = ('innerHTML' in a) ? 'innerHTML' : 'textContent';
//a[iText] = "Starting at $" + dollars + " a month. Learn More";
a[iText] = '
Financing available with payments as low as $' + dollars + '/month.';
// open the customized Affirm learn more modal
a.onclick = payment_estimate.open_modal;
a.style.visibility = "visible";
}
// request a payment estimate
affirm.ui.payments.get_estimate(options, handleEstimateResponse);
}
}