@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/.babelrc +13 -4
  2. package/.eslintrc.js +3 -0
  3. package/.prettierrc.js +11 -0
  4. package/README.md +15 -314
  5. package/dist/events/base-event.js +6 -9
  6. package/dist/events/events.spec.js +4 -4
  7. package/dist/events/index.js +2 -1
  8. package/dist/functions/destroy.js +12 -14
  9. package/dist/functions/destroy.spec.js +3 -3
  10. package/dist/functions/mount/fetch-data.js +183 -0
  11. package/dist/functions/mount/fetch-data.spec.js +189 -0
  12. package/dist/functions/mount/index.js +158 -251
  13. package/dist/functions/mount/mount.spec.js +24 -121
  14. package/dist/functions/mount/setup-element.js +40 -0
  15. package/dist/functions/mount/setup-framepay.js +46 -0
  16. package/dist/functions/mount/setup-i18n.js +33 -0
  17. package/dist/functions/mount/setup-options.js +96 -0
  18. package/dist/functions/mount/setup-options.spec.js +66 -0
  19. package/dist/functions/mount/setup-storefront.js +34 -0
  20. package/dist/functions/mount/setup-styles.js +43 -0
  21. package/dist/functions/on.js +13 -4
  22. package/dist/functions/on.spec.js +19 -5
  23. package/dist/functions/purchase.js +139 -22
  24. package/dist/functions/purchase.spec.js +23 -19
  25. package/dist/functions/setup.js +85 -0
  26. package/dist/functions/setup.spec.js +87 -0
  27. package/dist/functions/show.js +31 -14
  28. package/dist/functions/show.spec.js +47 -18
  29. package/dist/functions/update.js +53 -27
  30. package/dist/functions/update.spec.js +40 -21
  31. package/dist/i18n/en.json +4 -1
  32. package/dist/i18n/es.json +4 -1
  33. package/dist/index.js +67 -56
  34. package/dist/index.spec.js +7 -27
  35. package/dist/loader/index.js +4 -3
  36. package/dist/storefront/index.js +33 -0
  37. package/dist/storefront/invoices.js +27 -0
  38. package/dist/storefront/models/base-model.js +18 -0
  39. package/dist/storefront/models/invoice-model.js +14 -0
  40. package/dist/storefront/models/plan-model.js +4 -35
  41. package/dist/storefront/models/product-model.js +4 -23
  42. package/dist/storefront/models/summary-model.js +12 -25
  43. package/dist/storefront/models/transaction-model.js +31 -0
  44. package/dist/storefront/payment-instruments.js +47 -0
  45. package/dist/storefront/payment-instruments.spec.js +55 -0
  46. package/dist/storefront/plans.js +15 -24
  47. package/dist/storefront/plans.spec.js +17 -44
  48. package/dist/storefront/products.js +16 -20
  49. package/dist/storefront/products.spec.js +25 -49
  50. package/dist/storefront/purchase.js +28 -16
  51. package/dist/storefront/purchase.spec.js +4 -22
  52. package/dist/storefront/ready-to-pay.js +26 -22
  53. package/dist/storefront/ready-to-pay.spec.js +25 -54
  54. package/dist/storefront/storefront.spec.js +1 -1
  55. package/dist/storefront/summary.js +27 -24
  56. package/dist/storefront/summary.spec.js +44 -86
  57. package/dist/storefront/transactions.js +27 -0
  58. package/dist/style/base/theme.js +3 -3
  59. package/dist/style/components/methods.js +43 -42
  60. package/dist/style/utils/color-values.js +1 -3
  61. package/dist/style/views/confirmation.js +0 -4
  62. package/dist/style/views/method-selector.js +1 -1
  63. package/dist/style/views/modal.js +3 -1
  64. package/dist/style/views/summary.js +5 -1
  65. package/dist/utils/format-currency.js +4 -2
  66. package/dist/utils/has-valid-css-selector.js +1 -1
  67. package/dist/utils/process-property-as-dom-element.js +0 -2
  68. package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
  69. package/dist/views/common/iframe/base-iframe.js +10 -2
  70. package/dist/views/common/iframe/modal-iframe.js +44 -3
  71. package/dist/views/confirmation.js +44 -20
  72. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  73. package/dist/views/method-selector/express-methods/google-pay.js +31 -0
  74. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  75. package/dist/views/method-selector/generate-digital-wallet.js +68 -0
  76. package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
  77. package/dist/views/method-selector/get-payment-methods.js +28 -8
  78. package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
  79. package/dist/views/method-selector/index.js +55 -86
  80. package/dist/views/method-selector/method-selector.spec.js +80 -69
  81. package/dist/views/method-selector/mount-express-methods.js +38 -62
  82. package/dist/views/method-selector/mount-methods.js +18 -18
  83. package/dist/views/modal.js +21 -15
  84. package/dist/views/result.js +13 -16
  85. package/dist/views/summary.js +170 -114
  86. package/dist/views/summary.spec.js +72 -76
  87. package/package.json +5 -4
  88. package/src/events/base-event.js +15 -17
  89. package/src/events/events.spec.js +6 -4
  90. package/src/events/index.js +6 -3
  91. package/src/functions/destroy.js +12 -13
  92. package/src/functions/destroy.spec.js +30 -31
  93. package/src/functions/mount/fetch-data.js +148 -0
  94. package/src/functions/mount/fetch-data.spec.js +238 -0
  95. package/src/functions/mount/index.js +129 -244
  96. package/src/functions/mount/mount.spec.js +35 -139
  97. package/src/functions/mount/setup-element.js +26 -0
  98. package/src/functions/mount/setup-framepay.js +41 -0
  99. package/src/functions/mount/setup-i18n.js +19 -0
  100. package/src/functions/mount/setup-options.js +100 -0
  101. package/src/functions/mount/setup-options.spec.js +60 -0
  102. package/src/functions/mount/setup-storefront.js +24 -0
  103. package/src/functions/mount/setup-styles.js +30 -0
  104. package/src/functions/on.js +13 -8
  105. package/src/functions/on.spec.js +30 -17
  106. package/src/functions/purchase.js +101 -19
  107. package/src/functions/purchase.spec.js +18 -18
  108. package/src/functions/setup.js +48 -0
  109. package/src/functions/setup.spec.js +98 -0
  110. package/src/functions/show.js +20 -10
  111. package/src/functions/show.spec.js +43 -22
  112. package/src/functions/update.js +50 -27
  113. package/src/functions/update.spec.js +57 -22
  114. package/src/i18n/en.json +4 -1
  115. package/src/i18n/es.json +4 -1
  116. package/src/i18n/i18n.spec.js +6 -4
  117. package/src/i18n/index.js +14 -11
  118. package/src/index.js +41 -52
  119. package/src/index.spec.js +8 -37
  120. package/src/loader/index.js +51 -47
  121. package/src/loader/loader.spec.js +26 -19
  122. package/src/storefront/index.js +37 -7
  123. package/src/storefront/invoices.js +11 -0
  124. package/src/storefront/models/base-model.js +10 -0
  125. package/src/storefront/models/invoice-model.js +3 -0
  126. package/src/storefront/models/plan-model.js +3 -35
  127. package/src/storefront/models/product-model.js +3 -23
  128. package/src/storefront/models/ready-to-pay-model.js +3 -3
  129. package/src/storefront/models/summary-model.js +15 -29
  130. package/src/storefront/models/transaction-model.js +19 -0
  131. package/src/storefront/payment-instruments.js +30 -0
  132. package/src/storefront/payment-instruments.spec.js +69 -0
  133. package/src/storefront/plans.js +16 -23
  134. package/src/storefront/plans.spec.js +25 -54
  135. package/src/storefront/products.js +18 -22
  136. package/src/storefront/products.spec.js +23 -54
  137. package/src/storefront/purchase.js +14 -14
  138. package/src/storefront/purchase.spec.js +17 -29
  139. package/src/storefront/ready-to-pay.js +26 -23
  140. package/src/storefront/ready-to-pay.spec.js +41 -71
  141. package/src/storefront/storefront.spec.js +1 -1
  142. package/src/storefront/summary.js +26 -22
  143. package/src/storefront/summary.spec.js +60 -109
  144. package/src/storefront/transactions.js +11 -0
  145. package/src/style/base/theme.js +10 -8
  146. package/src/style/base/theme.spec.js +4 -2
  147. package/src/style/browserslist.js +1 -3
  148. package/src/style/components/button.js +3 -1
  149. package/src/style/components/forms/checkbox.js +3 -1
  150. package/src/style/components/index.js +1 -1
  151. package/src/style/components/loader.js +3 -1
  152. package/src/style/components/methods.js +43 -42
  153. package/src/style/helpers/index.js +1 -1
  154. package/src/style/index.js +2 -1
  155. package/src/style/utils/color-values.js +4 -4
  156. package/src/style/vendor/framepay.js +1 -1
  157. package/src/style/vendor/postmate.js +1 -1
  158. package/src/style/views/confirmation.js +0 -4
  159. package/src/style/views/index.js +1 -1
  160. package/src/style/views/method-selector.js +1 -1
  161. package/src/style/views/modal.js +4 -2
  162. package/src/style/views/summary.js +5 -1
  163. package/src/utils/add-dom-element.js +12 -13
  164. package/src/utils/format-currency.js +6 -2
  165. package/src/utils/has-valid-css-selector.js +2 -2
  166. package/src/utils/is-dom-element.js +1 -1
  167. package/src/utils/process-property-as-dom-element.js +27 -24
  168. package/src/utils/sleep.js +1 -1
  169. package/src/views/__snapshots__/summary.spec.js.snap +103 -113
  170. package/src/views/common/iframe/base-iframe.js +12 -4
  171. package/src/views/common/iframe/event-listeners.js +6 -6
  172. package/src/views/common/iframe/index.js +1 -1
  173. package/src/views/common/iframe/method-iframe.js +3 -6
  174. package/src/views/common/iframe/modal-iframe.js +42 -6
  175. package/src/views/common/iframe/view-iframe.js +3 -5
  176. package/src/views/common/render-utilities.js +3 -3
  177. package/src/views/confirmation.js +34 -25
  178. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  179. package/src/views/method-selector/express-methods/google-pay.js +24 -0
  180. package/src/views/method-selector/express-methods/paypal.js +7 -0
  181. package/src/views/method-selector/generate-digital-wallet.js +51 -0
  182. package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
  183. package/src/views/method-selector/get-method-data.js +7 -4
  184. package/src/views/method-selector/get-payment-methods.js +38 -29
  185. package/src/views/method-selector/get-payment-methods.spec.js +26 -33
  186. package/src/views/method-selector/index.js +70 -99
  187. package/src/views/method-selector/method-selector.spec.js +88 -78
  188. package/src/views/method-selector/mount-express-methods.js +36 -60
  189. package/src/views/method-selector/mount-methods.js +32 -21
  190. package/src/views/modal.js +37 -23
  191. package/src/views/result.js +12 -15
  192. package/src/views/summary.js +169 -101
  193. package/src/views/summary.spec.js +99 -74
  194. package/tests/async-utilities.js +22 -0
  195. package/tests/mocks/rebilly-instruments-mock.js +89 -77
  196. package/tests/mocks/storefront-api-mock.js +8 -0
  197. package/tests/mocks/storefront-mock.js +17 -0
  198. package/dist/events/purchase-completed.js +0 -24
  199. package/dist/functions/initialize.js +0 -82
  200. package/dist/functions/initialize.spec.js +0 -34
  201. package/dist/functions/mount/fetch-summary-data.js +0 -31
  202. package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
  203. package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
  204. package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
  205. package/src/events/purchase-completed.js +0 -11
  206. package/src/functions/initialize.js +0 -74
  207. package/src/functions/initialize.spec.js +0 -38
  208. package/src/functions/mount/fetch-summary-data.js +0 -26
  209. package/src/functions/mount/fetch-summary-data.spec.js +0 -46
  210. package/src/views/method-selector/process-digital-wallet-options.js +0 -16
  211. package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
 
