@rebilly/instruments 1.0.1-beta → 1.0.2-beta.10

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 (277) hide show
  1. package/.babelrc +23 -5
  2. package/.eslintrc.js +27 -0
  3. package/.prettierrc.js +11 -0
  4. package/CONTRIBUTING.md +4 -0
  5. package/README.md +361 -2
  6. package/dist/events/base-event.js +51 -37
  7. package/dist/events/events.spec.js +18 -0
  8. package/dist/events/index.js +11 -8
  9. package/dist/functions/destroy.js +27 -5
  10. package/dist/functions/destroy.spec.js +69 -0
  11. package/dist/functions/initialize.js +60 -41
  12. package/dist/functions/initialize.spec.js +13 -13
  13. package/dist/functions/mount/fetch-summary-data.js +46 -0
  14. package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
  15. package/dist/functions/mount/index.js +346 -0
  16. package/dist/functions/mount/mount.spec.js +135 -0
  17. package/dist/functions/on.js +26 -18
  18. package/dist/functions/on.spec.js +45 -63
  19. package/dist/functions/purchase.js +41 -154
  20. package/dist/functions/purchase.spec.js +60 -76
  21. package/dist/functions/show.js +39 -43
  22. package/dist/functions/show.spec.js +57 -0
  23. package/dist/functions/update.js +60 -5
  24. package/dist/functions/update.spec.js +100 -0
  25. package/dist/i18n/en.json +19 -0
  26. package/dist/i18n/es.json +19 -0
  27. package/dist/i18n/i18n.spec.js +6 -23
  28. package/dist/i18n/index.js +44 -67
  29. package/dist/index.js +70 -71
  30. package/dist/index.spec.js +24 -44
  31. package/dist/loader/index.js +63 -62
  32. package/dist/loader/loader.spec.js +14 -11
  33. package/dist/storefront/index.js +28 -39
  34. package/dist/storefront/models/plan-model.js +37 -54
  35. package/dist/storefront/models/product-model.js +25 -36
  36. package/dist/storefront/models/ready-to-pay-model.js +38 -42
  37. package/dist/storefront/models/summary-model.js +72 -99
  38. package/dist/storefront/plans.js +37 -84
  39. package/dist/storefront/plans.spec.js +61 -151
  40. package/dist/storefront/products.js +35 -83
  41. package/dist/storefront/products.spec.js +60 -150
  42. package/dist/storefront/purchase.js +27 -64
  43. package/dist/storefront/purchase.spec.js +51 -87
  44. package/dist/storefront/ready-to-pay.js +45 -107
  45. package/dist/storefront/ready-to-pay.spec.js +72 -147
  46. package/dist/storefront/storefront.spec.js +6 -6
  47. package/dist/storefront/summary.js +37 -84
  48. package/dist/storefront/summary.spec.js +135 -240
  49. package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
  50. package/dist/style/base/index.js +72 -0
  51. package/dist/style/base/theme.js +73 -0
  52. package/dist/style/base/theme.spec.js +30 -0
  53. package/dist/style/browserslist.js +8 -0
  54. package/dist/style/components/address.js +64 -0
  55. package/dist/style/components/button.js +61 -0
  56. package/dist/style/components/divider.js +48 -0
  57. package/dist/style/components/forms/checkbox.js +83 -0
  58. package/dist/style/components/forms/field.js +53 -0
  59. package/dist/style/components/forms/form.js +28 -0
  60. package/dist/style/components/forms/input.js +45 -0
  61. package/dist/style/components/forms/label.js +43 -0
  62. package/dist/style/components/forms/select.js +63 -0
  63. package/dist/style/components/forms/validation.js +34 -0
  64. package/dist/style/components/icons.js +22 -0
  65. package/dist/style/components/index.js +57 -0
  66. package/dist/style/components/loader.js +48 -0
  67. package/dist/style/components/methods.js +104 -0
  68. package/dist/style/components/overlay.js +33 -0
  69. package/dist/style/helpers/index.js +59 -0
  70. package/dist/style/index.js +48 -0
  71. package/dist/style/payment-instruments/content.js +17 -0
  72. package/dist/style/payment-instruments/index.js +20 -0
  73. package/dist/style/payment-instruments/payment-card.js +35 -0
  74. package/dist/style/utils/color-values.js +22 -0
  75. package/dist/style/vendor/framepay.js +34 -0
  76. package/dist/style/vendor/postmate.js +17 -0
  77. package/dist/style/views/confirmation.js +85 -0
  78. package/dist/style/views/index.js +29 -0
  79. package/dist/style/views/method-selector.js +20 -0
  80. package/dist/style/views/modal.js +93 -0
  81. package/dist/style/views/result.js +61 -0
  82. package/dist/style/views/summary.js +123 -0
  83. package/dist/utils/add-dom-element.js +12 -34
  84. package/dist/utils/format-currency.js +4 -4
  85. package/dist/utils/has-valid-css-selector.js +2 -2
  86. package/dist/utils/index.js +15 -31
  87. package/dist/utils/is-dom-element.js +1 -1
  88. package/dist/utils/process-property-as-dom-element.js +12 -17
  89. package/dist/utils/sleep.js +10 -0
  90. package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
  91. package/dist/views/common/iframe/base-iframe.js +57 -0
  92. package/dist/views/common/iframe/event-listeners.js +50 -0
  93. package/dist/views/common/iframe/index.js +19 -0
  94. package/dist/views/common/iframe/method-iframe.js +33 -0
  95. package/dist/views/common/iframe/modal-iframe.js +38 -0
  96. package/dist/views/common/iframe/view-iframe.js +31 -0
  97. package/dist/views/common/render-utilities.js +11 -0
  98. package/dist/views/confirmation.js +82 -0
  99. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
  100. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  101. package/dist/views/method-selector/express-methods/google-pay.js +32 -0
  102. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  103. package/dist/views/method-selector/generate-digital-wallet.js +59 -0
  104. package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
  105. package/dist/views/method-selector/get-method-data.js +25 -0
  106. package/dist/views/method-selector/get-payment-methods.js +55 -0
  107. package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
  108. package/dist/views/method-selector/index.js +133 -0
  109. package/dist/views/method-selector/method-selector.spec.js +139 -0
  110. package/dist/views/method-selector/mount-express-methods.js +69 -0
  111. package/dist/views/method-selector/mount-methods.js +78 -0
  112. package/dist/views/modal.js +83 -0
  113. package/dist/views/result.js +42 -0
  114. package/dist/views/summary.js +162 -0
  115. package/dist/views/summary.spec.js +148 -0
  116. package/package.json +12 -6
  117. package/src/events/base-event.js +35 -12
  118. package/src/events/events.spec.js +11 -0
  119. package/src/events/index.js +12 -6
  120. package/src/functions/destroy.js +22 -3
  121. package/src/functions/destroy.spec.js +63 -0
  122. package/src/functions/initialize.js +43 -20
  123. package/src/functions/initialize.spec.js +9 -7
  124. package/src/functions/mount/fetch-summary-data.js +29 -0
  125. package/src/functions/mount/fetch-summary-data.spec.js +41 -0
  126. package/src/functions/mount/index.js +312 -0
  127. package/src/functions/mount/mount.spec.js +171 -0
  128. package/src/functions/on.js +17 -14
  129. package/src/functions/on.spec.js +39 -29
  130. package/src/functions/purchase.js +24 -64
  131. package/src/functions/purchase.spec.js +19 -17
  132. package/src/functions/show.js +27 -7
  133. package/src/functions/show.spec.js +61 -0
  134. package/src/functions/update.js +50 -3
  135. package/src/functions/update.spec.js +107 -0
  136. package/src/i18n/i18n.spec.js +6 -4
  137. package/src/i18n/index.js +20 -12
  138. package/src/index.js +43 -49
  139. package/src/index.spec.js +11 -42
  140. package/src/loader/index.js +55 -39
  141. package/src/loader/loader.spec.js +30 -23
  142. package/src/storefront/index.js +9 -7
  143. package/src/storefront/models/plan-model.js +1 -1
  144. package/src/storefront/models/product-model.js +1 -1
  145. package/src/storefront/models/ready-to-pay-model.js +10 -4
  146. package/src/storefront/models/summary-model.js +8 -15
  147. package/src/storefront/plans.js +16 -12
  148. package/src/storefront/plans.spec.js +29 -37
  149. package/src/storefront/products.js +16 -12
  150. package/src/storefront/products.spec.js +28 -39
  151. package/src/storefront/purchase.js +8 -6
  152. package/src/storefront/purchase.spec.js +18 -17
  153. package/src/storefront/ready-to-pay.js +19 -13
  154. package/src/storefront/ready-to-pay.spec.js +41 -41
  155. package/src/storefront/storefront.spec.js +1 -1
  156. package/src/storefront/summary.js +14 -12
  157. package/src/storefront/summary.spec.js +37 -50
  158. package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
  159. package/src/style/base/index.js +63 -0
  160. package/src/style/base/theme.js +61 -0
  161. package/src/style/base/theme.spec.js +32 -0
  162. package/src/style/browserslist.js +1 -0
  163. package/src/style/components/address.js +55 -0
  164. package/src/style/components/button.js +54 -0
  165. package/src/style/components/divider.js +39 -0
  166. package/src/style/components/forms/checkbox.js +76 -0
  167. package/src/style/components/forms/field.js +44 -0
  168. package/src/style/components/forms/form.js +19 -0
  169. package/src/style/components/forms/input.js +36 -0
  170. package/src/style/components/forms/label.js +34 -0
  171. package/src/style/components/forms/select.js +54 -0
  172. package/src/style/components/forms/validation.js +25 -0
  173. package/src/style/components/icons.js +13 -0
  174. package/src/style/components/index.js +35 -0
  175. package/src/style/components/loader.js +41 -0
  176. package/src/style/components/methods.js +93 -0
  177. package/src/style/components/overlay.js +24 -0
  178. package/src/style/helpers/index.js +51 -0
  179. package/src/style/index.js +30 -0
  180. package/src/style/payment-instruments/content.js +8 -0
  181. package/src/style/payment-instruments/index.js +10 -0
  182. package/src/style/payment-instruments/payment-card.js +26 -0
  183. package/src/style/utils/color-values.js +9 -0
  184. package/src/style/vendor/framepay.js +25 -0
  185. package/src/style/vendor/postmate.js +8 -0
  186. package/src/style/views/confirmation.js +76 -0
  187. package/src/style/views/index.js +16 -0
  188. package/src/style/views/method-selector.js +11 -0
  189. package/src/style/views/modal.js +84 -0
  190. package/src/style/views/result.js +52 -0
  191. package/src/style/views/summary.js +114 -0
  192. package/src/utils/add-dom-element.js +12 -13
  193. package/src/utils/format-currency.js +4 -1
  194. package/src/utils/has-valid-css-selector.js +2 -2
  195. package/src/utils/index.js +2 -6
  196. package/src/utils/is-dom-element.js +1 -1
  197. package/src/utils/process-property-as-dom-element.js +27 -24
  198. package/src/utils/sleep.js +3 -0
  199. package/src/views/__snapshots__/summary.spec.js.snap +292 -0
  200. package/src/views/common/iframe/base-iframe.js +46 -0
  201. package/src/views/common/iframe/event-listeners.js +27 -0
  202. package/src/views/common/iframe/index.js +7 -0
  203. package/src/views/common/iframe/method-iframe.js +21 -0
  204. package/src/views/common/iframe/modal-iframe.js +27 -0
  205. package/src/views/common/iframe/view-iframe.js +18 -0
  206. package/src/views/common/render-utilities.js +4 -0
  207. package/src/views/confirmation.js +57 -0
  208. package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
  209. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  210. package/src/views/method-selector/express-methods/google-pay.js +25 -0
  211. package/src/views/method-selector/express-methods/paypal.js +7 -0
  212. package/src/views/method-selector/generate-digital-wallet.js +44 -0
  213. package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
  214. package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
  215. package/src/views/method-selector/get-payment-methods.js +40 -0
  216. package/src/views/method-selector/get-payment-methods.spec.js +40 -0
  217. package/src/views/method-selector/index.js +110 -0
  218. package/src/views/method-selector/method-selector.spec.js +146 -0
  219. package/src/views/method-selector/mount-express-methods.js +53 -0
  220. package/src/views/method-selector/mount-methods.js +71 -0
  221. package/src/views/modal.js +84 -0
  222. package/src/views/result.js +30 -0
  223. package/src/{components → views}/summary.js +90 -21
  224. package/src/views/summary.spec.js +170 -0
  225. package/tests/async-utilities.js +22 -0
  226. package/tests/mocks/rebilly-instruments-mock.js +105 -7
  227. package/dist/components/confirmation.js +0 -103
  228. package/dist/components/form/form.js +0 -110
  229. package/dist/components/form/form.spec.js +0 -135
  230. package/dist/components/form/get-method-data.js +0 -21
  231. package/dist/components/form/get-payment-methods.js +0 -42
  232. package/dist/components/form/method-selector.js +0 -61
  233. package/dist/components/form/mount-express-payment-methods.js +0 -102
  234. package/dist/components/form/process-digital-wallet-options.js +0 -20
  235. package/dist/components/form/zoid-helpers.js +0 -130
  236. package/dist/components/result.js +0 -66
  237. package/dist/components/summary.js +0 -60
  238. package/dist/components/summary.spec.js +0 -144
  239. package/dist/events/instrument-ready.js +0 -51
  240. package/dist/events/purchase-complete.js +0 -51
  241. package/dist/functions/mount.js +0 -311
  242. package/dist/functions/mount.spec.js +0 -203
  243. package/dist/styles/base-styles.js +0 -12
  244. package/dist/styles/flat-theme-object.js +0 -42
  245. package/dist/styles/framepay.js +0 -15
  246. package/dist/styles/main.js +0 -25
  247. package/dist/styles/payment-card.js +0 -12
  248. package/dist/styles/shade-tint-values-helper.js +0 -28
  249. package/dist/styles/style-variables.js +0 -43
  250. package/dist/utils/camel-case.js +0 -12
  251. package/dist/utils/kebab-case.js +0 -10
  252. package/dist/utils/un-kebab-case.js +0 -10
  253. package/src/components/confirmation.js +0 -77
  254. package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
  255. package/src/components/form/form.js +0 -88
  256. package/src/components/form/form.spec.js +0 -109
  257. package/src/components/form/get-payment-methods.js +0 -32
  258. package/src/components/form/method-selector.js +0 -47
  259. package/src/components/form/mount-express-payment-methods.js +0 -84
  260. package/src/components/form/process-digital-wallet-options.js +0 -11
  261. package/src/components/form/zoid-helpers.js +0 -114
  262. package/src/components/result.js +0 -50
  263. package/src/components/summary.spec.js +0 -106
  264. package/src/events/instrument-ready.js +0 -11
  265. package/src/events/purchase-complete.js +0 -11
  266. package/src/functions/mount.js +0 -204
  267. package/src/functions/mount.spec.js +0 -172
  268. package/src/styles/base-styles.js +0 -741
  269. package/src/styles/flat-theme-object.js +0 -12
  270. package/src/styles/framepay.js +0 -30
  271. package/src/styles/main.js +0 -17
  272. package/src/styles/payment-card.js +0 -18
  273. package/src/styles/shade-tint-values-helper.js +0 -13
  274. package/src/styles/style-variables.js +0 -34
  275. package/src/utils/camel-case.js +0 -3
  276. package/src/utils/kebab-case.js +0 -3
  277. package/src/utils/un-kebab-case.js +0 -3
