@rebilly/instruments 1.0.2-beta.9 → 3.0.0-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 (255) 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 +187 -0
  11. package/dist/functions/mount/fetch-data.spec.js +189 -0
  12. package/dist/functions/mount/index.js +164 -251
  13. package/dist/functions/mount/mount.spec.js +25 -124
  14. package/dist/functions/mount/setup-element.js +40 -0
  15. package/dist/functions/mount/setup-framepay-theme.js +95 -0
  16. package/dist/functions/mount/setup-framepay.js +46 -0
  17. package/dist/functions/mount/setup-i18n.js +33 -0
  18. package/dist/functions/mount/setup-options.js +99 -0
  19. package/dist/functions/mount/setup-options.spec.js +66 -0
  20. package/dist/functions/mount/setup-storefront.js +34 -0
  21. package/dist/functions/mount/setup-styles.js +43 -0
  22. package/dist/functions/on.js +13 -4
  23. package/dist/functions/on.spec.js +19 -5
  24. package/dist/functions/purchase.js +139 -22
  25. package/dist/functions/purchase.spec.js +23 -19
  26. package/dist/functions/setup.js +85 -0
  27. package/dist/functions/setup.spec.js +87 -0
  28. package/dist/functions/show.js +31 -14
  29. package/dist/functions/show.spec.js +47 -18
  30. package/dist/functions/update.js +53 -27
  31. package/dist/functions/update.spec.js +40 -21
  32. package/dist/i18n/en.json +5 -2
  33. package/dist/i18n/es.json +4 -1
  34. package/dist/index.js +67 -56
  35. package/dist/index.spec.js +7 -27
  36. package/dist/loader/index.js +4 -3
  37. package/dist/storefront/index.js +33 -0
  38. package/dist/storefront/invoices.js +27 -0
  39. package/dist/storefront/models/base-model.js +18 -0
  40. package/dist/storefront/models/invoice-model.js +14 -0
  41. package/dist/storefront/models/plan-model.js +4 -35
  42. package/dist/storefront/models/product-model.js +4 -23
  43. package/dist/storefront/models/summary-model.js +12 -25
  44. package/dist/storefront/models/transaction-model.js +31 -0
  45. package/dist/storefront/payment-instruments.js +47 -0
  46. package/dist/storefront/payment-instruments.spec.js +55 -0
  47. package/dist/storefront/plans.js +15 -24
  48. package/dist/storefront/plans.spec.js +17 -44
  49. package/dist/storefront/products.js +16 -20
  50. package/dist/storefront/products.spec.js +25 -49
  51. package/dist/storefront/purchase.js +28 -16
  52. package/dist/storefront/purchase.spec.js +4 -22
  53. package/dist/storefront/ready-to-pay.js +26 -22
  54. package/dist/storefront/ready-to-pay.spec.js +25 -54
  55. package/dist/storefront/storefront.spec.js +1 -1
  56. package/dist/storefront/summary.js +27 -24
  57. package/dist/storefront/summary.spec.js +44 -86
  58. package/dist/storefront/transactions.js +27 -0
  59. package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
  60. package/dist/style/base/default-theme.js +699 -0
  61. package/dist/style/base/index.js +48 -16
  62. package/dist/style/base/theme.js +15 -48
  63. package/dist/style/base/theme.spec.js +4 -15
  64. package/dist/style/components/address.js +3 -3
  65. package/dist/style/components/button.js +32 -22
  66. package/dist/style/components/divider.js +9 -9
  67. package/dist/style/components/forms/checkbox.js +12 -9
  68. package/dist/style/components/forms/field.js +18 -6
  69. package/dist/style/components/forms/form.js +2 -2
  70. package/dist/style/components/forms/input.js +54 -13
  71. package/dist/style/components/forms/label.js +44 -18
  72. package/dist/style/components/forms/select.js +54 -22
  73. package/dist/style/components/forms/validation.js +53 -6
  74. package/dist/style/components/icons.js +4 -4
  75. package/dist/style/components/loader.js +5 -3
  76. package/dist/style/components/methods.js +52 -48
  77. package/dist/style/components/overlay.js +5 -5
  78. package/dist/style/helpers/index.js +46 -46
  79. package/dist/style/index.js +3 -1
  80. package/dist/style/payment-instruments/payment-card.js +4 -4
  81. package/dist/style/utils/border.js +47 -0
  82. package/dist/style/utils/color-values.js +37 -3
  83. package/dist/style/utils/remove-empty-null.js +20 -0
  84. package/dist/style/vendor/framepay.js +11 -8
  85. package/dist/style/vendor/postmate.js +2 -2
  86. package/dist/style/views/confirmation.js +13 -13
  87. package/dist/style/views/method-selector.js +3 -3
  88. package/dist/style/views/modal.js +8 -6
  89. package/dist/style/views/result.js +4 -4
  90. package/dist/style/views/summary.js +26 -22
  91. package/dist/utils/format-currency.js +4 -2
  92. package/dist/utils/has-valid-css-selector.js +1 -1
  93. package/dist/utils/process-property-as-dom-element.js +0 -2
  94. package/dist/views/__snapshots__/summary.spec.js.snap +72 -118
  95. package/dist/views/common/iframe/base-iframe.js +10 -2
  96. package/dist/views/common/iframe/modal-iframe.js +50 -4
  97. package/dist/views/confirmation.js +44 -20
  98. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  99. package/dist/views/method-selector/express-methods/google-pay.js +31 -0
  100. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  101. package/dist/views/method-selector/generate-digital-wallet.js +68 -0
  102. package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
  103. package/dist/views/method-selector/get-payment-methods.js +27 -7
  104. package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
  105. package/dist/views/method-selector/index.js +55 -86
  106. package/dist/views/method-selector/method-selector.spec.js +80 -69
  107. package/dist/views/method-selector/mount-express-methods.js +38 -62
  108. package/dist/views/method-selector/mount-methods.js +18 -18
  109. package/dist/views/modal.js +18 -12
  110. package/dist/views/result.js +13 -16
  111. package/dist/views/summary.js +176 -114
  112. package/dist/views/summary.spec.js +72 -76
  113. package/package.json +7 -4
  114. package/src/events/base-event.js +15 -17
  115. package/src/events/events.spec.js +6 -4
  116. package/src/events/index.js +6 -3
  117. package/src/functions/destroy.js +12 -13
  118. package/src/functions/destroy.spec.js +30 -31
  119. package/src/functions/mount/fetch-data.js +152 -0
  120. package/src/functions/mount/fetch-data.spec.js +238 -0
  121. package/src/functions/mount/index.js +131 -244
  122. package/src/functions/mount/mount.spec.js +35 -141
  123. package/src/functions/mount/setup-element.js +26 -0
  124. package/src/functions/mount/setup-framepay-theme.js +82 -0
  125. package/src/functions/mount/setup-framepay.js +41 -0
  126. package/src/functions/mount/setup-i18n.js +19 -0
  127. package/src/functions/mount/setup-options.js +103 -0
  128. package/src/functions/mount/setup-options.spec.js +60 -0
  129. package/src/functions/mount/setup-storefront.js +24 -0
  130. package/src/functions/mount/setup-styles.js +30 -0
  131. package/src/functions/on.js +13 -8
  132. package/src/functions/on.spec.js +30 -17
  133. package/src/functions/purchase.js +101 -19
  134. package/src/functions/purchase.spec.js +18 -18
  135. package/src/functions/setup.js +48 -0
  136. package/src/functions/setup.spec.js +98 -0
  137. package/src/functions/show.js +20 -10
  138. package/src/functions/show.spec.js +43 -22
  139. package/src/functions/update.js +50 -27
  140. package/src/functions/update.spec.js +57 -22
  141. package/src/i18n/en.json +5 -2
  142. package/src/i18n/es.json +4 -1
  143. package/src/i18n/i18n.spec.js +6 -4
  144. package/src/i18n/index.js +14 -11
  145. package/src/index.js +41 -52
  146. package/src/index.spec.js +8 -37
  147. package/src/loader/index.js +51 -47
  148. package/src/loader/loader.spec.js +26 -19
  149. package/src/storefront/index.js +37 -7
  150. package/src/storefront/invoices.js +11 -0
  151. package/src/storefront/models/base-model.js +10 -0
  152. package/src/storefront/models/invoice-model.js +3 -0
  153. package/src/storefront/models/plan-model.js +3 -35
  154. package/src/storefront/models/product-model.js +3 -23
  155. package/src/storefront/models/ready-to-pay-model.js +3 -3
  156. package/src/storefront/models/summary-model.js +15 -29
  157. package/src/storefront/models/transaction-model.js +19 -0
  158. package/src/storefront/payment-instruments.js +30 -0
  159. package/src/storefront/payment-instruments.spec.js +69 -0
  160. package/src/storefront/plans.js +16 -23
  161. package/src/storefront/plans.spec.js +25 -54
  162. package/src/storefront/products.js +18 -22
  163. package/src/storefront/products.spec.js +23 -54
  164. package/src/storefront/purchase.js +14 -14
  165. package/src/storefront/purchase.spec.js +17 -29
  166. package/src/storefront/ready-to-pay.js +26 -23
  167. package/src/storefront/ready-to-pay.spec.js +41 -71
  168. package/src/storefront/storefront.spec.js +1 -1
  169. package/src/storefront/summary.js +26 -22
  170. package/src/storefront/summary.spec.js +60 -109
  171. package/src/storefront/transactions.js +11 -0
  172. package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
  173. package/src/style/base/default-theme.js +674 -0
  174. package/src/style/base/index.js +48 -16
  175. package/src/style/base/theme.js +20 -48
  176. package/src/style/base/theme.spec.js +5 -15
  177. package/src/style/browserslist.js +1 -3
  178. package/src/style/components/address.js +3 -3
  179. package/src/style/components/button.js +32 -22
  180. package/src/style/components/divider.js +9 -9
  181. package/src/style/components/forms/checkbox.js +11 -9
  182. package/src/style/components/forms/field.js +18 -6
  183. package/src/style/components/forms/form.js +2 -2
  184. package/src/style/components/forms/input.js +54 -13
  185. package/src/style/components/forms/label.js +44 -18
  186. package/src/style/components/forms/select.js +54 -22
  187. package/src/style/components/forms/validation.js +53 -6
  188. package/src/style/components/icons.js +4 -4
  189. package/src/style/components/index.js +1 -1
  190. package/src/style/components/loader.js +4 -3
  191. package/src/style/components/methods.js +52 -48
  192. package/src/style/components/overlay.js +5 -5
  193. package/src/style/helpers/index.js +46 -46
  194. package/src/style/index.js +4 -2
  195. package/src/style/payment-instruments/payment-card.js +4 -4
  196. package/src/style/utils/border.js +34 -0
  197. package/src/style/utils/color-values.js +30 -4
  198. package/src/style/utils/remove-empty-null.js +10 -0
  199. package/src/style/vendor/framepay.js +12 -9
  200. package/src/style/vendor/postmate.js +3 -3
  201. package/src/style/views/confirmation.js +13 -13
  202. package/src/style/views/index.js +1 -1
  203. package/src/style/views/method-selector.js +3 -3
  204. package/src/style/views/modal.js +9 -7
  205. package/src/style/views/result.js +4 -4
  206. package/src/style/views/summary.js +26 -22
  207. package/src/utils/add-dom-element.js +12 -13
  208. package/src/utils/format-currency.js +6 -2
  209. package/src/utils/has-valid-css-selector.js +2 -2
  210. package/src/utils/is-dom-element.js +1 -1
  211. package/src/utils/process-property-as-dom-element.js +27 -24
  212. package/src/utils/sleep.js +1 -1
  213. package/src/views/__snapshots__/summary.spec.js.snap +72 -118
  214. package/src/views/common/iframe/base-iframe.js +12 -4
  215. package/src/views/common/iframe/event-listeners.js +6 -6
  216. package/src/views/common/iframe/index.js +1 -1
  217. package/src/views/common/iframe/method-iframe.js +3 -6
  218. package/src/views/common/iframe/modal-iframe.js +48 -6
  219. package/src/views/common/iframe/view-iframe.js +3 -5
  220. package/src/views/common/render-utilities.js +3 -3
  221. package/src/views/confirmation.js +34 -25
  222. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  223. package/src/views/method-selector/express-methods/google-pay.js +24 -0
  224. package/src/views/method-selector/express-methods/paypal.js +7 -0
  225. package/src/views/method-selector/generate-digital-wallet.js +51 -0
  226. package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
  227. package/src/views/method-selector/get-method-data.js +7 -4
  228. package/src/views/method-selector/get-payment-methods.js +38 -31
  229. package/src/views/method-selector/get-payment-methods.spec.js +26 -33
  230. package/src/views/method-selector/index.js +70 -99
  231. package/src/views/method-selector/method-selector.spec.js +88 -78
  232. package/src/views/method-selector/mount-express-methods.js +36 -60
  233. package/src/views/method-selector/mount-methods.js +32 -21
  234. package/src/views/modal.js +36 -22
  235. package/src/views/result.js +12 -15
  236. package/src/views/summary.js +175 -101
  237. package/src/views/summary.spec.js +99 -74
  238. package/tests/async-utilities.js +22 -0
  239. package/tests/mocks/rebilly-instruments-mock.js +89 -77
  240. package/tests/mocks/storefront-api-mock.js +8 -0
  241. package/tests/mocks/storefront-mock.js +17 -0
  242. package/dist/events/purchase-completed.js +0 -24
  243. package/dist/functions/initialize.js +0 -82
  244. package/dist/functions/initialize.spec.js +0 -34
  245. package/dist/functions/mount/fetch-summary-data.js +0 -31
  246. package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
  247. package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
  248. package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
  249. package/src/events/purchase-completed.js +0 -11
  250. package/src/functions/initialize.js +0 -74
  251. package/src/functions/initialize.spec.js +0 -38
  252. package/src/functions/mount/fetch-summary-data.js +0 -26
  253. package/src/functions/mount/fetch-summary-data.spec.js +0 -46
  254. package/src/views/method-selector/process-digital-wallet-options.js +0 -16
  255. package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