3
- var _summaryModel = _interopRequireDefault(require("@/storefront/models/summary-model"));
3
+ var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
4
4
 
5
- var _readyToPayModel = _interopRequireDefault(require("@/storefront/models/ready-to-pay-model"));
5
+ var _readyToPayModel = _interopRequireDefault(require("../../storefront/models/ready-to-pay-model"));
6
6
 
7
7
  var _loader = require("../../loader");
8
8
 
@@ -10,6 +10,14 @@ var _i18n = require("../../i18n");
10
10
 
11
11
  var _index = require("./index");
12
12
 
13
+ var _asyncUtilities = require("../../../tests/async-utilities");
14
+
15
+ var _storefrontMock = require("../../../tests/mocks/storefront-mock");
16
+
17
+ var _fetchData = require("../../functions/mount/fetch-data");
18
+
19
+ var _setupOptions = _interopRequireDefault(require("../../functions/mount/setup-options"));
20
+
13
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
22
 
15
23
  describe('Summary component', () => {
@@ -21,93 +29,96 @@ describe('Summary component', () => {
21
29
 
22
30
  class TestMountMethodSelectorInstance {
23
31
  constructor({
24
- configs = {},
25
32
  options = {},
26
33
  form = formElement,
27
34
  loader = new _loader.Loader(),
28
- translate = new _i18n.Translate(),
29
- zoidComponents = {}
35
+ translate = new _i18n.Translate()
30
36
  } = {}) {
31
- this.configs = configs;
32
- this.options = options;
37
+ this.options = (0, _setupOptions.default)({
38
+ options
39
+ });
33
40
  this.form = form;
34
41
  this.loader = loader;
35
42
  this.translate = translate;
36
- this.zoidComponents = zoidComponents;
37
- }
38
-
39
- mountMethodSelector(readyToPayAndSummary, ...args) {
40
- this.loader.DOM.form = this.form;
41
- return _index.MountMethodSelector.apply(this, args.concat(readyToPayAndSummary));
43
+ this.storefront = (0, _storefrontMock.MockStorefront)();
44
+ this.data = new _fetchData.DataInstance({
45
+ state: {
46
+ options
47
+ },
48
+ previewPurchase: new _summaryModel.default({
49
+ currency: 'USD',
50
+ lineItems: [{
51
+ type: 'debit',
52
+ description: 'My Awesome Product',
53
+ unitPrice: 30,
54
+ quantity: 1,
55
+ price: 30,
56
+ productId: 'my-awesome-product',
57
+ planId: 'my-awesome-product'
58
+ }, {
59
+ type: 'debit',
60
+ description: 'Awesome T-Shirt',
61
+ unitPrice: 20,
62
+ quantity: 2,
63
+ price: 40,
64
+ productId: 'my-app',
65
+ planId: 'awesome-t-shirt'
66
+ }],
67
+ subtotalAmount: 70,
68
+ taxAmount: 0,
69
+ shippingAmount: 0,
70
+ discountsAmount: 0,
71
+ total: 70
72
+ }),
73
+ readyToPay: [new _readyToPayModel.default({
74
+ method: 'payment-card',
75
+ feature: {
76
+ name: 'Google Pay',
77
+ merchantName: 'google-pay-merchant-name',
78
+ merchantOrigin: 'google-pay-merchant-origin'
79
+ },
80
+ brands: ['Visa'],
81
+ filters: []
82
+ })]
83
+ });
42
84
  }
43
85
 
44
86
  }
45
87
 
46
88
  const options = {
47
- intent: {
48
- countryCode: 'US',
49
- items: [{
50
- planId: 'my-awesome-product',
51
- quantity: 1,
52
- thumbnail: ''
53
- }, {
54
- planId: 'awesome-t-shirt',
55
- quantity: 2,
56
- thumbnail: ''
57
- }]
58
- },
59
- paymentInstruments: {
60
- compactExpressInstruments: true
61
- }
62
- };
63
- const summaryData = new _summaryModel.default({
64
- currency: "USD",
65
- lineItems: [{
66
- type: "debit",
67
- description: "My Awesome Product",
68
- unitPrice: 30,
69
- quantity: 1,
70
- price: 30,
71
- productId: "my-awesome-product",
72
- planId: "my-awesome-product"
89
+ websiteId: 'test-website-id',
90
+ countryCode: 'US',
91
+ items: [{
92
+ planId: 'my-awesome-product',
93
+ quantity: 1
73
94
  }, {
74
- type: "debit",
75
- description: "Awesome T-Shirt",
76
- unitPrice: 20,
77
- quantity: 2,
78
- price: 40,
79
- productId: "my-app",
80
- planId: "awesome-t-shirt"
95
+ planId: 'awesome-t-shirt',
96
+ quantity: 2
81
97
  }],
82
- subtotalAmount: 70,
83
- taxAmount: 0,
84
- shippingAmount: 0,
85
- discountsAmount: 0,
86
- total: 70
87
- });
88
- const readyToPayData = [new _readyToPayModel.default({
89
- method: 'payment-card',
90
- feature: {
91
- name: 'Google Pay',
92
- merchantName: 'google-pay-merchant-name',
93
- merchantOrigin: 'google-pay-merchant-origin'
94
- },
95
- brands: ['Visa'],
96
- filters: []
97
- })];
98
- const configs = {
99
- websiteId: 'test-website-id'
98
+ _computed: {
99
+ paymentMethodsUrl: ''
100
+ }
100
101
  };
101
- it('should inject the proper HTML for express methods', () => {
102
+ it('should inject the proper HTML for express methods', async () => {
102
103
  const mountSummaryInstance = new TestMountMethodSelectorInstance({
103
- configs,
104
104
  options
105
105
  });
106
- mountSummaryInstance.mountMethodSelector({
107
- summary: summaryData,
108
- readyToPay: readyToPayData
106
+ mountSummaryInstance.loader.DOM.form = mountSummaryInstance.form;
107
+ (0, _index.mountMethodSelector)({
108
+ state: mountSummaryInstance
109
109
  });
110
110
  const form = document.querySelector('.rebilly-instruments-form');
111
111
  expect(form).toMatchSnapshot();
112
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
113
+ });
114
+ it('should allow updating method selector', async () => {
115
+ const state = new TestMountMethodSelectorInstance({
116
+ options
117
+ });
118
+ state.loader.DOM.form = state.form;
119
+ await (0, _index.updateMethodSelector)({
120
+ state,
121
+ mainStyle: 'any main style'
122
+ });
112
123
  });
113
124
  });
@@ -5,88 +5,64 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.mountExpressMethods = mountExpressMethods;
7
7
 
8
- var _iframe = require("../common/iframe");
8
+ var _googlePay = _interopRequireDefault(require("./express-methods/google-pay"));
9
9
 
10
- var _getMethodData = require("./get-method-data");
11
-
12
- /* eslint-disable no-undef */
13
- async function mountGooglePay({
14
- methodId
15
- }) {
16
- const container = document.querySelector('.rebilly-instruments-express-methods');
17
- const {
18
- paymentMethodsUrl
19
- } = this.options._computed;
20
- const model = {
21
- configs: this.configs,
22
- options: this.options
23
- };
24
- const iframe = await new _iframe.MethodIframe({
25
- name: methodId,
26
- url: `${paymentMethodsUrl}/${methodId}`,
27
- container,
28
- model
29
- });
30
- iframe.bindEventListeners({
31
- loader: this.loader
32
- });
33
- this.iframeComponents.push(iframe);
34
- }
10
+ var _applePay = _interopRequireDefault(require("./express-methods/apple-pay"));
35
11
 
36
- function mountApplePay({
37
- EXPRESS_METHODS_CONTAINER,
38
- METHOD_ID,
39
- METHOD_TYPE
40
- }) {
41
- EXPRESS_METHODS_CONTAINER.innerHTML += `
42
- <div id="rebilly-instruments-${METHOD_ID}" data-rebilly-instruments-express-type="${METHOD_TYPE}"></div>
43
- `;
44
- Rebilly.applePay.mount(`#rebilly-instruments-${METHOD_ID}`);
45
- Rebilly.on('token-ready', token => {
46
- dispatch('instrument-ready', token);
47
- });
48
- }
12
+ var _paypal = _interopRequireDefault(require("./express-methods/paypal"));
49
13
 
50
- function mountPaypal() {
51
- console.log('PayPal - work in progress');
52
- this.loader.stopLoading({
53
- id: 'paypal-express'
54
- });
55
- }
14
+ var _getMethodData = require("./get-method-data");
56
15
 
57
- const browserIsSafari = () => window.ApplePaySession;
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58
17
 
59
18
  function mountExpressMethods({
19
+ state,
60
20
  EXPRESS_METHODS,
61
21
  EXPRESS_METHODS_CONTAINER
62
22
  }) {
23
+ // A child div for each method must be created before mounting.
24
+ // Any DOM operation (innerHTML, append, etc) done on the parent div (EXPRESS_METHODS_CONTAINER) in between
25
+ // the two Postmate's instantiation (1 parent, 1 child) will cause the parent <-> child handshake to fail
26
+ EXPRESS_METHODS.forEach(expressMethod => {
27
+ const {
28
+ METHOD_ID
29
+ } = (0, _getMethodData.getMethodData)(expressMethod);
30
+ EXPRESS_METHODS_CONTAINER.innerHTML += `
31
+ <div class="rebilly-instruments-${METHOD_ID}-method"></div>
32
+ `;
33
+ });
63
34
  EXPRESS_METHODS.forEach(expressMethod => {
64
35
  const {
65
36
  method,
66
37
  feature
67
38
  } = expressMethod;
68
- const methodData = (0, _getMethodData.getMethodData)(expressMethod);
69
-
70
- if (method === 'paypal') {
71
- mountPaypal.call(this);
72
- }
73
-
74
- ;
39
+ const {
40
+ METHOD_ID,
41
+ METHOD_TYPE
42
+ } = (0, _getMethodData.getMethodData)(expressMethod);
75
43
 
76
44
  if ((feature === null || feature === void 0 ? void 0 : feature.name) === 'Google Pay') {
77
- mountGooglePay.call(this, {
78
- methodId: methodData.METHOD_ID
45
+ (0, _googlePay.default)({
46
+ state,
47
+ METHOD_ID
79
48
  });
80
49
  }
81
50
 
82
- if ((feature === null || feature === void 0 ? void 0 : feature.name) === 'Apple Pay' && browserIsSafari()) {
83
- mountApplePay.call(this, {
84
- EXPRESS_METHODS_CONTAINER,
85
- ...methodData
51
+ if ((feature === null || feature === void 0 ? void 0 : feature.name) === 'Apple Pay') {
52
+ (0, _applePay.default)({
53
+ state,
54
+ METHOD_ID,
55
+ METHOD_TYPE,
56
+ EXPRESS_METHODS,
57
+ EXPRESS_METHODS_CONTAINER
86
58
  });
87
- } else {
88
- this.loader.stopLoading({
89
- id: 'payment-card-express'
59
+ }
60
+
61
+ if (method === 'paypal') {
62
+ (0, _paypal.default)({
63
+ state,
64
+ METHOD_ID,
65
+ METHOD_TYPE
90
66
  });
91
67
  }
92
68
  });
@@ -7,6 +7,8 @@ exports.MountMethods = MountMethods;
7
7
 
8
8
  var _lodash = _interopRequireDefault(require("lodash.camelcase"));
9
9
 
10
+ var _modal = require("../modal");
11
+
10
12
  var _iframe = require("../common/iframe");
11
13
 
12
14
  var _getMethodData = require("./get-method-data");
@@ -14,14 +16,12 @@ var _getMethodData = require("./get-method-data");
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  function MountMethods({
19
+ state,
17
20
  METHODS_CONTAINER,
18
- METHODS,
19
- mainStyle,
20
- plans,
21
- products
21
+ METHODS
22
22
  }) {
23
23
  METHODS.forEach(async method => {
24
- var _this$options$payment;
24
+ var _state$options$paymen;
25
25
 
26
26
  const {
27
27
  METHOD_ID: methodId,
@@ -29,16 +29,15 @@ function MountMethods({
29
29
  } = (0, _getMethodData.getMethodData)(method);
30
30
  const {
31
31
  paymentMethodsUrl
32
- } = this.options._computed || 'https://www.example.com';
32
+ } = state.options._computed || 'https://www.example.com';
33
33
  const selector = `rebilly-instruments-${methodId}`;
34
- const isiFrame = methodId === 'payment-card' && !((_this$options$payment = this.options.paymentInstruments[methodType]) !== null && _this$options$payment !== void 0 && _this$options$payment.popup);
34
+ const isiFrame = methodId === 'payment-card' && !((_state$options$paymen = state.options.paymentInstruments[methodType]) !== null && _state$options$paymen !== void 0 && _state$options$paymen.popup);
35
35
  const model = {
36
- configs: this.configs,
37
- options: this.options,
38
- mainStyle,
39
- method,
40
- plans,
41
- products
36
+ options: state.options,
37
+ mainStyle: state.mainStyle,
38
+ plans: state.data.plans,
39
+ products: state.data.products,
40
+ method
42
41
  };
43
42
  METHODS_CONTAINER.insertAdjacentHTML('beforeend', `<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`);
44
43
  const container = document.querySelector(`#${selector}`);
@@ -51,22 +50,23 @@ function MountMethods({
51
50
  model
52
51
  });
53
52
  iframe.bindEventListeners({
54
- loader: this.loader,
53
+ loader: state.loader,
55
54
  id: method.method
56
55
  });
57
- this.iframeComponents.push(iframe);
56
+ state.iframeComponents.push(iframe);
58
57
  } else {
59
58
  container.insertAdjacentHTML('beforeend', `<button class="${selector} rebilly-instruments-button" data-rebilly-i18n="paymentMethods.${method.method}">${(0, _lodash.default)(method.method)}</button>`);
60
59
  const paymentCardButton = document.querySelector(`.${selector}`);
61
60
  paymentCardButton.addEventListener('click', async () => {
62
- const iframe = await this._mountModal.call(this, {
61
+ const iframe = await (0, _modal.mountModal)({
62
+ state,
63
63
  name: methodId,
64
64
  url: `${paymentMethodsUrl}/${methodId}`,
65
65
  model
66
66
  });
67
- this.iframeComponents.push(iframe);
67
+ state.iframeComponents.push(iframe);
68
68
  });
69
- this.loader.stopLoading({
69
+ state.loader.stopLoading({
70
70
  id: method.method
71
71
  });
72
72
  }
@@ -3,33 +3,36 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.MountModal = MountModal;
6
+ exports.mountModal = mountModal;
7
7
 
8
8
  var _iframe = require("./common/iframe");
9
9
 
10
10
  const modalTemplate = (isRedirect, method) => `
11
11
  <div class="rebilly-instruments-modal-overlay">
12
12
  <div class="rebilly-instruments-modal-container ${method ? `rebilly-instruments-${method}` : ''} ${isRedirect ? 'is-redirect' : ''}">
13
+ ${isRedirect ? '' : `
13
14
  <svg class="rebilly-instruments-modal-close" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
14
15
  <path d="m15 13.5858 7.2929-7.293c.3905-.3904 1.0237-.3904 1.4142 0 .3905.3906.3905 1.0238 0 1.4143L16.4142 15l7.293 7.2929c.3904.3905.3904 1.0237 0 1.4142-.3906.3905-1.0238.3905-1.4143 0L15 16.4142l-7.2929 7.293c-.3905.3904-1.0237.3904-1.4142 0-.3905-.3906-.3905-1.0238 0-1.4143L13.5858 15l-7.293-7.2929c-.3904-.3905-.3904-1.0237 0-1.4142.3906-.3905 1.0238-.3905 1.4143 0L15 13.5858Z" fill-rule="nonzero"/>
15
16
  </svg>
17
+ `}
16
18
  <div class="rebilly-instruments-modal-content"></div>
17
19
  </div>
18
20
  </div>
19
21
  `;
20
22
 
21
- async function MountModal({
23
+ async function mountModal({
22
24
  name = '',
23
25
  url = '',
24
26
  model = {},
25
27
  classListArray = [],
26
- close = () => {}
28
+ close = () => {},
29
+ state = null
27
30
  } = {}) {
28
- const {
29
- method
30
- } = model === null || model === void 0 ? void 0 : model.method;
31
+ var _model$method;
32
+
33
+ const method = model === null || model === void 0 ? void 0 : (_model$method = model.method) === null || _model$method === void 0 ? void 0 : _model$method.method;
31
34
  const isRedirect = name === 'rebilly-instruments-approval-url';
32
- this.form.insertAdjacentHTML('beforeend', modalTemplate(isRedirect, method));
35
+ state.form.insertAdjacentHTML('beforeend', modalTemplate(isRedirect, method));
33
36
  const modalOverlay = document.querySelector('.rebilly-instruments-modal-overlay');
34
37
  const modalContainer = document.querySelector('.rebilly-instruments-modal-container');
35
38
  const closeButton = document.querySelector('.rebilly-instruments-modal-close');
@@ -39,20 +42,20 @@ async function MountModal({
39
42
  modalOverlay.classList.add('is-visible');
40
43
  modalContainer.classList.add('is-visible');
41
44
  }, 240);
42
- this.loader.addDOMElement({
45
+ state.loader.addDOMElement({
43
46
  section: 'modal',
44
47
  el: modalContent
45
48
  });
46
- this.loader.startLoading({
49
+ state.loader.startLoading({
47
50
  section: 'modal',
48
51
  id: 'modal-content'
49
52
  });
50
53
  const injectedModel = {
51
- configs: this.configs,
52
- options: this.options,
54
+ options: state.options,
53
55
  ...model
54
56
  };
55
57
  const iframe = await new _iframe.ModalIframe({
58
+ state,
56
59
  name,
57
60
  url,
58
61
  model: injectedModel,
@@ -68,15 +71,18 @@ async function MountModal({
68
71
  modalOverlay.children.forEach(child => child.remove());
69
72
  modalOverlay.remove();
70
73
  close(...args);
71
- iframe.component.destroy();
74
+ iframe.destroy();
72
75
  }, 300);
73
76
  };
74
77
 
75
78
  iframe.bindEventListeners({
76
79
  close: closeModal,
77
- loader: this.loader
80
+ loader: state.loader
78
81
  });
79
- modalOverlay.addEventListener('click', closeModal);
80
- closeButton.addEventListener('click', closeModal);
82
+
83
+ if (!isRedirect) {
84
+ closeButton.addEventListener('click', closeModal);
85
+ }
86
+
81
87
  return iframe;
82
88
  }
@@ -3,30 +3,29 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.MountResult = MountResult;
6
+ exports.mountResult = mountResult;
7
7
 
8
8
  var _iframe = require("./common/iframe");
9
9
 
10
10
  var _renderUtilities = require("./common/render-utilities");
11
11
 
12
- async function MountResult({
13
- purchase,
14
- mainStyle
12
+ async function mountResult({
13
+ payload,
14
+ state
15
15
  }) {
16
16
  const resultContainerClassName = 'rebilly-instruments-result';
17
- (0, _renderUtilities.replaceContent)(this.form, `<div class="${resultContainerClassName}"></div>`);
18
- this.loader.startLoading({
17
+ (0, _renderUtilities.replaceContent)(state.form, `<div class="${resultContainerClassName}"></div>`);
18
+ state.loader.startLoading({
19
19
  id: 'result'
20
20
  });
21
21
  const container = document.querySelector(`.${resultContainerClassName}`);
22
22
  const {
23
23
  paymentMethodsUrl
24
- } = this.options._computed;
24
+ } = state.options._computed;
25
25
  const model = {
26
- configs: this.configs,
27
- options: this.options,
28
- mainStyle,
29
- purchase
26
+ options: state.options,
27
+ mainStyle: state.mainStyle,
28
+ [state.options.transactionType]: payload
30
29
  };
31
30
  const iframe = await new _iframe.ViewIframe({
32
31
  name: 'rebilly-instruments-result',
@@ -35,9 +34,7 @@ async function MountResult({
35
34
  model
36
35
  });
37
36
  iframe.bindEventListeners({
38
- loader: this.loader
37
+ loader: state.loader
39
38
  });
40
- this.iframeComponents.push(iframe);
41
- }
42
-
43
- ;
39
+ state.iframeComponents.push(iframe);
40
+ }