@@ -0,0 +1,170 @@
1
+ import SummaryModel from '@/storefront/models/summary-model';
2
+ import PlanModel from '@/storefront/models/plan-model';
3
+ import ProductModel from '@/storefront/models/product-model';
4
+ import { Loader } from '../loader';
5
+ import { Translate } from '../i18n';
6
+ import { mountSummary } from './summary';
7
+ import { RebillyInstrumentsInstance } from '../index';
8
+
9
+ describe('Summary component', () => {
10
+ let summaryElement;
11
+ beforeEach(() => {
12
+ document.body.innerHTML = '';
13
+ summaryElement = document.createElement('div');
14
+ document.body.append(summaryElement);
15
+ });
16
+
17
+ class TestMountSummaryInstance {
18
+ constructor({
19
+ configs = {},
20
+ options = {},
21
+ summary = summaryElement,
22
+ loader = new Loader(),
23
+ translate = new Translate()
24
+ } = {}) {
25
+ this.configs = configs;
26
+ this.options = options;
27
+ this.summary = summary;
28
+ this.loader = loader;
29
+ this.translate = translate;
30
+ }
31
+ }
32
+
33
+ const options = {
34
+ intent: {
35
+ countryCode: 'US',
36
+ items: [
37
+ {
38
+ planId: 'my-awesome-product',
39
+ quantity: 1,
40
+ thumbnail: ''
41
+ },
42
+ {
43
+ planId: 'awesome-t-shirt',
44
+ quantity: 2,
45
+ thumbnail: ''
46
+ }
47
+ ]
48
+ }
49
+ };
50
+
51
+ const summaryData = new SummaryModel({
52
+ currency: 'USD',
53
+ lineItems: [
54
+ {
55
+ type: 'debit',
56
+ description: 'My Awesome Product',
57
+ unitPrice: 30,
58
+ quantity: 1,
59
+ price: 30,
60
+ productId: 'test-product-1',
61
+ planId: 'my-awesome-product'
62
+ },
63
+ {
64
+ type: 'debit',
65
+ description: 'Awesome T-Shirt',
66
+ unitPrice: 20,
67
+ quantity: 2,
68
+ price: 40,
69
+ productId: 'test-product-2',
70
+ planId: 'awesome-t-shirt'
71
+ }
72
+ ],
73
+ subtotalAmount: 70,
74
+ taxAmount: 0,
75
+ shippingAmount: 0,
76
+ discountsAmount: 0,
77
+ total: 70
78
+ });
79
+
80
+ const planData = [
81
+ new PlanModel({
82
+ name: 'My Awesome Product',
83
+ id: 'my-awesome-product',
84
+ productId: 'test-product-1'
85
+ }),
86
+ new PlanModel({
87
+ name: 'My Awesome T-Shirt',
88
+ id: 'awesome-t-shirt',
89
+ productId: 'test-product-2'
90
+ })
91
+ ];
92
+
93
+ const productData = [
94
+ new ProductModel({
95
+ description: 'My Awesome Product',
96
+ id: 'test-product-1'
97
+ }),
98
+ new ProductModel({
99
+ description: 'My Awesome T-Shirt',
100
+ id: 'test-product-2'
101
+ })
102
+ ];
103
+
104
+ const configs = {
105
+ websiteId: 'test-website-id'
106
+ };
107
+
108
+ it('should render the summary correctly', () => {
109
+ const mountSummaryInstance = new TestMountSummaryInstance({
110
+ configs,
111
+ options
112
+ });
113
+
114
+ //TODO: improve design to avoid this manual change
115
+ mountSummaryInstance.loader.DOM.summary = mountSummaryInstance.summary;
116
+
117
+ mountSummary({
118
+ state: mountSummaryInstance,
119
+ summaryOptions: {
120
+ summary: summaryData,
121
+ plans: planData,
122
+ products: productData
123
+ }
124
+ });
125
+
126
+ // Number of line items
127
+ const itemsContainer = document.querySelector(
128
+ '.rebilly-instruments-summary-line-items'
129
+ );
130
+ expect(itemsContainer).toMatchSnapshot();
131
+
132
+ // Breakdown
133
+ const summaryBreakdown = document.querySelector(
134
+ '.rebilly-instruments-summary-breakdown'
135
+ );
136
+ expect(summaryBreakdown).toMatchSnapshot();
137
+ });
138
+
139
+ it('should not render the plan description if its falsy', () => {
140
+ const state = new RebillyInstrumentsInstance();
141
+ state.configs = configs;
142
+ state.options = options;
143
+
144
+ const mountSummaryInstance = new TestMountSummaryInstance({
145
+ configs,
146
+ options
147
+ });
148
+
149
+ // Making one product description falsy
150
+ productData[0].description = null;
151
+
152
+ //TODO: improve design to avoid this manual change
153
+ mountSummaryInstance.loader.DOM.summary = mountSummaryInstance.summary;
154
+
155
+ mountSummary({
156
+ state: mountSummaryInstance,
157
+ summaryOptions: {
158
+ summary: summaryData,
159
+ plans: planData,
160
+ products: productData
161
+ }
162
+ });
163
+
164
+ // Check that only one description is render
165
+ const itemsSynopsysDescription = document.querySelectorAll(
166
+ '.rebilly-instruments-summary-line-item-synopsis-description'
167
+ );
168
+ expect(itemsSynopsysDescription.length).toEqual(1);
169
+ });
170
+ });
@@ -0,0 +1,22 @@
1
+ import { sleep } from '@/utils'
2
+
3
+ export async function avoidUnhandledPromises() {
4
+ // We need this sleep to avoid unhandled promises.
5
+ // This hack will be removed if we refactor the current design.
6
+ await sleep(100)
7
+ }
8
+
9
+ /**
10
+ * @param {Promise} promise
11
+ */
12
+ export async function expectConfigurationError(promise) {
13
+ const NoConfigOrOptionsError =
14
+ 'Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data'
15
+ let error = null
16
+ try {
17
+ await promise
18
+ } catch (e) {
19
+ error = e
20
+ }
21
+ expect(error.message).toBe(NoConfigOrOptionsError)
22
+ }
@@ -1,24 +1,122 @@
1
- import RebillyInstruments from '@rebilly/instruments';
1
+ import { RebillyInstrumentsInstance } from '@rebilly/instruments';
2
+ import { createFramepayMock } from 'tests/mocks/framepay-mock';
3
+ import { get, ok, post } from 'msw-when-then';
4
+ import { when } from 'tests/msw/server';
5
+ import { storefrontURL } from 'tests/mocks/storefront-api-mock';
6
+ import PlanModel from '@/storefront/models/plan-model';
7
+ import ProductModel from '@/storefront/models/product-model';
8
+ import SummaryModel from '@/storefront/models/summary-model';
9
+ import merge from 'lodash.merge';
10
+
11
+ export async function RenderMockRebillyInstruments(configs = {}, options = {}) {
12
+ const testPlan = new PlanModel({ name: 'Test Plan', id: 'test-plan-id-1' });
13
+ const testProduct = new ProductModel({
14
+ description: 'My Awesome Product',
15
+ id: 'test-product-1'
16
+ });
17
+ const testSummary = new SummaryModel({
18
+ currency: 'USD',
19
+ lineItems: [
20
+ {
21
+ description: 'test-plan-id-1',
22
+ planId: 'test-plan-id-1',
23
+ productId: 'test-product-1',
24
+ quantity: 1
25
+ }
26
+ ]
27
+ });
28
+ const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
29
+
30
+ when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
31
+ (() => {
32
+ return ok([
33
+ {
34
+ method: 'payment-card',
35
+ feature: {
36
+ name: 'Google Pay',
37
+ merchantName: 'google-pay-merchant-name',
38
+ merchantOrigin: 'google-pay-merchant-origin'
39
+ },
40
+ brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
41
+ filters: []
42
+ }
43
+ ]);
44
+ })()
45
+ );
46
+
47
+ when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
48
+ (() => {
49
+ return ok(testSummary);
50
+ })()
51
+ );
52
+
53
+ when(get(`${storefrontURL}/plans`)).thenReturn(
54
+ (() => {
55
+ return ok([testPlan]);
56
+ })()
57
+ );
58
+
59
+ when(get(`${storefrontURL}/products`)).thenReturn(
60
+ (() => {
61
+ return ok([testProduct]);
62
+ })()
63
+ );
64
+
65
+ document.body.innerHTML = `
66
+ <div class="form-selector"></div>
67
+ <div class="summary-selector"></div>
68
+ `;
69
+
70
+ const defaultConfigs = {};
71
+
72
+ const defaultOptions = {
73
+ form: '.form-selector',
74
+ summary: '.summary-selector',
75
+ _dev: {
76
+ framePayStyleLink: framePayStyleUrl
77
+ },
78
+ options: {
79
+ locale: 'auto',
80
+ intent: {
81
+ items: [
82
+ {
83
+ planId: 'test-plan-id-1',
84
+ quantity: 1
85
+ }
86
+ ]
87
+ }
88
+ }
89
+ };
90
+
91
+ const framepayMock = createFramepayMock();
92
+ global.Rebilly = framepayMock;
93
+
94
+ const rebillyInstruments = MockRebillyInstruments(
95
+ merge(defaultConfigs, configs)
96
+ );
97
+ await rebillyInstruments.mount(merge(defaultOptions, options));
98
+ return rebillyInstruments;
99
+ }
2
100
 
