@rebilly/instruments 3.0.0-beta.0 → 3.1.2-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 (169) hide show
  1. package/dist/index.js +88 -107
  2. package/dist/index.min.js +88 -0
  3. package/package.json +17 -6
  4. package/rollup.config.js +84 -0
  5. package/src/functions/mount/fetch-data.js +13 -1
  6. package/src/functions/mount/index.js +6 -42
  7. package/src/functions/mount/setup-framepay-theme.js +2 -2
  8. package/src/functions/mount/setup-options.js +3 -0
  9. package/src/functions/mount/setup-user-flow.js +49 -0
  10. package/src/functions/purchase.js +1 -1
  11. package/src/functions/setup.js +1 -1
  12. package/src/functions/show.spec.js +1 -1
  13. package/src/i18n/en.json +3 -0
  14. package/src/i18n/index.js +1 -1
  15. package/src/index.js +1 -61
  16. package/src/instance.js +65 -0
  17. package/src/{index.spec.js → instance.spec.js} +2 -1
  18. package/src/loader/index.js +21 -1
  19. package/src/storefront/models/ready-to-pay-model.js +13 -2
  20. package/src/storefront/plans.js +8 -4
  21. package/src/storefront/plans.spec.js +8 -2
  22. package/src/storefront/products.js +8 -4
  23. package/src/storefront/products.spec.js +8 -2
  24. package/src/storefront/ready-to-pay.js +5 -4
  25. package/src/style/base/__snapshots__/theme.spec.js.snap +34 -2
  26. package/src/style/base/default-theme.js +106 -3
  27. package/src/style/components/button.js +17 -1
  28. package/src/style/components/forms/label.js +0 -5
  29. package/src/style/components/loader.js +2 -1
  30. package/src/style/payment-instruments/payment-card.js +2 -1
  31. package/src/style/utils/remove-empty-null.js +9 -9
  32. package/src/style/vendor/postmate.js +13 -0
  33. package/src/style/views/confirmation.js +2 -1
  34. package/src/views/common/iframe/base-iframe.js +2 -0
  35. package/src/views/common/iframe/event-listeners.js +10 -0
  36. package/src/views/common/iframe/method-iframe.js +3 -1
  37. package/src/views/confirmation.js +1 -0
  38. package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
  39. package/src/views/method-selector/mount-express-methods.js +6 -18
  40. package/src/views/result.js +1 -0
  41. package/tests/mocks/rebilly-instruments-mock.js +2 -2
  42. package/dist/events/base-event.js +0 -66
  43. package/dist/events/events.spec.js +0 -18
  44. package/dist/events/index.js +0 -22
  45. package/dist/functions/destroy.js +0 -34
  46. package/dist/functions/destroy.spec.js +0 -69
  47. package/dist/functions/mount/fetch-data.js +0 -187
  48. package/dist/functions/mount/fetch-data.spec.js +0 -189
  49. package/dist/functions/mount/index.js +0 -218
  50. package/dist/functions/mount/mount.spec.js +0 -64
  51. package/dist/functions/mount/setup-element.js +0 -40
  52. package/dist/functions/mount/setup-framepay-theme.js +0 -95
  53. package/dist/functions/mount/setup-framepay.js +0 -46
  54. package/dist/functions/mount/setup-i18n.js +0 -33
  55. package/dist/functions/mount/setup-options.js +0 -99
  56. package/dist/functions/mount/setup-options.spec.js +0 -66
  57. package/dist/functions/mount/setup-storefront.js +0 -34
  58. package/dist/functions/mount/setup-styles.js +0 -43
  59. package/dist/functions/on.js +0 -40
  60. package/dist/functions/on.spec.js +0 -55
  61. package/dist/functions/purchase.js +0 -158
  62. package/dist/functions/purchase.spec.js +0 -74
  63. package/dist/functions/setup.js +0 -85
  64. package/dist/functions/setup.spec.js +0 -87
  65. package/dist/functions/show.js +0 -55
  66. package/dist/functions/show.spec.js +0 -61
  67. package/dist/functions/update.js +0 -74
  68. package/dist/functions/update.spec.js +0 -86
  69. package/dist/i18n/en.json +0 -22
  70. package/dist/i18n/es.json +0 -22
  71. package/dist/i18n/i18n.spec.js +0 -22
  72. package/dist/i18n/index.js +0 -72
  73. package/dist/index.spec.js +0 -35
  74. package/dist/loader/index.js +0 -94
  75. package/dist/loader/loader.spec.js +0 -69
  76. package/dist/storefront/index.js +0 -73
  77. package/dist/storefront/invoices.js +0 -27
  78. package/dist/storefront/models/base-model.js +0 -18
  79. package/dist/storefront/models/invoice-model.js +0 -14
  80. package/dist/storefront/models/plan-model.js +0 -14
  81. package/dist/storefront/models/product-model.js +0 -14
  82. package/dist/storefront/models/ready-to-pay-model.js +0 -46
  83. package/dist/storefront/models/summary-model.js +0 -79
  84. package/dist/storefront/models/transaction-model.js +0 -31
  85. package/dist/storefront/payment-instruments.js +0 -47
  86. package/dist/storefront/payment-instruments.spec.js +0 -55
  87. package/dist/storefront/plans.js +0 -37
  88. package/dist/storefront/plans.spec.js +0 -64
  89. package/dist/storefront/products.js +0 -40
  90. package/dist/storefront/products.spec.js +0 -65
  91. package/dist/storefront/purchase.js +0 -43
  92. package/dist/storefront/purchase.spec.js +0 -48
  93. package/dist/storefront/ready-to-pay.js +0 -58
  94. package/dist/storefront/ready-to-pay.spec.js +0 -69
  95. package/dist/storefront/storefront.spec.js +0 -15
  96. package/dist/storefront/summary.js +0 -55
  97. package/dist/storefront/summary.spec.js +0 -124
  98. package/dist/storefront/transactions.js +0 -27
  99. package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -195
  100. package/dist/style/base/default-theme.js +0 -699
  101. package/dist/style/base/index.js +0 -104
  102. package/dist/style/base/theme.js +0 -41
  103. package/dist/style/base/theme.spec.js +0 -19
  104. package/dist/style/browserslist.js +0 -8
  105. package/dist/style/components/address.js +0 -64
  106. package/dist/style/components/button.js +0 -71
  107. package/dist/style/components/divider.js +0 -48
  108. package/dist/style/components/forms/checkbox.js +0 -86
  109. package/dist/style/components/forms/field.js +0 -65
  110. package/dist/style/components/forms/form.js +0 -28
  111. package/dist/style/components/forms/input.js +0 -86
  112. package/dist/style/components/forms/label.js +0 -69
  113. package/dist/style/components/forms/select.js +0 -95
  114. package/dist/style/components/forms/validation.js +0 -81
  115. package/dist/style/components/icons.js +0 -22
  116. package/dist/style/components/index.js +0 -57
  117. package/dist/style/components/loader.js +0 -50
  118. package/dist/style/components/methods.js +0 -108
  119. package/dist/style/components/overlay.js +0 -33
  120. package/dist/style/helpers/index.js +0 -59
  121. package/dist/style/index.js +0 -50
  122. package/dist/style/payment-instruments/content.js +0 -17
  123. package/dist/style/payment-instruments/index.js +0 -20
  124. package/dist/style/payment-instruments/payment-card.js +0 -35
  125. package/dist/style/utils/border.js +0 -47
  126. package/dist/style/utils/color-values.js +0 -58
  127. package/dist/style/utils/remove-empty-null.js +0 -20
  128. package/dist/style/vendor/framepay.js +0 -37
  129. package/dist/style/vendor/postmate.js +0 -17
  130. package/dist/style/views/confirmation.js +0 -85
  131. package/dist/style/views/index.js +0 -29
  132. package/dist/style/views/method-selector.js +0 -20
  133. package/dist/style/views/modal.js +0 -93
  134. package/dist/style/views/result.js +0 -61
  135. package/dist/style/views/summary.js +0 -127
  136. package/dist/utils/add-dom-element.js +0 -26
  137. package/dist/utils/format-currency.js +0 -15
  138. package/dist/utils/has-valid-css-selector.js +0 -11
  139. package/dist/utils/index.js +0 -55
  140. package/dist/utils/is-dom-element.js +0 -10
  141. package/dist/utils/process-property-as-dom-element.js +0 -38
  142. package/dist/utils/sleep.js +0 -10
  143. package/dist/views/__snapshots__/summary.spec.js.snap +0 -246
  144. package/dist/views/common/iframe/base-iframe.js +0 -59
  145. package/dist/views/common/iframe/event-listeners.js +0 -50
  146. package/dist/views/common/iframe/index.js +0 -19
  147. package/dist/views/common/iframe/method-iframe.js +0 -33
  148. package/dist/views/common/iframe/modal-iframe.js +0 -84
  149. package/dist/views/common/iframe/view-iframe.js +0 -31
  150. package/dist/views/common/render-utilities.js +0 -11
  151. package/dist/views/confirmation.js +0 -92
  152. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
  153. package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
  154. package/dist/views/method-selector/express-methods/google-pay.js +0 -31
  155. package/dist/views/method-selector/express-methods/paypal.js +0 -19
  156. package/dist/views/method-selector/generate-digital-wallet.js +0 -68
  157. package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
  158. package/dist/views/method-selector/get-method-data.js +0 -25
  159. package/dist/views/method-selector/get-payment-methods.js +0 -66
  160. package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
  161. package/dist/views/method-selector/index.js +0 -122
  162. package/dist/views/method-selector/method-selector.spec.js +0 -124
  163. package/dist/views/method-selector/mount-express-methods.js +0 -69
  164. package/dist/views/method-selector/mount-methods.js +0 -74
  165. package/dist/views/modal.js +0 -88
  166. package/dist/views/result.js +0 -40
  167. package/dist/views/summary.js +0 -215
  168. package/dist/views/summary.spec.js +0 -134
  169. package/src/views/method-selector/express-methods/paypal.js +0 -7
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- var _events = _interopRequireWildcard(require("../events"));
4
-
5
- var _baseEvent = _interopRequireDefault(require("../events/base-event"));
6
-
7
- var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
-
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
-
15
- describe('RebillyInstruments Destroy', () => {
16
- it('should be able to destroy instance', async () => {
17
- const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
18
- const formElement = document.querySelector('.form-selector');
19
- const summaryElement = document.querySelector('.summary-selector');
20
- expect(formElement.innerHTML).not.toEqual('');
21
- expect(summaryElement.innerHTML).not.toEqual('');
22
- await rebillyInstruments.destroy();
23
- expect(formElement.innerHTML).toEqual('');
24
- expect(summaryElement.innerHTML).toEqual('');
25
- });
26
- it('should remove registered listeners', async () => {
27
- const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
28
- const fakeEventListener = jest.fn();
29
- _events.default.fakeEvent = new _baseEvent.default('fake-event');
30
-
31
- _events.publicEventNames.push('fake-event');
32
-
33
- rebillyInstruments.on('fake-event', fakeEventListener);
34
-
35
- _events.default.fakeEvent.dispatch();
36
-
37
- expect(fakeEventListener).toHaveBeenCalledTimes(1);
38
- fakeEventListener.mockClear();
39
- await rebillyInstruments.destroy();
40
-
41
- _events.default.fakeEvent.dispatch();
42
-
43
- expect(fakeEventListener).not.toHaveBeenCalled();
44
- });
45
- it('should remove multiple listeners on the same event', async () => {
46
- const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
47
- const fakeEventListener = jest.fn();
48
- const anotherFakeEventListener = jest.fn();
49
- _events.default.fakeEvent = new _baseEvent.default('fake-event');
50
-
51
- _events.publicEventNames.push('fake-event');
52
-
53
- rebillyInstruments.on('fake-event', fakeEventListener);
54
- rebillyInstruments.on('fake-event', anotherFakeEventListener);
55
-
56
- _events.default.fakeEvent.dispatch();
57
-
58
- expect(fakeEventListener).toHaveBeenCalledTimes(1);
59
- expect(anotherFakeEventListener).toHaveBeenCalledTimes(1);
60
- fakeEventListener.mockClear();
61
- anotherFakeEventListener.mockClear();
62
- await rebillyInstruments.destroy();
63
-
64
- _events.default.fakeEvent.dispatch();
65
-
66
- expect(fakeEventListener).not.toHaveBeenCalled();
67
- expect(anotherFakeEventListener).not.toHaveBeenCalled();
68
- });
69
- });
@@ -1,187 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchData = fetchData;
7
- exports.DataInstance = void 0;
8
-
9
- var _riskDataCollector = require("@rebilly/risk-data-collector");
10
-
11
- var _plans = require("../../storefront/plans");
12
-
13
- var _products = require("../../storefront/products");
14
-
15
- var _readyToPay = require("../../storefront/ready-to-pay");
16
-
17
- var _summary = require("../../storefront/summary");
18
-
19
- var _invoices = require("../../storefront/invoices");
20
-
21
- var _transactions = require("../../storefront/transactions");
22
-
23
- class DataInstance {
24
- constructor({
25
- state = {},
26
- ...fields
27
- } = {}) {
28
- var _state$options;
29
-
30
- Object.entries({ ...(state.data || {}),
31
- ...fields
32
- }).forEach(([key, value]) => {
33
- this[key] = value;
34
- });
35
- this.money = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.money) || null;
36
- }
37
-
38
- get amountAndCurrency() {
39
- let currency;
40
- let amount;
41
-
42
- if (this.previewPurchase) {
43
- currency = this.previewPurchase.currency;
44
- amount = this.previewPurchase.total;
45
- } else if (this.invoice) {
46
- currency = this.invoice.currency;
47
- amount = this.invoice.amount;
48
- } else if (this.transaction) {
49
- currency = this.transaction.currency;
50
- amount = this.transaction.amount;
51
- } else if (this.money) {
52
- currency = this.money.currency;
53
- amount = this.money.amount;
54
- }
55
-
56
- return {
57
- amount,
58
- currency
59
- };
60
- }
61
-
62
- get isPayment() {
63
- return this.invoice || this.transaction || this.money;
64
- }
65
-
66
- get isPurchase() {
67
- return this.previewPurchase;
68
- }
69
-
70
- get summaryItems() {
71
- const {
72
- discountsAmount = null,
73
- shippingAmount = null,
74
- subtotalAmount = null,
75
- taxAmount = null
76
- } = this.previewPurchase || this.invoice || {};
77
- return {
78
- discountsAmount,
79
- shippingAmount,
80
- subtotalAmount,
81
- taxAmount
82
- };
83
- }
84
-
85
- get summaryLineItems() {
86
- let lineItems = [];
87
-
88
- if (this.invoice) {
89
- ({
90
- items: lineItems = []
91
- } = this.invoice);
92
- } else {
93
- ({
94
- lineItems = []
95
- } = this.previewPurchase || {});
96
- }
97
-
98
- return lineItems;
99
- }
100
-
101
- get isShippingRequired() {
102
- return this.products.some(product => product.requiresShipping);
103
- }
104
-
105
- }
106
-
107
- exports.DataInstance = DataInstance;
108
-
109
- async function fetchData({
110
- state = null,
111
- riskMetadata = null,
112
- summaryPayload = null,
113
- // Dependancy injectable functions
114
- fetchInvoice = _invoices.fetchInvoice,
115
- fetchTransaction = _transactions.fetchTransaction
116
- }) {
117
- try {
118
- var _state$options2, _state$options3, _state$data, _state$data$transacti, _state$data3;
119
-
120
- let transaction = null;
121
-
122
- if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.transactionId) {
123
- transaction = await fetchTransaction({
124
- data: {
125
- id: state.options.transactionId
126
- },
127
- state
128
- });
129
- state.data.transaction = transaction;
130
- }
131
-
132
- let invoice = null;
133
-
134
- if ((_state$options3 = state.options) !== null && _state$options3 !== void 0 && _state$options3.invoiceId || (_state$data = state.data) !== null && _state$data !== void 0 && (_state$data$transacti = _state$data.transaction) !== null && _state$data$transacti !== void 0 && _state$data$transacti.hasInvoice) {
135
- var _state$options4, _state$data2, _state$data2$transact;
136
-
137
- invoice = await fetchInvoice({
138
- data: {
139
- id: ((_state$options4 = state.options) === null || _state$options4 === void 0 ? void 0 : _state$options4.invoiceId) || ((_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : (_state$data2$transact = _state$data2.transaction) === null || _state$data2$transact === void 0 ? void 0 : _state$data2$transact.invoiceId)
140
- },
141
- state
142
- });
143
- state.data.invoice = invoice;
144
- }
145
-
146
- if (!riskMetadata) {
147
- const {
148
- riskMetadata: data
149
- } = await (0, _riskDataCollector.collectData)();
150
- riskMetadata = data;
151
- }
152
-
153
- state.data = new DataInstance({
154
- state,
155
- invoice,
156
- transaction,
157
- riskMetadata
158
- });
159
- const [readyToPay, previewPurchase] = await Promise.all([((_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.readyToPay) || (0, _readyToPay.fetchReadyToPay)({
160
- riskMetadata,
161
- state
162
- }), state.options.items ? (0, _summary.fetchSummary)({
163
- data: summaryPayload,
164
- state
165
- }) : null]);
166
- const plans = await (0, _plans.fetchPlans)({
167
- state
168
- });
169
- state.data.plans = plans;
170
- const products = await (0, _products.fetchProducts)({
171
- state
172
- });
173
- return new DataInstance({
174
- state,
175
- readyToPay,
176
- previewPurchase,
177
- plans,
178
- products,
179
- invoice,
180
- transaction,
181
- riskMetadata
182
- });
183
- } catch (error) {// console.log(error);
184
- }
185
-
186
- return new DataInstance({});
187
- }
@@ -1,189 +0,0 @@
1
- "use strict";
2
-
3
- var _fetchData = require("./fetch-data");
4
-
5
- var _transactionModel = _interopRequireDefault(require("../../storefront/models/transaction-model"));
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('fetchData function', () => {
10
- it('Should use correct invoice id for invoiceId', async () => {
11
- const mockFetchInvoice = jest.fn();
12
- const invoiceId = 'test-invoice-id';
13
- const invoiceState = {
14
- options: {
15
- invoiceId
16
- }
17
- };
18
- (0, _fetchData.fetchData)({
19
- state: invoiceState,
20
- fetchInvoice: mockFetchInvoice
21
- });
22
- expect(mockFetchInvoice).toBeCalledTimes(1);
23
- expect(mockFetchInvoice).toBeCalledWith(expect.objectContaining({
24
- data: {
25
- id: invoiceId
26
- }
27
- }));
28
- });
29
- it('Should use correct invoice id for transaction with invoiceIds', async () => {
30
- const mockFetchInvoice = jest.fn();
31
- const invoiceId = 'test-invoice-id';
32
- const invoiceState = {
33
- options: {},
34
- data: {
35
- transaction: new _transactionModel.default({
36
- invoiceIds: [invoiceId]
37
- })
38
- }
39
- };
40
- (0, _fetchData.fetchData)({
41
- state: invoiceState,
42
- fetchInvoice: mockFetchInvoice
43
- });
44
- expect(mockFetchInvoice).toBeCalledTimes(1);
45
- expect(mockFetchInvoice).toBeCalledWith(expect.objectContaining({
46
- data: {
47
- id: invoiceId
48
- }
49
- }));
50
- });
51
- it('Should not fetch invoice for transaction with no invoice Ids', async () => {
52
- const mockFetchInvoice = jest.fn();
53
- const invoiceState = {
54
- options: {},
55
- data: {
56
- transaction: new _transactionModel.default({
57
- invoiceIds: []
58
- })
59
- }
60
- };
61
- (0, _fetchData.fetchData)({
62
- state: invoiceState,
63
- fetchInvoice: mockFetchInvoice
64
- });
65
- expect(mockFetchInvoice).toBeCalledTimes(0);
66
- });
67
- });
68
- describe('DataInstance', () => {
69
- it('Should correctly determine amountAndCurrency', () => {
70
- const expectedAmountAndCurrency = {
71
- amount: 10,
72
- currency: 'USD'
73
- };
74
- let fetchedData = new _fetchData.DataInstance({
75
- state: {
76
- options: {
77
- money: { ...expectedAmountAndCurrency
78
- }
79
- }
80
- }
81
- });
82
- expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
83
- fetchedData = new _fetchData.DataInstance({
84
- previewPurchase: {
85
- total: expectedAmountAndCurrency.amount,
86
- currency: expectedAmountAndCurrency.currency
87
- }
88
- });
89
- expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
90
- fetchedData = new _fetchData.DataInstance({
91
- invoice: { ...expectedAmountAndCurrency
92
- }
93
- });
94
- expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
95
- fetchedData = new _fetchData.DataInstance({
96
- transaction: { ...expectedAmountAndCurrency
97
- }
98
- });
99
- expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
100
- fetchedData = new _fetchData.DataInstance();
101
- expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining({
102
- amount: undefined,
103
- currency: undefined
104
- }));
105
- });
106
- it('Should correctly determine isPayment', () => {
107
- let fetchedData = new _fetchData.DataInstance({
108
- state: {
109
- options: {
110
- money: true
111
- }
112
- }
113
- });
114
- expect(fetchedData.isPayment).toBeTruthy();
115
- fetchedData = new _fetchData.DataInstance({
116
- invoice: true
117
- });
118
- expect(fetchedData.isPayment).toBeTruthy();
119
- fetchedData = new _fetchData.DataInstance({
120
- transaction: true
121
- });
122
- expect(fetchedData.isPayment).toBeTruthy();
123
- fetchedData = new _fetchData.DataInstance({
124
- previewPurchase: true
125
- });
126
- expect(fetchedData.isPayment).toBeFalsy();
127
- fetchedData = new _fetchData.DataInstance({});
128
- expect(fetchedData.isPayment).toBeFalsy();
129
- });
130
- it('Should correctly determine isPurchase', () => {
131
- let fetchedData = new _fetchData.DataInstance({
132
- previewPurchase: true
133
- });
134
- expect(fetchedData.isPurchase).toBeTruthy();
135
- fetchedData = new _fetchData.DataInstance({
136
- state: {
137
- options: {
138
- money: true
139
- }
140
- }
141
- });
142
- expect(fetchedData.isPurchase).toBeFalsy();
143
- fetchedData = new _fetchData.DataInstance({
144
- invoice: true
145
- });
146
- expect(fetchedData.isPurchase).toBeFalsy();
147
- fetchedData = new _fetchData.DataInstance({
148
- transaction: true
149
- });
150
- expect(fetchedData.isPurchase).toBeFalsy();
151
- fetchedData = new _fetchData.DataInstance({});
152
- expect(fetchedData.isPurchase).toBeFalsy();
153
- });
154
- it('Should get summaryItems', () => {
155
- const expectedSummaryItems = {
156
- discountsAmount: 1,
157
- shippingAmount: 2,
158
- subtotalAmount: 3,
159
- taxAmount: 4
160
- };
161
- let fetchedData = new _fetchData.DataInstance({
162
- previewPurchase: { ...expectedSummaryItems
163
- }
164
- });
165
- expect(fetchedData.summaryItems).toEqual(expect.objectContaining(expectedSummaryItems));
166
- fetchedData = new _fetchData.DataInstance({
167
- invoice: { ...expectedSummaryItems
168
- }
169
- });
170
- expect(fetchedData.summaryItems).toEqual(expect.objectContaining(expectedSummaryItems));
171
- });
172
- it('Should get summaryLineItems', () => {
173
- const expectedSummaryLineItems = [{
174
- line: 'item'
175
- }];
176
- let fetchedData = new _fetchData.DataInstance({
177
- previewPurchase: {
178
- lineItems: expectedSummaryLineItems
179
- }
180
- });
181
- expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
182
- fetchedData = new _fetchData.DataInstance({
183
- invoice: {
184
- items: expectedSummaryLineItems
185
- }
186
- });
187
- expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
188
- });
189
- });
@@ -1,218 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mount = mount;
7
-
8
- var _summary = require("../../views/summary");
9
-
10
- var _methodSelector = require("../../views/method-selector");
11
-
12
- var _fetchData = require("./fetch-data");
13
-
14
- var _show = require("../show");
15
-
16
- var _on = require("../on");
17
-
18
- var _setupElement = _interopRequireDefault(require("./setup-element"));
19
-
20
- var _setupStorefront = _interopRequireDefault(require("./setup-storefront"));
21
-
22
- var _setupOptions = _interopRequireDefault(require("./setup-options"));
23
-
24
- var _setupFramepay = _interopRequireDefault(require("./setup-framepay"));
25
-
26
- var _setupStyles = _interopRequireDefault(require("./setup-styles"));
27
-
28
- var _setupI18n = _interopRequireDefault(require("./setup-i18n"));
29
-
30
- var _setupFramepayTheme = _interopRequireDefault(require("./setup-framepay-theme"));
31
-
32
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
-
34
- /* eslint-disable max-len */
35
-
36
- /**
37
- * @typedef {object} Item
38
- * @property {string} planId - The Rebilly id of the plan.
39
- * @property {number} quantity - The number of the plans to be purchased.
40
- * @property {string} thumbnail - The source img for the product. Recommend 100px by 100px.
41
- *
42
- * @typedef {object} GooglePayDisplayOptions
43
- * @property {"back" | "white"} [buttonColor=black] - Color of google pay button
44
- * @property {"short" | "long"} [buttonType=short] - The length of the button
45
- * @property {string} [buttonHeight=44px] - The value and units of the button to match other payment buttons
46
- *
47
- * @typedef {object} ApplePayDisplayOptions
48
- * @property {"back" | "white"} [buttonColor=black] - Color of apple pay button
49
- * @property {"short" | "long"} [buttonType=short] - The length of the button
50
- * @property {string} [buttonHeight=44px] - The value and units of the button to match other payment buttons
51
- *
52
- * @typedef {object} ApplePayMerchantOptions
53
- * @property {string} merchantName - The name of the merchant store.
54
- *
55
- * @typedef {object} GooglePay
56
- * @property {GooglePayDisplayOptions} displayOptions - display options for google pay instrument
57
- *
58
- * @typedef {object} ApplePay
59
- * @property {ApplePayDisplayOptions} displayOptions - display options for apple pay instrument
60
- * @property {ApplePayMerchantOptions} merchantOptions - merchant options for apple pay instrument
61
- *
62
- * @typedef {object} PaymentCard
63
- * @property {boolean} [popup=true] - Show method as a button with a form popup. Otherwise the form will be mounted inline.
64
- *
65
- * @typedef {object} Address
66
- * @property {string} [name=default] - One of default, combined, or stacked.
67
- * @property {string} [region=default] - One of default, split, or stacked.
68
- * @property {Array.<"organization" | "phoneNumber">} show - Show extra fields listed.
69
- * @property {Array.<"address" | "address2" | "email | "country" | "region" | "postalCode"">} hide - Hide the listed fields.
70
- * @property {Array.<"organization" | "address" | "address2" | "email" | "phoneNumber" | "country" | "region" | "postalCode">} require - Require the listed fields.
71
- *
72
- * @typedef {object} PaymentInstruments
73
- * @property {boolean} [compactExpressInstruments=true] - Show express methods as inline pill buttons, or list of full width button.
74
- * @property {PaymentCard} paymentCard - settings for payment card instruments
75
- * @property {GooglePay} googlePay - settings for google pay instruments
76
- * @property {ApplePay} applePay - settings for apple pay instruments
77
- * @property {Address} address - customization for address components for all payment instruments.
78
- *
79
- * @typedef {object} Features
80
- * @property {boolean} [autoConfirmation=true] - Will mount the confirmation screen after `instrument-ready` event is triggered.
81
- * @property {boolean} [autoResult=true] - Show results of transaction after `purchase-completed` event is triggered
82
- */
83
-
84
- /**
85
- * Mount library with configurations.
86
- * @param {object} options - The options object
87
- * @param {object} options.state - Global state
88
- * @param {string | HTMLElement} options.form - The CSS class or HTML element were the form will be mounted.
89
- * @param {string | HTMLElement} options.summary - The CSS class or HTML element were the summary will be mounted.
90
- * @param {Item[]} options.items - Which plans the customer is purchasing.
91
- * @param {string} options.invoiceId - The Rebilly id of the invoice used for purchasing.
92
- * @param {string} options.customerJwt - The customer token to access the invoice.
93
- * @param {string} [options.countryCode=USD] - The country code for the transaction
94
- * @param {PaymentInstruments} options.paymentInstruments - settings for various payment instruments
95
- * @param {Features} options.features - flags to enable and disable different features
96
- * @param {string} options.locale - default: auto. Language to render component text
97
- */
98
- async function mount({
99
- state,
100
- ...options
101
- } = {}) {
102
- try {
103
- var _state$data$transacti;
104
-
105
- state.data = {};
106
- state.options = {}; // Setup DOM
107
-
108
- state.form = (0, _setupElement.default)({
109
- element: 'form',
110
- options
111
- });
112
- state.summary = (0, _setupElement.default)({
113
- element: 'summary',
114
- options
115
- }); // Setup loader
116
-
117
- state.loader.addDOMElement({
118
- el: state.form
119
- });
120
- state.loader.addDOMElement({
121
- section: 'summary',
122
- el: state.summary
123
- });
124
- state.loader.startLoading({
125
- section: 'summary',
126
- id: 'initSummary'
127
- });
128
- state.loader.startLoading({
129
- id: 'initForm'
130
- }); // Setup state
131
-
132
- state.storefront = (0, _setupStorefront.default)({
133
- options
134
- });
135
- state.options = (0, _setupOptions.default)({
136
- options
137
- });
138
- state.mainStyle = await (0, _setupStyles.default)({
139
- options
140
- });
141
- state.data = await (0, _fetchData.fetchData)({
142
- state
143
- });
144
- state.options.themeFramepay = await (0, _setupFramepayTheme.default)({
145
- state,
146
- options
147
- });
148
- const i18n = (0, _setupI18n.default)({
149
- state
150
- });
151
- (0, _setupFramepay.default)({
152
- state
153
- });
154
-
155
- if (state.data.transaction && ((_state$data$transacti = state.data.transaction) === null || _state$data$transacti === void 0 ? void 0 : _state$data$transacti.type) === 'setup') {
156
- state.options.transactionType = 'setup';
157
- } // Mount content
158
-
159
-
160
- if (state.form) {
161
- (0, _methodSelector.mountMethodSelector)({
162
- state
163
- });
164
- }
165
-
166
- if (state.summary) {
167
- (0, _summary.mountSummary)({
168
- state
169
- });
170
- }
171
-
172
- i18n({
173
- state
174
- });
175
- state.hasMounted = true;
176
- } catch (error) {
177
- throw error;
178
- }
179
-
180
- if (state.options.features.autoConfirmation) {
181
- (0, _on.on)({
182
- eventName: 'instrument-ready',
183
- callback: payload => {
184
- (0, _show.show)({
185
- componentName: 'confirmation',
186
- payload,
187
- state
188
- });
189
- }
190
- });
191
- }
192
-
193
- if (state.options.features.autoResult) {
194
- if (state.options.transactionType === 'setup') {
195
- (0, _on.on)({
196
- eventName: 'setup-completed',
197
- callback: payload => {
198
- (0, _show.show)({
199
- componentName: 'result',
200
- payload,
201
- state
202
- });
203
- }
204
- });
205
- } else {
206
- (0, _on.on)({
207
- eventName: 'purchase-completed',
208
- callback: payload => {
209
- (0, _show.show)({
210
- componentName: 'result',
211
- payload,
212
- state
213
- });
214
- }
215
- });
216
- }
217
- }
218
- }