@rebilly/instruments 2.1.1-beta.0 → 3.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 (192) hide show
  1. package/dist/index.js +88 -107
  2. package/dist/index.min.js +88 -0
  3. package/package.json +18 -5
  4. package/rollup.config.js +84 -0
  5. package/src/functions/mount/fetch-data.js +16 -0
  6. package/src/functions/mount/index.js +8 -42
  7. package/src/functions/mount/mount.spec.js +3 -5
  8. package/src/functions/mount/setup-framepay-theme.js +82 -0
  9. package/src/functions/mount/setup-options.js +6 -0
  10. package/src/functions/mount/setup-user-flow.js +49 -0
  11. package/src/functions/purchase.js +1 -1
  12. package/src/functions/setup.js +1 -1
  13. package/src/functions/show.spec.js +1 -1
  14. package/src/i18n/en.json +4 -1
  15. package/src/i18n/index.js +1 -1
  16. package/src/index.js +1 -61
  17. package/src/instance.js +65 -0
  18. package/src/{index.spec.js → instance.spec.js} +2 -1
  19. package/src/loader/index.js +21 -1
  20. package/src/storefront/models/ready-to-pay-model.js +13 -2
  21. package/src/storefront/plans.js +8 -4
  22. package/src/storefront/plans.spec.js +8 -2
  23. package/src/storefront/products.js +8 -4
  24. package/src/storefront/products.spec.js +8 -2
  25. package/src/storefront/ready-to-pay.js +5 -4
  26. package/src/style/base/__snapshots__/theme.spec.js.snap +220 -45
  27. package/src/style/base/default-theme.js +777 -0
  28. package/src/style/base/index.js +48 -16
  29. package/src/style/base/theme.js +17 -47
  30. package/src/style/base/theme.spec.js +4 -16
  31. package/src/style/components/address.js +3 -3
  32. package/src/style/components/button.js +48 -24
  33. package/src/style/components/divider.js +9 -9
  34. package/src/style/components/forms/checkbox.js +11 -11
  35. package/src/style/components/forms/field.js +18 -6
  36. package/src/style/components/forms/form.js +2 -2
  37. package/src/style/components/forms/input.js +54 -13
  38. package/src/style/components/forms/label.js +39 -18
  39. package/src/style/components/forms/select.js +54 -22
  40. package/src/style/components/forms/validation.js +53 -6
  41. package/src/style/components/icons.js +4 -4
  42. package/src/style/components/loader.js +6 -6
  43. package/src/style/components/methods.js +18 -15
  44. package/src/style/components/overlay.js +5 -5
  45. package/src/style/helpers/index.js +46 -46
  46. package/src/style/index.js +2 -1
  47. package/src/style/payment-instruments/payment-card.js +6 -5
  48. package/src/style/utils/border.js +34 -0
  49. package/src/style/utils/color-values.js +27 -1
  50. package/src/style/utils/remove-empty-null.js +10 -0
  51. package/src/style/vendor/framepay.js +11 -8
  52. package/src/style/vendor/postmate.js +15 -2
  53. package/src/style/views/confirmation.js +15 -14
  54. package/src/style/views/method-selector.js +2 -2
  55. package/src/style/views/modal.js +6 -6
  56. package/src/style/views/result.js +4 -4
  57. package/src/style/views/summary.js +23 -23
  58. package/src/views/__snapshots__/summary.spec.js.snap +4 -40
  59. package/src/views/common/iframe/base-iframe.js +2 -0
  60. package/src/views/common/iframe/event-listeners.js +10 -0
  61. package/src/views/common/iframe/method-iframe.js +3 -1
  62. package/src/views/common/iframe/modal-iframe.js +7 -1
  63. package/src/views/confirmation.js +1 -0
  64. package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
  65. package/src/views/method-selector/mount-express-methods.js +6 -18
  66. package/src/views/result.js +1 -0
  67. package/src/views/summary.js +17 -11
  68. package/tests/mocks/rebilly-instruments-mock.js +2 -2
  69. package/dist/events/base-event.js +0 -66
  70. package/dist/events/events.spec.js +0 -18
  71. package/dist/events/index.js +0 -22
  72. package/dist/functions/destroy.js +0 -34
  73. package/dist/functions/destroy.spec.js +0 -69
  74. package/dist/functions/mount/fetch-data.js +0 -183
  75. package/dist/functions/mount/fetch-data.spec.js +0 -189
  76. package/dist/functions/mount/index.js +0 -212
  77. package/dist/functions/mount/mount.spec.js +0 -66
  78. package/dist/functions/mount/setup-element.js +0 -40
  79. package/dist/functions/mount/setup-framepay.js +0 -46
  80. package/dist/functions/mount/setup-i18n.js +0 -33
  81. package/dist/functions/mount/setup-options.js +0 -96
  82. package/dist/functions/mount/setup-options.spec.js +0 -66
  83. package/dist/functions/mount/setup-storefront.js +0 -34
  84. package/dist/functions/mount/setup-styles.js +0 -43
  85. package/dist/functions/on.js +0 -40
  86. package/dist/functions/on.spec.js +0 -55
  87. package/dist/functions/purchase.js +0 -158
  88. package/dist/functions/purchase.spec.js +0 -74
  89. package/dist/functions/setup.js +0 -85
  90. package/dist/functions/setup.spec.js +0 -87
  91. package/dist/functions/show.js +0 -55
  92. package/dist/functions/show.spec.js +0 -61
  93. package/dist/functions/update.js +0 -74
  94. package/dist/functions/update.spec.js +0 -86
  95. package/dist/i18n/en.json +0 -22
  96. package/dist/i18n/es.json +0 -22
  97. package/dist/i18n/i18n.spec.js +0 -22
  98. package/dist/i18n/index.js +0 -72
  99. package/dist/index.spec.js +0 -35
  100. package/dist/loader/index.js +0 -94
  101. package/dist/loader/loader.spec.js +0 -69
  102. package/dist/storefront/index.js +0 -73
  103. package/dist/storefront/invoices.js +0 -27
  104. package/dist/storefront/models/base-model.js +0 -18
  105. package/dist/storefront/models/invoice-model.js +0 -14
  106. package/dist/storefront/models/plan-model.js +0 -14
  107. package/dist/storefront/models/product-model.js +0 -14
  108. package/dist/storefront/models/ready-to-pay-model.js +0 -46
  109. package/dist/storefront/models/summary-model.js +0 -79
  110. package/dist/storefront/models/transaction-model.js +0 -31
  111. package/dist/storefront/payment-instruments.js +0 -47
  112. package/dist/storefront/payment-instruments.spec.js +0 -55
  113. package/dist/storefront/plans.js +0 -37
  114. package/dist/storefront/plans.spec.js +0 -64
  115. package/dist/storefront/products.js +0 -40
  116. package/dist/storefront/products.spec.js +0 -65
  117. package/dist/storefront/purchase.js +0 -43
  118. package/dist/storefront/purchase.spec.js +0 -48
  119. package/dist/storefront/ready-to-pay.js +0 -58
  120. package/dist/storefront/ready-to-pay.spec.js +0 -69
  121. package/dist/storefront/storefront.spec.js +0 -15
  122. package/dist/storefront/summary.js +0 -55
  123. package/dist/storefront/summary.spec.js +0 -124
  124. package/dist/storefront/transactions.js +0 -27
  125. package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -52
  126. package/dist/style/base/index.js +0 -72
  127. package/dist/style/base/theme.js +0 -74
  128. package/dist/style/base/theme.spec.js +0 -30
  129. package/dist/style/browserslist.js +0 -8
  130. package/dist/style/components/address.js +0 -64
  131. package/dist/style/components/button.js +0 -61
  132. package/dist/style/components/divider.js +0 -48
  133. package/dist/style/components/forms/checkbox.js +0 -83
  134. package/dist/style/components/forms/field.js +0 -53
  135. package/dist/style/components/forms/form.js +0 -28
  136. package/dist/style/components/forms/input.js +0 -45
  137. package/dist/style/components/forms/label.js +0 -43
  138. package/dist/style/components/forms/select.js +0 -63
  139. package/dist/style/components/forms/validation.js +0 -34
  140. package/dist/style/components/icons.js +0 -22
  141. package/dist/style/components/index.js +0 -57
  142. package/dist/style/components/loader.js +0 -48
  143. package/dist/style/components/methods.js +0 -105
  144. package/dist/style/components/overlay.js +0 -33
  145. package/dist/style/helpers/index.js +0 -59
  146. package/dist/style/index.js +0 -48
  147. package/dist/style/payment-instruments/content.js +0 -17
  148. package/dist/style/payment-instruments/index.js +0 -20
  149. package/dist/style/payment-instruments/payment-card.js +0 -35
  150. package/dist/style/utils/color-values.js +0 -22
  151. package/dist/style/vendor/framepay.js +0 -34
  152. package/dist/style/vendor/postmate.js +0 -17
  153. package/dist/style/views/confirmation.js +0 -85
  154. package/dist/style/views/index.js +0 -29
  155. package/dist/style/views/method-selector.js +0 -20
  156. package/dist/style/views/modal.js +0 -93
  157. package/dist/style/views/result.js +0 -61
  158. package/dist/style/views/summary.js +0 -127
  159. package/dist/utils/add-dom-element.js +0 -26
  160. package/dist/utils/format-currency.js +0 -15
  161. package/dist/utils/has-valid-css-selector.js +0 -11
  162. package/dist/utils/index.js +0 -55
  163. package/dist/utils/is-dom-element.js +0 -10
  164. package/dist/utils/process-property-as-dom-element.js +0 -38
  165. package/dist/utils/sleep.js +0 -10
  166. package/dist/views/__snapshots__/summary.spec.js.snap +0 -282
  167. package/dist/views/common/iframe/base-iframe.js +0 -59
  168. package/dist/views/common/iframe/event-listeners.js +0 -50
  169. package/dist/views/common/iframe/index.js +0 -19
  170. package/dist/views/common/iframe/method-iframe.js +0 -33
  171. package/dist/views/common/iframe/modal-iframe.js +0 -79
  172. package/dist/views/common/iframe/view-iframe.js +0 -31
  173. package/dist/views/common/render-utilities.js +0 -11
  174. package/dist/views/confirmation.js +0 -92
  175. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
  176. package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
  177. package/dist/views/method-selector/express-methods/google-pay.js +0 -31
  178. package/dist/views/method-selector/express-methods/paypal.js +0 -19
  179. package/dist/views/method-selector/generate-digital-wallet.js +0 -68
  180. package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
  181. package/dist/views/method-selector/get-method-data.js +0 -25
  182. package/dist/views/method-selector/get-payment-methods.js +0 -66
  183. package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
  184. package/dist/views/method-selector/index.js +0 -122
  185. package/dist/views/method-selector/method-selector.spec.js +0 -124
  186. package/dist/views/method-selector/mount-express-methods.js +0 -69
  187. package/dist/views/method-selector/mount-methods.js +0 -74
  188. package/dist/views/modal.js +0 -88
  189. package/dist/views/result.js +0 -40
  190. package/dist/views/summary.js +0 -209
  191. package/dist/views/summary.spec.js +0 -134
  192. package/src/views/method-selector/express-methods/paypal.js +0 -7