3
101
  export function MockRebillyInstruments(config = {}, mount = null) {
102
+ const instance = new RebillyInstrumentsInstance();
4
103
  const initializeConfig = {
5
104
  organizationId: 'test-organization-id',
6
105
  publishableKey: 'test-api-key',
7
106
  websiteId: 'test-website-id',
8
107
  apiMode: 'live',
9
108
  ...config
10
- }
109
+ };
11
110
 
12
- RebillyInstruments.initialize(initializeConfig);
111
+ instance.initialize(initializeConfig);
13
112
 
14
113
  if (mount !== null) {
15
- document.body.innerHTML =
16
- `
114
+ document.body.innerHTML = `
17
115
  <div class="${mount.form || 'rebilly-instruments'}"></div>
18
116
  <div class="${mount.summary || 'rebilly-instruments-summary'}"></div>
19
117
  `;
20
- RebillyInstruments.mount(mount);
118
+ instance.mount(mount);
21
119
  }
22
120
 
23
- return RebillyInstruments;
121
+ return instance;
24
122
  }
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MountConfirmation = MountConfirmation;
7
- exports.baseConfirmationHTML = void 0;
8
-
9
- var _zoid = _interopRequireDefault(require("zoid"));
10
-
11
- var _main = require("../styles/main");
12
-
13
- var _zoidHelpers = require("./form/zoid-helpers");
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
-
17
- var baseConfirmationHTML = "\n <div class=\"rebilly-instruments-confirmation\"></div>\n";
18
- exports.baseConfirmationHTML = baseConfirmationHTML;
19
-
20
- function _confirmPurchase(instrument) {
21
- this.purchase(instrument);
22
- }
23
-
24
- function MountConfirmation(_ref) {
25
- var _this$configs,
26
- _this = this;
27
-
28
- var instrument = _ref.instrument;
29
- this.form.innerHTML += baseConfirmationHTML;
30
- this.loader.startLoading({
31
- id: 'confirmation'
32
- });
33
- var CONFIRMATION_CONTAINER = document.querySelector('.rebilly-instruments-confirmation');
34
- this.form.querySelectorAll(":not(.rebilly-instruments-confirmation)").forEach(function (element) {
35
- if (!element.classList.contains('rebilly-instruments-loader') && !element.classList.contains('rebilly-instruments-loader-spinner')) {
36
- element.remove();
37
- }
38
- });
39
- var paymentMethodsUrl = this.options._computed.paymentMethodsUrl;
40
- var zoidCreateConfig = {
41
- tag: 'rebilly-instruments-confirmation',
42
- url: "".concat(paymentMethodsUrl, "/confirmation"),
43
- defaultContext: 'iframe',
44
- dimensions: {
45
- width: '100%',
46
- height: '100%'
47
- }
48
- };
49
- var zoidMountConfig = {
50
- configs: this.configs,
51
- options: this.options,
52
- MAIN_STYLE: (0, _main.MAIN_STYLE)(((_this$configs = this.configs) === null || _this$configs === void 0 ? void 0 : _this$configs.theme) || {}),
53
- instrument: instrument,
54
- // eslint-disable-next-line no-shadow
55
- confirmPurchase: function confirmPurchase(instrument) {
56
- _confirmPurchase.call(_this, instrument);
57
- },
58
- onFrameResize: function onFrameResize(height) {
59
- CONFIRMATION_CONTAINER.style.height = height;
60
- },
61
- onLoading: function onLoading(id) {
62
- setTimeout(function () {
63
- _this.loader.stopLoading({
64
- id: id
65
- });
66
- }, 1);
67
- },
68
- back: function back() {
69
- CONFIRMATION_CONTAINER.remove();
70
-
71
- _this._mountForm(_this.formOptions);
72
- },
73
- showBackDrop: function showBackDrop(_ref2) {
74
- var doc = _ref2.doc,
75
- uid = _ref2.uid,
76
- focus = _ref2.focus;
77
-
78
- var container = _zoidHelpers.containerTemplate.call(_this, {
79
- doc: doc,
80
- uid: uid,
81
- focus: focus
82
- });
83
-
84
- document.body.append(container);
85
- },
86
- dispatch: _zoidHelpers.dispatch
87
- };
88
-
89
- if (!this.zoidComponents.confirmation) {
90
- this.zoidComponents.confirmation = _zoid["default"].create(zoidCreateConfig);
91
- }
92
-
93
- this.zoidComponents.confirmation({
94
- RebillyInstruments: zoidMountConfig,
95
- onClose: function onClose() {
96
- var backDropContainer = document.querySelector('.rebilly-instruments-overlay');
97
-
98
- if (backDropContainer) {
99
- backDropContainer.remove();
100
- }
101
- }
102
- }).render('.rebilly-instruments-confirmation');
103
- }
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MountForm = MountForm;
7
- exports.baseFormHTML = void 0;
8
-
9
- var _getPaymentMethods = require("./get-payment-methods");
10
-
11
- var _mountExpressPaymentMethods = require("./mount-express-payment-methods");
12
-
13
- var _processDigitalWalletOptions = require("./process-digital-wallet-options");
14
-
15
- var _methodSelector = require("./method-selector");
16
-
17
- var _events = _interopRequireDefault(require("../../events"));
18
-
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
20
-
21
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
22
-
23
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
-
25
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
26
-
27
- var baseFormHTML = function baseFormHTML(compactExpressInstruments) {
28
- return "\n <form class=\"rebilly-instruments-form\">\n <div class=\"rebilly-instruments-form-express ".concat(compactExpressInstruments ? 'compact' : '', "\">\n <span data-rebilly-i18n=\"form.expressCheckout\" class=\"rebilly-instruments-form-express-label\">Express checkout</span>\n </div>\n <div class=\"rebilly-instruments-divider\">\n <span class=\"rebilly-instruments-divider-label\" data-rebilly-i18n=\"form.or\">Or</span>\n </div>\n </form>\n");
29
- };
30
-
31
- exports.baseFormHTML = baseFormHTML;
32
-
33
- function MountForm() {
34
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
35
- readyToPay = _ref.readyToPay,
36
- summary = _ref.summary,
37
- plans = _ref.plans,
38
- products = _ref.products;
39
-
40
- var _getPaymentMethods$ca = _getPaymentMethods.getPaymentMethods.call(this, readyToPay),
41
- EXPRESS_METHODS = _getPaymentMethods$ca.EXPRESS_METHODS,
42
- METHODS = _getPaymentMethods$ca.METHODS;
43
-
44
- var EXPRESS_METHODS_CONTAINER = document.querySelector('.rebilly-instruments-form-express');
45
- this.form.innerHTML += baseFormHTML(this.options.paymentInstruments.compactExpressInstruments);
46
- var METHODS_DIVIDER = document.querySelector('.rebilly-instruments-divider');
47
- METHODS_DIVIDER.style.display = METHODS.length && EXPRESS_METHODS.length ? 'block' : 'none';
48
-
49
- var digitalWallet = _objectSpread({
50
- transactionData: {
51
- amount: summary.total,
52
- currency: summary.currency,
53
- countryCode: this.options.intent.countryCode,
54
- label: this.configs.websiteId
55
- }
56
- }, (0, _processDigitalWalletOptions.processDigitalWalletOptions)(this.options));
57
-
58
- this.configs = _objectSpread(_objectSpread({}, this.configs), {}, {
59
- digitalWallet: digitalWallet
60
- });
61
-
62
- function initializeFramepay() {
63
- var _this = this;
64
-
65
- if (Rebilly.initialized) {
66
- _mountExpressPaymentMethods.mountExpressPaymentMethods.call(this, {
67
- EXPRESS_METHODS: EXPRESS_METHODS,
68
- EXPRESS_METHODS_CONTAINER: EXPRESS_METHODS_CONTAINER
69
- });
70
- } else {
71
- Rebilly.initialize({
72
- publishableKey: this.configs.publishableKey,
73
- organizationId: this.configs.organizationId,
74
- digitalWallet: digitalWallet
75
- });
76
- Rebilly.on('ready', function () {
77
- _mountExpressPaymentMethods.mountExpressPaymentMethods.call(_this, {
78
- EXPRESS_METHODS: EXPRESS_METHODS,
79
- EXPRESS_METHODS_CONTAINER: EXPRESS_METHODS_CONTAINER
80
- });
81
- });
82
- Rebilly.on('token-ready', function (data) {
83
- _events["default"].instrumentReady.dispatch(data);
84
- });
85
- }
86
- }
87
-
88
- if (METHODS.length) {
89
- this.form.innerHTML += "<div class=\"rebilly-instruments-methods\"></div>";
90
- var METHODS_CONTAINER = document.querySelector('.rebilly-instruments-methods');
91
-
92
- _methodSelector.MountMethodSelector.call(this, {
93
- METHODS_CONTAINER: METHODS_CONTAINER,
94
- METHODS: METHODS,
95
- plans: plans,
96
- products: products
97
- });
98
- }
99
-
100
- if (window.Rebilly && EXPRESS_METHODS.length) {
101
- initializeFramepay.call(this);
102
- }
103
-
104
- this.translate.translateItems();
105
- this.loader.stopLoading({
106
- id: 'initForm'
107
- });
108
- }
109
-
110
- ;
@@ -1,135 +0,0 @@
1
- "use strict";
2
-
3
- var _summaryModel = _interopRequireDefault(require("@/storefront/models/summary-model"));
4
-
5
- var _readyToPayModel = _interopRequireDefault(require("@/storefront/models/ready-to-pay-model"));
6
-
7
- var _loader = require("../../loader");
8
-
9
- var _i18n = require("../../i18n");
10
-
11
- var _form = require("./form");
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
-
15
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
-
17
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
18
-
19
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
20
-
21
- describe('Summary component', function () {
22
- var formElement;
23
- beforeEach(function () {
24
- formElement = document.createElement('div');
25
- document.body.append(formElement);
26
- });
27
-
28
- var TestMountFormInstance = /*#__PURE__*/function () {
29
- function TestMountFormInstance() {
30
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
31
- _ref$configs = _ref.configs,
32
- configs = _ref$configs === void 0 ? {} : _ref$configs,
33
- _ref$options = _ref.options,
34
- options = _ref$options === void 0 ? {} : _ref$options,
35
- _ref$form = _ref.form,
36
- form = _ref$form === void 0 ? formElement : _ref$form,
37
- _ref$loader = _ref.loader,
38
- loader = _ref$loader === void 0 ? new _loader.Loader() : _ref$loader,
39
- _ref$translate = _ref.translate,
40
- translate = _ref$translate === void 0 ? new _i18n.Translate() : _ref$translate,
41
- _ref$zoidComponents = _ref.zoidComponents,
42
- zoidComponents = _ref$zoidComponents === void 0 ? {} : _ref$zoidComponents;
43
-
44
- _classCallCheck(this, TestMountFormInstance);
45
-
46
- this.configs = configs;
47
- this.options = options;
48
- this.form = form;
49
- this.loader = loader;
50
- this.translate = translate;
51
- this.zoidComponents = zoidComponents;
52
- }
53
-
54
- _createClass(TestMountFormInstance, [{
55
- key: "mountForm",
56
- value: function mountForm(readyToPayAndSummary) {
57
- this.loader.DOM.form = this.form;
58
-
59
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
60
- args[_key - 1] = arguments[_key];
61
- }
62
-
63
- return _form.MountForm.apply(this, args.concat(readyToPayAndSummary));
64
- }
65
- }]);
66
-
67
- return TestMountFormInstance;
68
- }();
69
-
70
- var options = {
71
- intent: {
72
- countryCode: 'US',
73
- items: [{
74
- planId: 'my-awesome-product',
75
- quantity: 1,
76
- thumbnail: ''
77
- }, {
78
- planId: 'awesome-t-shirt',
79
- quantity: 2,
80
- thumbnail: ''
81
- }]
82
- },
83
- paymentInstruments: {
84
- compactExpressInstruments: true
85
- }
86
- };
87
- var summaryData = new _summaryModel["default"]({
88
- currency: "USD",
89
- lineItems: [{
90
- type: "debit",
91
- description: "My Awesome Product",
92
- unitPrice: 30,
93
- quantity: 1,
94
- price: 30,
95
- productId: "my-awesome-product",
96
- planId: "my-awesome-product"
97
- }, {
98
- type: "debit",
99
- description: "Awesome T-Shirt",
100
- unitPrice: 20,
101
- quantity: 2,
102
- price: 40,
103
- productId: "my-app",
104
- planId: "awesome-t-shirt"
105
- }],
106
- subtotalAmount: 70,
107
- taxAmount: 0,
108
- shippingAmount: 0,
109
- discountsAmount: 0,
110
- total: 70
111
- });
112
- var readyToPayData = [new _readyToPayModel["default"](), new _readyToPayModel["default"]({
113
- method: 'payment-card',
114
- feature: {
115
- name: 'Google Pay'
116
- },
117
- brands: ['Visa'],
118
- filters: []
119
- })];
120
- var configs = {
121
- websiteId: 'test-website-id'
122
- };
123
- it('should inject the proper HTML for express methods', function () {
124
- var mountSummaryInstance = new TestMountFormInstance({
125
- configs: configs,
126
- options: options
127
- });
128
- mountSummaryInstance.mountForm({
129
- summary: summaryData,
130
- readyToPay: readyToPayData
131
- });
132
- var form = document.querySelector('.rebilly-instruments-form');
133
- expect(form).toMatchSnapshot();
134
- });
135
- });
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getMethodData = void 0;
7
-
8
- var _utils = require("../../utils");
9
-
10
- var getMethodData = function getMethodData(method) {
11
- var _method$feature, _method$feature2;
12
-
13
- var METHOD_ID = (0, _utils.kebabCase)(((_method$feature = method.feature) === null || _method$feature === void 0 ? void 0 : _method$feature.name) || method.method);
14
- var METHOD_TYPE = (0, _utils.camelCase)(((_method$feature2 = method.feature) === null || _method$feature2 === void 0 ? void 0 : _method$feature2.name) || method.method).replace('-', '');
15
- return {
16
- METHOD_ID: METHOD_ID,
17
- METHOD_TYPE: METHOD_TYPE
18
- };
19
- };
20
-
21
- exports.getMethodData = getMethodData;