billing-agreement.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'Magento_Ui/js/modal/confirm',
  8. 'Magento_Customer/js/customer-data'
  9. ], function ($, confirm, customerData) {
  10. 'use strict';
  11. $.widget('mage.billingAgreement', {
  12. options: {
  13. invalidateOnLoad: false,
  14. cancelButtonSelector: '.block-billing-agreements-view button.cancel',
  15. cancelMessage: '',
  16. cancelUrl: ''
  17. },
  18. /**
  19. * Initialize billing agreements events
  20. * @private
  21. */
  22. _create: function () {
  23. var self = this;
  24. if (this.options.invalidateOnLoad) {
  25. this.invalidate();
  26. }
  27. $(this.options.cancelButtonSelector).on('click', function () {
  28. confirm({
  29. content: self.options.cancelMessage,
  30. actions: {
  31. /**
  32. * 'Confirm' action handler.
  33. */
  34. confirm: function () {
  35. self.invalidate();
  36. window.location.href = self.options.cancelUrl;
  37. }
  38. }
  39. });
  40. return false;
  41. });
  42. },
  43. /**
  44. * clear paypal billing agreement customer data
  45. * @returns void
  46. */
  47. invalidate: function () {
  48. customerData.invalidate(['paypal-billing-agreement']);
  49. }
  50. });
  51. return $.mage.billingAgreement;
  52. });