@@ -2,109 +2,119 @@ import SummaryModel from '@/storefront/models/summary-model';
2
2
  import ReadyToPayModel from '@/storefront/models/ready-to-pay-model';
3
3
  import { Loader } from '../../loader';
4
4
  import { Translate } from '../../i18n';
5
- import { MountMethodSelector } from './index';
5
+ import { mountMethodSelector, updateMethodSelector } from './index';
6
+ import { avoidUnhandledPromises } from 'tests/async-utilities';
7
+ import { MockStorefront } from 'tests/mocks/storefront-mock';
8
+ import { DataInstance } from '../../functions/mount/fetch-data';
9
+ import setupOptions from '../../functions/mount/setup-options';
6
10
 
7
11
  describe('Summary component', () => {
8
12
  let formElement;
9
13
  beforeEach(() => {
10
14
  formElement = document.createElement('div');
11
15
  document.body.append(formElement);
12
- })
16
+ });
13
17
 
14
18
  class TestMountMethodSelectorInstance {
15
19
  constructor({
16
- configs = {},
17
20
  options = {},
18
21
  form = formElement,
19
22
  loader = new Loader(),
20
- translate = new Translate(),
21
- zoidComponents = {},
23
+ translate = new Translate()
22
24
  } = {}) {
23
- this.configs = configs;
24
- this.options = options;
25
+ this.options = setupOptions({options});
25
26
  this.form = form;
26
27
  this.loader = loader;
27
28
  this.translate = translate;
28
- this.zoidComponents = zoidComponents;
29
- }
30
-
31
- mountMethodSelector(readyToPayAndSummary, ...args) {
32
- this.loader.DOM.form = this.form;
33
- return MountMethodSelector.apply(this, args.concat(readyToPayAndSummary));
29
+ this.storefront = MockStorefront();
30
+ this.data = new DataInstance({
31
+ state: {options},
32
+ previewPurchase: new SummaryModel({
33
+ currency: 'USD',
34
+ lineItems: [
35
+ {
36
+ type: 'debit',
37
+ description: 'My Awesome Product',
38
+ unitPrice: 30,
39
+ quantity: 1,
40
+ price: 30,
41
+ productId: 'my-awesome-product',
42
+ planId: 'my-awesome-product'
43
+ },
44
+ {
45
+ type: 'debit',
46
+ description: 'Awesome T-Shirt',
47
+ unitPrice: 20,
48
+ quantity: 2,
49
+ price: 40,
50
+ productId: 'my-app',
51
+ planId: 'awesome-t-shirt'
52
+ }
53
+ ],
54
+ subtotalAmount: 70,
55
+ taxAmount: 0,
56
+ shippingAmount: 0,
57
+ discountsAmount: 0,
58
+ total: 70
59
+ }),
60
+ readyToPay: [
61
+ new ReadyToPayModel({
62
+ method: 'payment-card',
63
+ feature: {
64
+ name: 'Google Pay',
65
+ merchantName: 'google-pay-merchant-name',
66
+ merchantOrigin: 'google-pay-merchant-origin'
67
+ },
68
+ brands: ['Visa'],
69
+ filters: []
70
+ }),
71
+ ]
72
+ });
34
73
  }
35
74
  }
36
75
 
37
76
  const options = {
38
- intent: {
39
- countryCode: 'US',
40
- items: [
41
- {
42
- planId: 'my-awesome-product',
43
- quantity: 1,
44
- thumbnail: '',
45
- },
46
- {
47
- planId: 'awesome-t-shirt',
48
- quantity: 2,
49
- thumbnail: '',
50
- }
51
- ]
52
- },
53
- paymentInstruments: {
54
- compactExpressInstruments: true
55
- },
56
- };
57
-
58
- const summaryData = new SummaryModel({
59
- currency: "USD",
60
- lineItems: [{
61
- type: "debit",
62
- description: "My Awesome Product",
63
- unitPrice: 30,
64
- quantity: 1,
65
- price: 30,
66
- productId: "my-awesome-product",
67
- planId: "my-awesome-product"
68
- }, {
69
- type: "debit",
70
- description: "Awesome T-Shirt",
71
- unitPrice: 20,
72
- quantity: 2,
73
- price: 40,
74
- productId: "my-app",
75
- planId: "awesome-t-shirt"
76
- }],
77
- subtotalAmount: 70,
78
- taxAmount: 0,
79
- shippingAmount: 0,
80
- discountsAmount: 0,
81
- total: 70
82
- });
83
-
84
- const readyToPayData = [
85
- new ReadyToPayModel(
77
+ websiteId: 'test-website-id',
78
+ countryCode: 'US',
79
+ items: [
80
+ {
81
+ planId: 'my-awesome-product',
82
+ quantity: 1
83
+ },
86
84
  {
87
- method: 'payment-card',
88
- feature: {
89
- name: 'Google Pay',
90
- merchantName: 'google-pay-merchant-name',
91
- merchantOrigin: 'google-pay-merchant-origin'
92
- },
93
- brands: ['Visa'],
94
- filters: []
85
+ planId: 'awesome-t-shirt',
86
+ quantity: 2
95
87
  }
96
- )
97
- ];
98
-
99
- const configs = {
100
- websiteId: 'test-website-id'
88
+ ],
89
+ _computed: {
90
+ paymentMethodsUrl: ''
91
+ }
101
92
  };
