Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. /**
  2. * Hive BuyCraft Implementation
  3. *
  4. * Wanted more functionality than the awesome BuyCraft default.
  5. * Please don't copy this. It'll _will_ break your store.
  6. *
  7. * Frog
  8. **/
  9.  
  10. HiveBuyCraft = {
  11.  
  12. //Init
  13. init: function () {
  14. this.setupClipboards();
  15. this.setupClickEvents();
  16. },
  17.  
  18. //Sets up "Click to Copy"
  19. setupClipboards: function () {
  20. var clipboard = new Clipboard('.clip');
  21.  
  22. clipboard.on('success', function (e) {
  23. e.trigger.innerHTML = "Copied to Clipboard";
  24. return false;
  25. });
  26. },
  27.  
  28. //Sets up the Modals
  29. setupClickEvents: function () {
  30. //On Model Open
  31. $(".modal-btn").click(function (event) {
  32. event.preventDefault();
  33. var package = $(event.currentTarget).data("modal-package");
  34. if (package != null) {
  35. HiveBuyCraft.showModal(package);
  36. }
  37. });
  38.  
  39. //BuyCraft Modal Override
  40. $(".toggle-modal").click(function (event) {
  41. event.preventDefault();
  42. var remote = $(event.currentTarget).data("remote");
  43. if (remote != null) {
  44. HiveBuyCraft.showModalCustom(remote);
  45. }
  46. });
  47.  
  48. //Close modal on clicks outside of it
  49. $("#hive-modal").click(function (event) {
  50. if (event.currentTarget == event.target) {
  51. HiveBuyCraft.hideModal();
  52. }
  53. });
  54.  
  55. //Close modal on "X"
  56. $(".close-modal").click(function (event) {
  57. event.preventDefault();
  58. HiveBuyCraft.hideModal();
  59. });
  60. },
  61.  
  62. //Shows a model for a package
  63. showModal: function (packageID) {
  64. $.ajax({
  65. url: "/package/" + packageID, success: function (data) {
  66. $('#hive-modal').html(data);
  67. $('#hive-modal').show();
  68. }, async: true
  69. });
  70. },
  71.  
  72. //Shows a custom modal
  73. showModalCustom: function (customUrl) {
  74. $.ajax({
  75. url: customUrl, success: function (data) {
  76. $('#hive-modal').html(data);
  77. $('#hive-modal').show();
  78. }, async: true
  79. });
  80. },
  81.  
  82. hideModal: function () {
  83. $('#hive-modal').hide();
  84. $('#hive-modal').html("");
  85. return false;
  86. },
  87.  
  88. showNotification: function () {
  89. setTimeout(function () {
  90. $('#notification-bar').slideDown();
  91. }, 500);
  92.  
  93. setTimeout(function () {
  94. $('#notification-bar').slideUp();
  95. }, 10000);
  96. },
  97.  
  98. checkPaySafeCard: function() {
  99. $.getJSON('https://storeredirect.hivemc.com/paysafecard.php', function(data) {
  100. if( data.result ) {
  101. $("#paysafecard").show();
  102. }
  103. });
  104. }
  105. }
  106.  
  107. HiveCheckout = {
  108.  
  109. hasErroredAlready: false,
  110.  
  111. setupCheckout: function () {
  112. $("#packages .update").click(function (event) {
  113. event.preventDefault();
  114. $("#packages").submit();
  115. });
  116. },
  117.  
  118. doCheckout: function (gateway, type) {
  119. if (!($("input[name='agreement']:checked").length > 0)) {
  120. $(".box .terms p").addClass("error");
  121.  
  122. if(HiveCheckout.hasErroredAlready) {
  123. alert("Please agree to our Terms and Conditions and Privacy Policy.");
  124. }
  125.  
  126. HiveCheckout.hasErroredAlready = true;
  127. return;
  128. }
  129.  
  130. if (!($("input[name='privacyConsent']:checked").length > 0)) {
  131. $(".box .privacyStatement p").addClass("error");
  132.  
  133. if(HiveCheckout.hasErroredAlready) {
  134. alert("Please agree to our Terms and Conditions and Privacy Policy.");
  135. }
  136.  
  137. HiveCheckout.hasErroredAlready = true;
  138. return;
  139. }
  140.  
  141. $("#redirecting").fadeIn();
  142.  
  143. $.post(
  144. "/checkout/pay",
  145. {
  146. gateway: gateway,
  147. type: type,
  148. agreement: true,
  149. privacyConsent: 1
  150. }
  151. ).done(function (data) {
  152. var json = $.parseJSON(data);
  153.  
  154. if (json.type == "error") {
  155. alert("Something went wrong. \"" + json.message + "\". Please refresh and try again, or email accounts@hivemc.com.");
  156. } else if (json.type == "success") {
  157. if (json.gateway == "cashu") {
  158. var cashuForm = $('<form id="mapform" action="https://www.cashu.com/cgi-bin/pcashu.cgi" method="post"></form>');
  159. for (var key in json.data) {
  160. if (json.data.hasOwnProperty(key)) {
  161. cashuForm.append('<input type="hidden" name="' + key + '" value="' + json.data[key] + '" />');
  162. }
  163. }
  164. $('body').append(cashuForm);
  165. cashuForm.submit();
  166. } else {
  167. window.top.location.replace(json.data);
  168. }
  169. }
  170. }).fail(function () {
  171. 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");
  172. });
  173. },
  174.  
  175. doFree: function() {
  176. if (!($("input[name='agreement']:checked").length > 0)) {
  177. $(".box .terms p").addClass("error");
  178.  
  179. if(HiveCheckout.hasErroredAlready) {
  180. alert("Please agree to our Terms and Conditions and Privacy Policy.");
  181. }
  182.  
  183. HiveCheckout.hasErroredAlready = true;
  184. return;
  185. }
  186.  
  187. if (!($("input[name='privacyConsent']:checked").length > 0)) {
  188. $(".box .privacyStatement p").addClass("error");
  189.  
  190. if(HiveCheckout.hasErroredAlready) {
  191. alert("Please agree to our Terms and Conditions and Privacy Policy.");
  192. }
  193.  
  194. HiveCheckout.hasErroredAlready = true;
  195. return;
  196. }
  197.  
  198. $("#freeform").submit();
  199. }
  200.  
  201. }
  202.  
  203. $(document).ready(function () {
  204. HiveBuyCraft.init();
  205. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement