Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Hive BuyCraft Implementation
- *
- * Wanted more functionality than the awesome BuyCraft default.
- * Please don't copy this. It'll _will_ break your store.
- *
- * Frog
- **/
- HiveBuyCraft = {
- //Init
- init: function () {
- this.setupClipboards();
- this.setupClickEvents();
- },
- //Sets up "Click to Copy"
- setupClipboards: function () {
- var clipboard = new Clipboard('.clip');
- clipboard.on('success', function (e) {
- e.trigger.innerHTML = "Copied to Clipboard";
- return false;
- });
- },
- //Sets up the Modals
- setupClickEvents: function () {
- //On Model Open
- $(".modal-btn").click(function (event) {
- event.preventDefault();
- var package = $(event.currentTarget).data("modal-package");
- if (package != null) {
- HiveBuyCraft.showModal(package);
- }
- });
- //BuyCraft Modal Override
- $(".toggle-modal").click(function (event) {
- event.preventDefault();
- var remote = $(event.currentTarget).data("remote");
- if (remote != null) {
- HiveBuyCraft.showModalCustom(remote);
- }
- });
- //Close modal on clicks outside of it
- $("#hive-modal").click(function (event) {
- if (event.currentTarget == event.target) {
- HiveBuyCraft.hideModal();
- }
- });
- //Close modal on "X"
- $(".close-modal").click(function (event) {
- event.preventDefault();
- HiveBuyCraft.hideModal();
- });
- },
- //Shows a model for a package
- showModal: function (packageID) {
- $.ajax({
- url: "/package/" + packageID, success: function (data) {
- $('#hive-modal').html(data);
- $('#hive-modal').show();
- }, async: true
- });
- },
- //Shows a custom modal
- showModalCustom: function (customUrl) {
- $.ajax({
- url: customUrl, success: function (data) {
- $('#hive-modal').html(data);
- $('#hive-modal').show();
- }, async: true
- });
- },
- hideModal: function () {
- $('#hive-modal').hide();
- $('#hive-modal').html("");
- return false;
- },
- showNotification: function () {
- setTimeout(function () {
- $('#notification-bar').slideDown();
- }, 500);
- setTimeout(function () {
- $('#notification-bar').slideUp();
- }, 10000);
- },
- checkPaySafeCard: function() {
- $.getJSON('https://storeredirect.hivemc.com/paysafecard.php', function(data) {
- if( data.result ) {
- $("#paysafecard").show();
- }
- });
- }
- }
- HiveCheckout = {
- hasErroredAlready: false,
- setupCheckout: function () {
- $("#packages .update").click(function (event) {
- event.preventDefault();
- $("#packages").submit();
- });
- },
- doCheckout: function (gateway, type) {
- if (!($("input[name='agreement']:checked").length > 0)) {
- $(".box .terms p").addClass("error");
- if(HiveCheckout.hasErroredAlready) {
- alert("Please agree to our Terms and Conditions and Privacy Policy.");
- }
- HiveCheckout.hasErroredAlready = true;
- return;
- }
- if (!($("input[name='privacyConsent']:checked").length > 0)) {
- $(".box .privacyStatement p").addClass("error");
- if(HiveCheckout.hasErroredAlready) {
- alert("Please agree to our Terms and Conditions and Privacy Policy.");
- }
- HiveCheckout.hasErroredAlready = true;
- return;
- }
- $("#redirecting").fadeIn();
- $.post(
- "/checkout/pay",
- {
- gateway: gateway,
- type: type,
- agreement: true,
- privacyConsent: 1
- }
- ).done(function (data) {
- var json = $.parseJSON(data);
- if (json.type == "error") {
- alert("Something went wrong. \"" + json.message + "\". Please refresh and try again, or email accounts@hivemc.com.");
- } else if (json.type == "success") {
- if (json.gateway == "cashu") {
- var cashuForm = $('<form id="mapform" action="https://www.cashu.com/cgi-bin/pcashu.cgi" method="post"></form>');
- for (var key in json.data) {
- if (json.data.hasOwnProperty(key)) {
- cashuForm.append('<input type="hidden" name="' + key + '" value="' + json.data[key] + '" />');
- }
- }
- $('body').append(cashuForm);
- cashuForm.submit();
- } else {
- window.top.location.replace(json.data);
- }
- }
- }).fail(function () {
- alert("Failed to send request. Please make sure all addons are disabled such as adblockers. Please refresh and try again, or email accounts@hivemc.com");
- });
- },
- doFree: function() {
- if (!($("input[name='agreement']:checked").length > 0)) {
- $(".box .terms p").addClass("error");
- if(HiveCheckout.hasErroredAlready) {
- alert("Please agree to our Terms and Conditions and Privacy Policy.");
- }
- HiveCheckout.hasErroredAlready = true;
- return;
- }
- if (!($("input[name='privacyConsent']:checked").length > 0)) {
- $(".box .privacyStatement p").addClass("error");
- if(HiveCheckout.hasErroredAlready) {
- alert("Please agree to our Terms and Conditions and Privacy Policy.");
- }
- HiveCheckout.hasErroredAlready = true;
- return;
- }
- $("#freeform").submit();
- }
- }
- $(document).ready(function () {
- HiveBuyCraft.init();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement