button.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'uiComponent',
  7. 'jquery',
  8. 'Magento_Paypal/js/in-context/express-checkout-wrapper',
  9. 'Magento_Customer/js/customer-data'
  10. ], function (Component, $, Wrapper, customerData) {
  11. 'use strict';
  12. return Component.extend(Wrapper).extend({
  13. defaults: {
  14. declinePayment: false
  15. },
  16. /** @inheritdoc */
  17. initialize: function (config, element) {
  18. var cart = customerData.get('cart'),
  19. customer = customerData.get('customer');
  20. this._super();
  21. this.renderPayPalButtons(element);
  22. this.declinePayment = !customer().firstname && !cart().isGuestCheckoutAllowed;
  23. return this;
  24. },
  25. /** @inheritdoc */
  26. beforePayment: function (resolve, reject) {
  27. var promise = $.Deferred();
  28. if (this.declinePayment) {
  29. this.addError(this.signInMessage, 'warning');
  30. reject();
  31. } else {
  32. promise.resolve();
  33. }
  34. return promise;
  35. },
  36. /** @inheritdoc */
  37. prepareClientConfig: function () {
  38. this._super();
  39. this.clientConfig.commit = false;
  40. return this.clientConfig;
  41. }
  42. });
  43. });