@@ -1,209 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.lineItemHTML = lineItemHTML;
7
- exports.summaryBreakdownHTML = summaryBreakdownHTML;
8
- exports.mountSummary = mountSummary;
9
- exports.updateSummary = updateSummary;
10
-
11
- var _riskDataCollector = require("@rebilly/risk-data-collector");
12
-
13
- var _utils = require("../utils");
14
-
15
- var _fetchData = require("../functions/mount/fetch-data");
16
-
17
- function lineItemHTML({
18
- state,
19
- lineItem
20
- }) {
21
- var _state$data;
22
-
23
- const {
24
- products
25
- } = state.data;
26
- const {
27
- currency = null
28
- } = (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.amountAndCurrency;
29
- const {
30
- items: optionItems = []
31
- } = state.options;
32
- const hasThumbnails = optionItems === null || optionItems === void 0 ? void 0 : optionItems.some(optionItem => optionItem.thumbnail);
33
- const {
34
- thumbnail = null
35
- } = optionItems.find(optionItem => optionItem.planId === lineItem.planId) || {};
36
- const {
37
- name
38
- } = products.find(product => product.id === lineItem.productId);
39
- return `
40
- <div class="rebilly-instruments-summary-line-item">
41
- ${hasThumbnails ? `
42
- <figure class="rebilly-instruments-summary-line-item-figure">
43
- ${thumbnail ? `<img src="${thumbnail}" alt="${name}">` : ''}
44
- </figure>
45
- ` : ''}
46
- <div class="rebilly-instruments-summary-line-item-synopsis">
47
- <p class="rebilly-instruments-summary-line-item-synopsis-title">${name}</p>
48
- ${lineItem.description ? `
49
- <p class="rebilly-instruments-summary-line-item-synopsis-description">${lineItem.description}</p>
50
- ` : ''}
51
- </div>
52
- <div class="rebilly-instruments-summary-line-item-price-breakdown">
53
- <p class="rebilly-instruments-summary-line-item-price-breakdown-quantity">${lineItem.quantity}</p>
54
- <svg class="rebilly-instruments-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
55
- <path d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z" fill-rule="nonzero"/>
56
- </svg>
57
- <p class="rebilly-instruments-summary-line-item-price-breakdown-unit-price">${(0, _utils.formatCurrency)(lineItem.unitPrice, currency)}</p>
58
- </div>
59
- </div>
60
- `;
61
- }
62
-
63
- function summaryBreakdownHTML({
64
- state,
65
- element
66
- }) {
67
- const {
68
- amount = null,
69
- currency = null,
70
- discountsAmount = null,
71
- shippingAmount = null,
72
- subtotalAmount = null,
73
- taxAmount = null
74
- } = { ...state.data.amountAndCurrency,
75
- ...state.data.summaryItems
76
- };
77
- let table = null;
78
- [{
79
- label: 'Sub Total',
80
- class: 'sub-total',
81
- i18n: 'summary.subTotal',
82
- value: subtotalAmount
83
- }, {
84
- label: 'Discounts',
85
- class: 'discounts',
86
- i18n: 'summary.discounts',
87
- value: discountsAmount
88
- }, {
89
- label: 'Taxes',
90
- class: 'taxes',
91
- i18n: 'summary.taxes',
92
- value: taxAmount
93
- }, {
94
- label: 'Shipping',
95
- class: 'shipping',
96
- i18n: 'summary.shipping',
97
- value: shippingAmount
98
- }].filter(({
99
- value
100
- }) => value !== null).forEach(item => {
101
- if (!table) {
102
- table = document.createElement('table');
103
- table.insertAdjacentHTML('beforeend', `
104
- <colgroup>
105
- <col>
106
- <col>
107
- </colgroup>
108
- `);
109
- }
110
-
111
- const row = document.createElement('tr');
112
- row.setAttribute('class', `rebilly-instruments-summary-breakdown-${item.class}`);
113
- row.insertAdjacentHTML('beforeend', `
114
- <td data-rebilly-i18n="${item.i18n}">${item.label}</td>
115
- <td>${(0, _utils.formatCurrency)(item.value, currency)}</td>
116
- `);
117
- table.appendChild(row);
118
- });
119
-
120
- if (table) {
121
- element.appendChild(table);
122
- }
123
-
124
- const totalElement = document.createElement('div');
125
- totalElement.setAttribute('class', 'rebilly-instruments-summary-breakdown-total');
126
- totalElement.insertAdjacentHTML('beforeend', `
127
- <p data-rebilly-i18n="summary.total">Total</p>
128
- <p class="rebilly-instruments-summary-breakdown-total-amount">
129
- <span class="rebilly-instruments-summary-breakdown-total-amount-currency">
130
- ${currency}
131
- </span>
132
- ${(0, _utils.formatCurrency)(amount, currency)}
133
- <p>
134
- `);
135
- element.appendChild(totalElement);
136
- return element;
137
- }
138
-
139
- async function mountSummary({
140
- state
141
- }) {
142
- const contentContainer = document.createElement('div');
143
- contentContainer.setAttribute('class', 'rebilly-instruments-content');
144
- const lineItems = state.data.summaryLineItems;
145
-
146
- if (lineItems) {
147
- const lineItemsElement = document.createElement('div');
148
- lineItemsElement.setAttribute('class', 'rebilly-instruments-summary-line-items');
149
- lineItems.forEach(lineItem => {
150
- lineItemsElement.insertAdjacentHTML('beforeend', lineItemHTML({
151
- state,
152
- lineItem
153
- }));
154
- });
155
- contentContainer.appendChild(lineItemsElement);
156
- }
157
-
158
- const summaryBreakdownElement = document.createElement('div');
159
- summaryBreakdownElement.setAttribute('class', 'rebilly-instruments-summary-breakdown');
160
- contentContainer.appendChild(summaryBreakdownHTML({
161
- state,
162
- element: summaryBreakdownElement
163
- }));
164
- state.summary.appendChild(contentContainer);
165
- state.summary.style.minHeight = '';
166
- state.translate.translateItems();
167
- state.loader.stopLoading({
168
- section: 'summary',
169
- id: 'initSummary'
170
- });
171
- }
172
-
173
- async function updateSummary({
174
- state,
175
- instrument = null
176
- }) {
177
- var _state$data$transacti;
178
-
179
- state.loader.startLoading({
180
- section: 'summary',
181
- id: 'initSummary'
182
- });
183
- const {
184
- riskMetadata
185
- } = await (0, _riskDataCollector.collectData)();
186
- let summaryPayload;
187
-
188
- if (instrument !== null && instrument !== void 0 && instrument.billingAddress) {
189
- summaryPayload = {
190
- billingAddress: instrument.billingAddress
191
- };
192
- }
193
-
194
- state.data = await (0, _fetchData.fetchData)({
195
- riskMetadata,
196
- summaryPayload,
197
- state
198
- });
199
-
200
- if (state.data.transaction && ((_state$data$transacti = state.data.transaction) === null || _state$data$transacti === void 0 ? void 0 : _state$data$transacti.type) === 'setup') {
201
- state.options.transactionType = 'setup';
202
- }
203
-
204
- const itemsContainer = state.summary.querySelector('.rebilly-instruments-content');
205
- itemsContainer === null || itemsContainer === void 0 ? void 0 : itemsContainer.remove();
206
- mountSummary({
207
- state
208
- });
209
- }
@@ -1,134 +0,0 @@
1
- "use strict";
2
-
3
- var _summaryModel = _interopRequireDefault(require("../storefront/models/summary-model"));
4
-
5
- var _planModel = _interopRequireDefault(require("../storefront/models/plan-model"));
6
-
7
- var _productModel = _interopRequireDefault(require("../storefront/models/product-model"));
8
-
9
- var _loader = require("../loader");
10
-
11
- var _i18n = require("../i18n");
12
-
13
- var _summary = require("./summary");
14
-
15
- var _fetchData = require("../functions/mount/fetch-data");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Summary component', () => {
20
- let summaryElement;
21
- beforeEach(() => {
22
- document.body.innerHTML = '';
23
- summaryElement = document.createElement('div');
24
- document.body.append(summaryElement);
25
- });
26
-
27
- class TestMountSummaryInstance {
28
- constructor({
29
- options = {},
30
- summary = summaryElement,
31
- loader = new _loader.Loader(),
32
- translate = new _i18n.Translate(),
33
- data = {}
34
- } = {}) {
35
- this.options = options;
36
- this.summary = summary;
37
- this.loader = loader;
38
- this.translate = translate;
39
- this.data = new _fetchData.DataInstance({
40
- state: {
41
- options
42
- },
43
- previewPurchase: new _summaryModel.default({
44
- currency: 'USD',
45
- lineItems: [{
46
- type: 'debit',
47
- description: 'My Awesome Product',
48
- unitPrice: 30,
49
- quantity: 1,
50
- price: 30,
51
- productId: 'test-product-1',
52
- planId: 'my-awesome-product'
53
- }, {
54
- type: 'debit',
55
- description: 'Awesome T-Shirt',
56
- unitPrice: 20,
57
- quantity: 2,
58
- price: 40,
59
- productId: 'test-product-2',
60
- planId: 'awesome-t-shirt'
61
- }],
62
- subtotalAmount: 70,
63
- taxAmount: 0,
64
- shippingAmount: 0,
65
- discountsAmount: 0,
66
- total: 70
67
- }),
68
- plans: [new _planModel.default({
69
- name: 'My Awesome Product',
70
- id: 'my-awesome-product',
71
- productId: 'test-product-1'
72
- }), new _planModel.default({
73
- name: 'My Awesome T-Shirt',
74
- id: 'awesome-t-shirt',
75
- productId: 'test-product-2'
76
- })],
77
- products: [new _productModel.default({
78
- name: 'My Awesome Product',
79
- id: 'test-product-1'
80
- }), new _productModel.default({
81
- name: 'My Awesome T-Shirt',
82
- id: 'test-product-2'
83
- })],
84
- ...data
85
- });
86
- }
87
-
88
- }
89
-
90
- const options = {
91
- websiteId: 'test-website-id',
92
- countryCode: 'US',
93
- items: [{
94
- planId: 'my-awesome-product',
95
- quantity: 1,
96
- thumbnail: ''
97
- }, {
98
- planId: 'awesome-t-shirt',
99
- quantity: 2,
100
- thumbnail: ''
101
- }]
102
- };
103
- it('should render the summary correctly', () => {
104
- const mountSummaryInstance = new TestMountSummaryInstance({
105
- options
106
- }); //TODO: improve design to avoid this manual change
107
-
108
- mountSummaryInstance.loader.DOM.summary = mountSummaryInstance.summary;
109
- (0, _summary.mountSummary)({
110
- state: mountSummaryInstance
111
- }); // Number of line items
112
-
113
- const itemsContainer = document.querySelector('.rebilly-instruments-summary-line-items');
114
- expect(itemsContainer).toMatchSnapshot(); // Breakdown
115
-
116
- const summaryBreakdown = document.querySelector('.rebilly-instruments-summary-breakdown');
117
- expect(summaryBreakdown).toMatchSnapshot();
118
- });
119
- it('should not render the plan description if its falsy', () => {
120
- const mountSummaryInstance = new TestMountSummaryInstance({
121
- options
122
- }); // Making one product description falsy
123
-
124
- mountSummaryInstance.data.previewPurchase.lineItems[0].description = null; //TODO: improve design to avoid this manual change
125
-
126
- mountSummaryInstance.loader.DOM.summary = mountSummaryInstance.summary;
127
- (0, _summary.mountSummary)({
128
- state: mountSummaryInstance
129
- }); // Check that only one description is render
130
-
131
- const itemsSynopsysDescription = document.querySelectorAll('.rebilly-instruments-summary-line-item-synopsis-description');
132
- expect(itemsSynopsysDescription.length).toEqual(1);
133
- });
134
- });
@@ -1,7 +0,0 @@
1
-
2
- export default async function mountPaypal({ state, METHOD_ID, METHOD_TYPE }) {
3
- console.log('PayPal - work in progress');
4
- const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
5
- container.style.display = 'none';
6
- state.loader.stopLoading({ id: `${METHOD_TYPE}-express` });
7
- }