102
93
 
103
- it('should inject the proper HTML for express methods', () => {
104
- const mountSummaryInstance = new TestMountMethodSelectorInstance({configs, options});
105
- mountSummaryInstance.mountMethodSelector({summary: summaryData, readyToPay: readyToPayData});
94
+ it('should inject the proper HTML for express methods', async () => {
95
+ const mountSummaryInstance = new TestMountMethodSelectorInstance({
96
+ options
97
+ });
98
+
99
+ mountSummaryInstance.loader.DOM.form = mountSummaryInstance.form;
100
+
101
+ mountMethodSelector({ state: mountSummaryInstance });
106
102
 
107
103
  const form = document.querySelector('.rebilly-instruments-form');
108
104
  expect(form).toMatchSnapshot();
105
+ await avoidUnhandledPromises();
106
+ });
107
+
108
+ it('should allow updating method selector', async () => {
109
+ const state = new TestMountMethodSelectorInstance({
110
+ options
111
+ });
112
+
113
+ state.loader.DOM.form = state.form;
114
+
115
+ await updateMethodSelector({
116
+ state,
117
+ mainStyle: 'any main style'
118
+ });
109
119
  });
110
- })
120
+ });
@@ -1,77 +1,53 @@
1
- /* eslint-disable no-undef */
2
- import { MethodIframe } from '../common/iframe';
1
+
2
+ import mountGooglePay from './express-methods/google-pay';
3
+ import mountApplePay from './express-methods/apple-pay';
4
+ import mountPaypal from './express-methods/paypal';
3
5
  import { getMethodData } from './get-method-data';
4
6
 
5
- async function mountGooglePay({
6
- methodId,
7
+ export function mountExpressMethods({
8
+ state,
9
+ EXPRESS_METHODS,
10
+ EXPRESS_METHODS_CONTAINER
7
11
  }) {
8
- const container = document.querySelector('.rebilly-instruments-express-methods');
9
-
10
- const {paymentMethodsUrl} = this.options._computed;
12
+ // A child div for each method must be created before mounting.
13
+ // Any DOM operation (innerHTML, append, etc) done on the parent div (EXPRESS_METHODS_CONTAINER) in between
14
+ // the two Postmate's instantiation (1 parent, 1 child) will cause the parent <-> child handshake to fail
15
+ EXPRESS_METHODS.forEach((expressMethod) => {
16
+ const { METHOD_ID } = getMethodData(expressMethod);
11
17
 
12
- const model = {
13
- configs: this.configs,
14
- options: this.options,
15
- };
16
- const iframe = await new MethodIframe({
17
- name: methodId,
18
- url: `${paymentMethodsUrl}/${methodId}`,
19
- container,
20
- model
21
- });
22
- iframe.bindEventListeners({
23
- loader: this.loader
18
+ EXPRESS_METHODS_CONTAINER.innerHTML += `
19
+ <div class="rebilly-instruments-${METHOD_ID}-method"></div>
20
+ `;
24
21
  });
25
- this.iframeComponents.push(iframe);
26
- }
27
-
28
- function mountApplePay({
29
- EXPRESS_METHODS_CONTAINER,
30
- METHOD_ID,
31
- METHOD_TYPE,
32
- }) {
33
- EXPRESS_METHODS_CONTAINER.innerHTML += `
34
- <div id="rebilly-instruments-${METHOD_ID}" data-rebilly-instruments-express-type="${METHOD_TYPE}"></div>
35
- `;
36
- Rebilly.applePay.mount(`#rebilly-instruments-${METHOD_ID}`);
37
22
 
38
- Rebilly.on('token-ready', (token) => {
39
- dispatch('instrument-ready', token);
40
- });
41
- }
42
23
 
43
- function mountPaypal() {
44
- console.log('PayPal - work in progress');
45
- this.loader.stopLoading({id: 'paypal-express'});
46
- }
47
-
48
- const browserIsSafari = () => window.ApplePaySession;
49
-
50
- export function mountExpressMethods({
51
- EXPRESS_METHODS,
52
- EXPRESS_METHODS_CONTAINER,
53
- }) {
54
24
  EXPRESS_METHODS.forEach((expressMethod) => {
55
- const {method, feature} = expressMethod;
56
- const methodData = getMethodData(expressMethod);
57
-
58
- if (method === 'paypal') {
59
- mountPaypal.call(this);
60
- };
25
+ const { method, feature } = expressMethod;
26
+ const { METHOD_ID, METHOD_TYPE } = getMethodData(expressMethod);
61
27
 
62
28
  if (feature?.name === 'Google Pay') {
63
- mountGooglePay.call(this, {
64
- methodId: methodData.METHOD_ID
29
+ mountGooglePay({
30
+ state,
31
+ METHOD_ID
65
32
  });
66
33
  }
67
34
 
68
- if (feature?.name === 'Apple Pay' && browserIsSafari()) {
69
- mountApplePay.call(this, {
70
- EXPRESS_METHODS_CONTAINER,
71
- ...methodData,
35
+ if (feature?.name === 'Apple Pay') {
36
+ mountApplePay({
37
+ state,
38
+ METHOD_ID,
39
+ METHOD_TYPE,
40
+ EXPRESS_METHODS,
41
+ EXPRESS_METHODS_CONTAINER
42
+ });
43
+ }
44
+
45
+ if (method === 'paypal') {
46
+ mountPaypal({
47
+ state,
48
+ METHOD_ID,
49
+ METHOD_TYPE,
72
50
  });
73
- } else {
74
- this.loader.stopLoading({id: 'payment-card-express'});
75
51
  }
76
52
  });
77
53
  }
@@ -1,30 +1,35 @@
1
1
  import camelCase from 'lodash.camelcase';
2
+ import { mountModal } from '../modal';
2
3
  import { MethodIframe } from '../common/iframe';
3
4
  import { getMethodData } from './get-method-data';
4
5
 
5
6
  export function MountMethods({
7
+ state,
6
8
  METHODS_CONTAINER,
7
- METHODS,
8
- mainStyle,
9
- plans,
10
- products
9
+ METHODS
11
10
  }) {
12
- METHODS.forEach(async method => {
13
- const { METHOD_ID: methodId, METHOD_TYPE: methodType } = getMethodData(method);
14
- const { paymentMethodsUrl } = this.options._computed || 'https://www.example.com';
11
+ METHODS.forEach(async (method) => {
12
+ const { METHOD_ID: methodId, METHOD_TYPE: methodType } =
13
+ getMethodData(method);
14
+ const { paymentMethodsUrl } =
15
+ state.options._computed || 'https://www.example.com';
15
16
 
16
17
  const selector = `rebilly-instruments-${methodId}`;
17
- const isiFrame = methodId === 'payment-card' && !this.options.paymentInstruments[methodType]?.popup;
18
+ const isiFrame =
19
+ methodId === 'payment-card' &&
20
+ !state.options.paymentInstruments[methodType]?.popup;
18
21
  const model = {
19
- configs: this.configs,
20
- options: this.options,
21
- mainStyle,
22
- method,
23
- plans,
24
- products,
22
+ options: state.options,
23
+ mainStyle: state.mainStyle,
24
+ plans: state.data.plans,
25
+ products: state.data.products,
26
+ method
25
27
  };
26
28
 
27
- METHODS_CONTAINER.insertAdjacentHTML('beforeend', `<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`);
29
+ METHODS_CONTAINER.insertAdjacentHTML(
30
+ 'beforeend',
31
+ `<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`
32
+ );
28
33
  const container = document.querySelector(`#${selector}`);
29
34
 
30
35
  if (isiFrame) {
@@ -35,22 +40,28 @@ export function MountMethods({
35
40
  model
36
41
  });
37
42
  iframe.bindEventListeners({
38
- loader: this.loader,
43
+ loader: state.loader,
39
44
  id: method.method
40
45
  });
41
- this.iframeComponents.push(iframe);
46
+ state.iframeComponents.push(iframe);
42
47
  } else {
43
- container.insertAdjacentHTML('beforeend', `<button class="${selector} rebilly-instruments-button" data-rebilly-i18n="paymentMethods.${method.method}">${camelCase(method.method)}</button>`);
48
+ container.insertAdjacentHTML(
49
+ 'beforeend',
50
+ `<button class="${selector} rebilly-instruments-button" data-rebilly-i18n="paymentMethods.${
51
+ method.method
52
+ }">${camelCase(method.method)}</button>`
53
+ );
44
54
  const paymentCardButton = document.querySelector(`.${selector}`);
45
55
  paymentCardButton.addEventListener('click', async () => {
46
- const iframe = await this._mountModal.call(this, {
56
+ const iframe = await mountModal({
57
+ state,
47
58
  name: methodId,
48
59
  url: `${paymentMethodsUrl}/${methodId}`,
49
60
  model
50
61
  });
51
- this.iframeComponents.push(iframe);
62
+ state.iframeComponents.push(iframe);
52
63
  });
53
- this.loader.stopLoading({id: method.method});
64
+ state.loader.stopLoading({ id: method.method });
54
65
  }
55
66
  });
56
67
  }
@@ -2,46 +2,59 @@ import { ModalIframe } from './common/iframe';
2
2
 
3
3
  const modalTemplate = (isRedirect, method) => `
4
4
  <div class="rebilly-instruments-modal-overlay">
5
- <div class="rebilly-instruments-modal-container ${method ? `rebilly-instruments-${method}` : ''} ${isRedirect ? 'is-redirect' : ''}">
5
+ <div class="rebilly-instruments-modal-container ${
6
+ method ? `rebilly-instruments-${method}` : ''
7
+ } ${isRedirect ? 'is-redirect' : ''}">
8
+ ${isRedirect ? '' : `
6
9
  <svg class="rebilly-instruments-modal-close" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
7
10
  <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"/>
8
11
  </svg>
12
+ `}
9
13
  <div class="rebilly-instruments-modal-content"></div>
10
14
  </div>
11
15
  </div>
12
16
  `;
13
17
 
14
- export async function MountModal({
18
+ export async function mountModal({
15
19
  name = '',
16
20
  url = '',
17
21
  model = {},
18
22
  classListArray = [],
19
- close = () => {}
23
+ close = () => {},
24
+ state = null
20
25
  } = {}) {
21
26
  const method = model?.method?.method;
22
27
  const isRedirect = name === 'rebilly-instruments-approval-url';
23
- this.form.insertAdjacentHTML('beforeend', modalTemplate(isRedirect, method));
24
-
25
- const modalOverlay = document.querySelector('.rebilly-instruments-modal-overlay');
26
- const modalContainer = document.querySelector('.rebilly-instruments-modal-container');
27
- const closeButton = document.querySelector('.rebilly-instruments-modal-close');
28
- const modalContent = document.querySelector('.rebilly-instruments-modal-content');
28
+ state.form.insertAdjacentHTML('beforeend', modalTemplate(isRedirect, method));
29
+
30
+ const modalOverlay = document.querySelector(
31
+ '.rebilly-instruments-modal-overlay'
32
+ );
33
+ const modalContainer = document.querySelector(
34
+ '.rebilly-instruments-modal-container'
35
+ );
36
+ const closeButton = document.querySelector(
37
+ '.rebilly-instruments-modal-close'
38
+ );
39
+ const modalContent = document.querySelector(
40
+ '.rebilly-instruments-modal-content'
41
+ );
29
42
 
30
43
  document.body.style.overflow = 'hidden';
31
44
  setTimeout(() => {
32
45
  modalOverlay.classList.add('is-visible');
33
46
  modalContainer.classList.add('is-visible');
34
47
  }, 240);
35
- this.loader.addDOMElement({section: 'modal', el: modalContent});
36
- this.loader.startLoading({section: 'modal', id: 'modal-content'});
48
+ state.loader.addDOMElement({ section: 'modal', el: modalContent });
49
+ state.loader.startLoading({ section: 'modal', id: 'modal-content' });
37
50
 
38
51
  const injectedModel = {
39
- configs: this.configs,
40
- options: this.options,
52
+ options: state.options,
41
53
  ...model
42
- }
54
+ };
43
55
 
44
56
  const iframe = await new ModalIframe({
57
+ state,
45
58
  name,
46
59
  url,
47
60
  model: injectedModel,
@@ -54,20 +67,21 @@ export async function MountModal({
54
67
  modalOverlay.classList.remove('is-visible');
55
68
  setTimeout(() => {
56
69
  document.body.style.overflow = 'auto';
57
- modalOverlay.children.forEach(child => child.remove());
70
+ modalOverlay.children.forEach((child) => child.remove());
58
71
  modalOverlay.remove();
59
72
  close(...args);
60
- iframe.component.destroy();
73
+ iframe.destroy();
61
74
  }, 300);
62
- }
63
-
75
+ };
76
+
64
77
  iframe.bindEventListeners({
65
78
  close: closeModal,
66
- loader: this.loader
79
+ loader: state.loader
67
80
  });
68
81
 
69
- modalOverlay.addEventListener('click', closeModal);
70
- closeButton.addEventListener('click', closeModal);
82
+ if (!isRedirect) {
83
+ closeButton.addEventListener('click', closeModal);
84
+ }
71
85
 
72
86
  return iframe;
73
- }
87
+ }
@@ -1,24 +1,21 @@
1
1
  import { ViewIframe } from './common/iframe';
2
2
  import { replaceContent } from './common/render-utilities';
3
3
 
4
- export async function MountResult({
5
- purchase,
6
- mainStyle
7
- }) {
4
+ export async function mountResult({ payload, state }) {
8
5
  const resultContainerClassName = 'rebilly-instruments-result';
9
- replaceContent(this.form, `<div class="${resultContainerClassName}"></div>`);
6
+ replaceContent(state.form, `<div class="${resultContainerClassName}"></div>`);
7
+
8
+ state.loader.startLoading({ id: 'result' });
10
9
 
11
- this.loader.startLoading({id: 'result'});
12
-
13
10
  const container = document.querySelector(`.${resultContainerClassName}`);
14
- const { paymentMethodsUrl } = this.options._computed;
11
+ const { paymentMethodsUrl } = state.options._computed;
15
12
 
16
13
  const model = {
17
- configs: this.configs,
18
- options: this.options,
19
- mainStyle,
20
- purchase
14
+ options: state.options,
15
+ mainStyle: state.mainStyle,
16
+ [state.options.transactionType]: payload
21
17
  };
18
+
22
19
  const iframe = await new ViewIframe({
23
20
  name: 'rebilly-instruments-result',
24
21
  url: `${paymentMethodsUrl}/result`,
@@ -26,8 +23,8 @@ export async function MountResult({
26
23
  model
27
24
  });
28
25
  iframe.bindEventListeners({
29
- loader: this.loader
26
+ loader: state.loader
30
27
  });
31
28
 
32
- this.iframeComponents.push(iframe);
33
- };
29
+ state.iframeComponents.push(iframe);
30
+ }