@rebilly/instruments 1.0.2-beta.9 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/.babelrc +13 -4
  2. package/.eslintrc.js +3 -0
  3. package/.prettierrc.js +11 -0
  4. package/README.md +15 -314
  5. package/dist/events/base-event.js +6 -9
  6. package/dist/events/events.spec.js +4 -4
  7. package/dist/events/index.js +2 -1
  8. package/dist/functions/destroy.js +12 -14
  9. package/dist/functions/destroy.spec.js +3 -3
  10. package/dist/functions/mount/fetch-data.js +187 -0
  11. package/dist/functions/mount/fetch-data.spec.js +189 -0
  12. package/dist/functions/mount/index.js +164 -251
  13. package/dist/functions/mount/mount.spec.js +25 -124
  14. package/dist/functions/mount/setup-element.js +40 -0
  15. package/dist/functions/mount/setup-framepay-theme.js +95 -0
  16. package/dist/functions/mount/setup-framepay.js +46 -0
  17. package/dist/functions/mount/setup-i18n.js +33 -0
  18. package/dist/functions/mount/setup-options.js +99 -0
  19. package/dist/functions/mount/setup-options.spec.js +66 -0
  20. package/dist/functions/mount/setup-storefront.js +34 -0
  21. package/dist/functions/mount/setup-styles.js +43 -0
  22. package/dist/functions/on.js +13 -4
  23. package/dist/functions/on.spec.js +19 -5
  24. package/dist/functions/purchase.js +139 -22
  25. package/dist/functions/purchase.spec.js +23 -19
  26. package/dist/functions/setup.js +85 -0
  27. package/dist/functions/setup.spec.js +87 -0
  28. package/dist/functions/show.js +31 -14
  29. package/dist/functions/show.spec.js +47 -18
  30. package/dist/functions/update.js +53 -27
  31. package/dist/functions/update.spec.js +40 -21
  32. package/dist/i18n/en.json +5 -2
  33. package/dist/i18n/es.json +4 -1
  34. package/dist/index.js +67 -56
  35. package/dist/index.spec.js +7 -27
  36. package/dist/loader/index.js +4 -3
  37. package/dist/storefront/index.js +33 -0
  38. package/dist/storefront/invoices.js +27 -0
  39. package/dist/storefront/models/base-model.js +18 -0
  40. package/dist/storefront/models/invoice-model.js +14 -0
  41. package/dist/storefront/models/plan-model.js +4 -35
  42. package/dist/storefront/models/product-model.js +4 -23
  43. package/dist/storefront/models/summary-model.js +12 -25
  44. package/dist/storefront/models/transaction-model.js +31 -0
  45. package/dist/storefront/payment-instruments.js +47 -0
  46. package/dist/storefront/payment-instruments.spec.js +55 -0
  47. package/dist/storefront/plans.js +15 -24
  48. package/dist/storefront/plans.spec.js +17 -44
  49. package/dist/storefront/products.js +16 -20
  50. package/dist/storefront/products.spec.js +25 -49
  51. package/dist/storefront/purchase.js +28 -16
  52. package/dist/storefront/purchase.spec.js +4 -22
  53. package/dist/storefront/ready-to-pay.js +26 -22
  54. package/dist/storefront/ready-to-pay.spec.js +25 -54
  55. package/dist/storefront/storefront.spec.js +1 -1
  56. package/dist/storefront/summary.js +27 -24
  57. package/dist/storefront/summary.spec.js +44 -86
  58. package/dist/storefront/transactions.js +27 -0
  59. package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
  60. package/dist/style/base/default-theme.js +699 -0
  61. package/dist/style/base/index.js +48 -16
  62. package/dist/style/base/theme.js +15 -48
  63. package/dist/style/base/theme.spec.js +4 -15
  64. package/dist/style/components/address.js +3 -3
  65. package/dist/style/components/button.js +32 -22
  66. package/dist/style/components/divider.js +9 -9
  67. package/dist/style/components/forms/checkbox.js +12 -9
  68. package/dist/style/components/forms/field.js +18 -6
  69. package/dist/style/components/forms/form.js +2 -2
  70. package/dist/style/components/forms/input.js +54 -13
  71. package/dist/style/components/forms/label.js +44 -18
  72. package/dist/style/components/forms/select.js +54 -22
  73. package/dist/style/components/forms/validation.js +53 -6
  74. package/dist/style/components/icons.js +4 -4
  75. package/dist/style/components/loader.js +5 -3
  76. package/dist/style/components/methods.js +52 -48
  77. package/dist/style/components/overlay.js +5 -5
  78. package/dist/style/helpers/index.js +46 -46
  79. package/dist/style/index.js +3 -1
  80. package/dist/style/payment-instruments/payment-card.js +4 -4
  81. package/dist/style/utils/border.js +47 -0
  82. package/dist/style/utils/color-values.js +37 -3
  83. package/dist/style/utils/remove-empty-null.js +20 -0
  84. package/dist/style/vendor/framepay.js +11 -8
  85. package/dist/style/vendor/postmate.js +2 -2
  86. package/dist/style/views/confirmation.js +13 -13
  87. package/dist/style/views/method-selector.js +3 -3
  88. package/dist/style/views/modal.js +8 -6
  89. package/dist/style/views/result.js +4 -4
  90. package/dist/style/views/summary.js +26 -22
  91. package/dist/utils/format-currency.js +4 -2
  92. package/dist/utils/has-valid-css-selector.js +1 -1
  93. package/dist/utils/process-property-as-dom-element.js +0 -2
  94. package/dist/views/__snapshots__/summary.spec.js.snap +72 -118
  95. package/dist/views/common/iframe/base-iframe.js +10 -2
  96. package/dist/views/common/iframe/modal-iframe.js +50 -4
  97. package/dist/views/confirmation.js +44 -20
  98. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  99. package/dist/views/method-selector/express-methods/google-pay.js +31 -0
  100. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  101. package/dist/views/method-selector/generate-digital-wallet.js +68 -0
  102. package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
  103. package/dist/views/method-selector/get-payment-methods.js +27 -7
  104. package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
  105. package/dist/views/method-selector/index.js +55 -86
  106. package/dist/views/method-selector/method-selector.spec.js +80 -69
  107. package/dist/views/method-selector/mount-express-methods.js +38 -62
  108. package/dist/views/method-selector/mount-methods.js +18 -18
  109. package/dist/views/modal.js +18 -12
  110. package/dist/views/result.js +13 -16
  111. package/dist/views/summary.js +176 -114
  112. package/dist/views/summary.spec.js +72 -76
  113. package/package.json +7 -4
  114. package/src/events/base-event.js +15 -17
  115. package/src/events/events.spec.js +6 -4
  116. package/src/events/index.js +6 -3
  117. package/src/functions/destroy.js +12 -13
  118. package/src/functions/destroy.spec.js +30 -31
  119. package/src/functions/mount/fetch-data.js +152 -0
  120. package/src/functions/mount/fetch-data.spec.js +238 -0
  121. package/src/functions/mount/index.js +131 -244
  122. package/src/functions/mount/mount.spec.js +35 -141
  123. package/src/functions/mount/setup-element.js +26 -0
  124. package/src/functions/mount/setup-framepay-theme.js +82 -0
  125. package/src/functions/mount/setup-framepay.js +41 -0
  126. package/src/functions/mount/setup-i18n.js +19 -0
  127. package/src/functions/mount/setup-options.js +103 -0
  128. package/src/functions/mount/setup-options.spec.js +60 -0
  129. package/src/functions/mount/setup-storefront.js +24 -0
  130. package/src/functions/mount/setup-styles.js +30 -0
  131. package/src/functions/on.js +13 -8
  132. package/src/functions/on.spec.js +30 -17
  133. package/src/functions/purchase.js +101 -19
  134. package/src/functions/purchase.spec.js +18 -18
  135. package/src/functions/setup.js +48 -0
  136. package/src/functions/setup.spec.js +98 -0
  137. package/src/functions/show.js +20 -10
  138. package/src/functions/show.spec.js +43 -22
  139. package/src/functions/update.js +50 -27
  140. package/src/functions/update.spec.js +57 -22
  141. package/src/i18n/en.json +5 -2
  142. package/src/i18n/es.json +4 -1
  143. package/src/i18n/i18n.spec.js +6 -4
  144. package/src/i18n/index.js +14 -11
  145. package/src/index.js +41 -52
  146. package/src/index.spec.js +8 -37
  147. package/src/loader/index.js +51 -47
  148. package/src/loader/loader.spec.js +26 -19
  149. package/src/storefront/index.js +37 -7
  150. package/src/storefront/invoices.js +11 -0
  151. package/src/storefront/models/base-model.js +10 -0
  152. package/src/storefront/models/invoice-model.js +3 -0
  153. package/src/storefront/models/plan-model.js +3 -35
  154. package/src/storefront/models/product-model.js +3 -23
  155. package/src/storefront/models/ready-to-pay-model.js +3 -3
  156. package/src/storefront/models/summary-model.js +15 -29
  157. package/src/storefront/models/transaction-model.js +19 -0
  158. package/src/storefront/payment-instruments.js +30 -0
  159. package/src/storefront/payment-instruments.spec.js +69 -0
  160. package/src/storefront/plans.js +16 -23
  161. package/src/storefront/plans.spec.js +25 -54
  162. package/src/storefront/products.js +18 -22
  163. package/src/storefront/products.spec.js +23 -54
  164. package/src/storefront/purchase.js +14 -14
  165. package/src/storefront/purchase.spec.js +17 -29
  166. package/src/storefront/ready-to-pay.js +26 -23
  167. package/src/storefront/ready-to-pay.spec.js +41 -71
  168. package/src/storefront/storefront.spec.js +1 -1
  169. package/src/storefront/summary.js +26 -22
  170. package/src/storefront/summary.spec.js +60 -109
  171. package/src/storefront/transactions.js +11 -0
  172. package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
  173. package/src/style/base/default-theme.js +674 -0
  174. package/src/style/base/index.js +48 -16
  175. package/src/style/base/theme.js +20 -48
  176. package/src/style/base/theme.spec.js +5 -15
  177. package/src/style/browserslist.js +1 -3
  178. package/src/style/components/address.js +3 -3
  179. package/src/style/components/button.js +32 -22
  180. package/src/style/components/divider.js +9 -9
  181. package/src/style/components/forms/checkbox.js +11 -9
  182. package/src/style/components/forms/field.js +18 -6
  183. package/src/style/components/forms/form.js +2 -2
  184. package/src/style/components/forms/input.js +54 -13
  185. package/src/style/components/forms/label.js +44 -18
  186. package/src/style/components/forms/select.js +54 -22
  187. package/src/style/components/forms/validation.js +53 -6
  188. package/src/style/components/icons.js +4 -4
  189. package/src/style/components/index.js +1 -1
  190. package/src/style/components/loader.js +4 -3
  191. package/src/style/components/methods.js +52 -48
  192. package/src/style/components/overlay.js +5 -5
  193. package/src/style/helpers/index.js +46 -46
  194. package/src/style/index.js +4 -2
  195. package/src/style/payment-instruments/payment-card.js +4 -4
  196. package/src/style/utils/border.js +34 -0
  197. package/src/style/utils/color-values.js +30 -4
  198. package/src/style/utils/remove-empty-null.js +10 -0
  199. package/src/style/vendor/framepay.js +12 -9
  200. package/src/style/vendor/postmate.js +3 -3
  201. package/src/style/views/confirmation.js +13 -13
  202. package/src/style/views/index.js +1 -1
  203. package/src/style/views/method-selector.js +3 -3
  204. package/src/style/views/modal.js +9 -7
  205. package/src/style/views/result.js +4 -4
  206. package/src/style/views/summary.js +26 -22
  207. package/src/utils/add-dom-element.js +12 -13
  208. package/src/utils/format-currency.js +6 -2
  209. package/src/utils/has-valid-css-selector.js +2 -2
  210. package/src/utils/is-dom-element.js +1 -1
  211. package/src/utils/process-property-as-dom-element.js +27 -24
  212. package/src/utils/sleep.js +1 -1
  213. package/src/views/__snapshots__/summary.spec.js.snap +72 -118
  214. package/src/views/common/iframe/base-iframe.js +12 -4
  215. package/src/views/common/iframe/event-listeners.js +6 -6
  216. package/src/views/common/iframe/index.js +1 -1
  217. package/src/views/common/iframe/method-iframe.js +3 -6
  218. package/src/views/common/iframe/modal-iframe.js +48 -6
  219. package/src/views/common/iframe/view-iframe.js +3 -5
  220. package/src/views/common/render-utilities.js +3 -3
  221. package/src/views/confirmation.js +34 -25
  222. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  223. package/src/views/method-selector/express-methods/google-pay.js +24 -0
  224. package/src/views/method-selector/express-methods/paypal.js +7 -0
  225. package/src/views/method-selector/generate-digital-wallet.js +51 -0
  226. package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
  227. package/src/views/method-selector/get-method-data.js +7 -4
  228. package/src/views/method-selector/get-payment-methods.js +38 -31
  229. package/src/views/method-selector/get-payment-methods.spec.js +26 -33
  230. package/src/views/method-selector/index.js +70 -99
  231. package/src/views/method-selector/method-selector.spec.js +88 -78
  232. package/src/views/method-selector/mount-express-methods.js +36 -60
  233. package/src/views/method-selector/mount-methods.js +32 -21
  234. package/src/views/modal.js +36 -22
  235. package/src/views/result.js +12 -15
  236. package/src/views/summary.js +175 -101
  237. package/src/views/summary.spec.js +99 -74
  238. package/tests/async-utilities.js +22 -0
  239. package/tests/mocks/rebilly-instruments-mock.js +89 -77
  240. package/tests/mocks/storefront-api-mock.js +8 -0
  241. package/tests/mocks/storefront-mock.js +17 -0
  242. package/dist/events/purchase-completed.js +0 -24
  243. package/dist/functions/initialize.js +0 -82
  244. package/dist/functions/initialize.spec.js +0 -34
  245. package/dist/functions/mount/fetch-summary-data.js +0 -31
  246. package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
  247. package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
  248. package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
  249. package/src/events/purchase-completed.js +0 -11
  250. package/src/functions/initialize.js +0 -74
  251. package/src/functions/initialize.spec.js +0 -38
  252. package/src/functions/mount/fetch-summary-data.js +0 -26
  253. package/src/functions/mount/fetch-summary-data.spec.js +0 -46
  254. package/src/views/method-selector/process-digital-wallet-options.js +0 -16
  255. package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
@@ -0,0 +1,189 @@
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
+ });
@@ -3,17 +3,31 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Mount = Mount;
6
+ exports.mount = mount;
7
7
 
8
- var _riskDataCollector = require("@rebilly/risk-data-collector");
8
+ var _summary = require("../../views/summary");
9
9
 
10
- var _lodash = _interopRequireDefault(require("lodash.merge"));
10
+ var _methodSelector = require("../../views/method-selector");
11
11
 
12
- var _style = require("../../style");
12
+ var _fetchData = require("./fetch-data");
13
13
 
14
- var _utils = require("../../utils");
14
+ var _show = require("../show");
15
15
 
16
- var _fetchSummaryData = require("./fetch-summary-data");
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"));
17
31
 
18
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
33
 
@@ -24,282 +38,181 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
38
  * @property {string} planId - The Rebilly id of the plan.
25
39
  * @property {number} quantity - The number of the plans to be purchased.
26
40
  * @property {string} thumbnail - The source img for the product. Recommend 100px by 100px.
27
- */
28
-
29
- /**
30
- * @typedef {object} Intent
31
- * @property {"purchase" | "vault"} mode - Which mode the mount is usings. Default "purchase".
32
- * @property {Array.<Item>} items - Which plans the customer is purchasing.
33
- * @property {string} customerId - Which customer is associated with the instrument.
34
- * @property {string} countryCode - The country code for the transaction
35
- */
36
-
37
- /**
38
- * @typedef {GooglePayDisplayOptions} GooglePay
39
- * @param {"back" | "white"} buttonColor - default "black". Color of google pay button
40
- * @param {"short" | "long"} buttonType - default "short". The length of the button
41
- * @param {string} buttonHeight - The value and units of the button to match other payment buttons
42
- * <br>example: "44px", "1rem" etc.
43
- */
44
-
45
- /**
46
- * @typedef {object} GooglePay
47
- * @param {GooglePayDisplayOptions} displayOptions - display options for google pay instrument
48
- */
49
-
50
- /**
51
- * @typedef {object} PaymentCard
52
- * @param {boolean} popup - default: false. Show method as a button with a form popup
53
- * <br>Otherwise the form will be mounted inline.
54
- */
55
-
56
- /**
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
+ *
57
65
  * @typedef {object} Address
58
- * @param {string} name - default: default. One of default, combined, or stacked.
59
- * @param {string} region - default: default. One of default, split, or stacked.
60
- * @param {Array.<"organization" | "phoneNumber">} show. Show extra fields listed.
61
- * @param {Array.<"address" | "address2" | "email | "country" | "region" | "postalCode"">} hide. Hide the listed fields.
62
- * @param {Array.<"organization" | "address" | "address2" | "email" | "phoneNumber" | "country" | "region" | "postalCode">} require.
63
- * <br>If the field name is included, enforce the data for those inputs to be included.
64
- * <br>First name and last name are always required. Country is always required if the products require shipping.
65
- */
66
-
67
- /**
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
+ *
68
72
  * @typedef {object} PaymentInstruments
69
- * @param {boolean} compactExpressInstruments - default: true. Show express methods as
70
- * <br>inline pill buttons, or list of full width button.
71
- * @param {PaymentCard} paymentCard - settings for payment card instruments
72
- * @param {GooglePay} googlePay - settings for google pay instruments
73
- * @param {Address} address - customization for address components for all payment instruments.
74
- */
75
-
76
- /**
77
- * @typedef {object} Features
78
- * @param {boolean} autoConfirmation - default: true. Will mount the confirmation screen after `instrument-ready`
79
- * <br>event is triggered. Will need to trigger purchase manually if set to false.
80
- * <br>Can use RebillyInstruments.show('confirmation', options) to mount defautl component
81
- * @param {boolean} autoResult - default: true. Show results of transaction after `purchase-completed` event is triggered
82
- * <br>Will need to handle purchase result manually if set to false.
83
- * <br>Can use RebillyInstruments.show('result', options) to display default component
84
- */
85
-
86
- /**
87
- * @typedef {object} Options
88
- * @property {Intent} intent - The information required for purchaseing or vaulting an instrument
89
- * @property {PaymentInstruments} paymentInstruments - settings for various payment instruments
90
- * @property {Features} features - flags to enable and disable different features
91
- * @property {string} locale - default: auto. Language to render component text
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
92
82
  */
93
83
 
94
84
  /**
95
85
  * Mount library with configurations.
96
- * @param {string | HTMLElement} form - The CSS class or HTML element were the form will be mounted.
97
- * @param {string | HTMLElement} summary - The CSS class or HTML element were the summary will be mounted.
98
- * @param {Options} options - The configurations that are to be passed to the library for use.
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
99
97
  */
100
- async function Mount({
101
- form = '.rebilly-instruments',
102
- summary = '.rebilly-instruments-summary',
103
- options = {},
104
- _dev = null
98
+ async function mount({
99
+ state,
100
+ ...options
105
101
  } = {}) {
106
- var _this$configs, _this$configs3;
107
-
108
- this.form = form;
109
- this.summary = summary;
110
- this.mainStyle = null;
111
- this._dev = _dev;
112
- const framePayUrls = {
113
- script: _dev ? _dev.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js' : 'https://framepay.rebilly.com/rebilly.js',
114
- style: _dev ? _dev.framePayStyleLink || 'https://framepay.rebilly.com/rebilly.css' : 'https://framepay.rebilly.com/rebilly.css'
115
- };
116
- const _computed = {
117
- paymentMethodsUrl: _dev ? _dev.paymentMethodsUrl || 'https://forms.local.rebilly.dev:3000' : 'https://forms.secure-payments.app'
118
- };
119
- const OPTIONS_DEFAULTS = {
120
- intent: {
121
- countryCode: 'US'
122
- },
123
- locale: 'auto',
124
- paymentInstruments: {
125
- address: {
126
- name: 'default',
127
- region: 'default',
128
- hide: [],
129
- show: [],
130
- require: []
131
- },
132
- compactExpressInstruments: true,
133
- googlePay: {
134
- displayOptions: {
135
- buttonColor: 'black',
136
- buttonType: 'short',
137
- buttonHeight: '44px'
138
- }
139
- },
140
- paymentCard: {
141
- popup: false
142
- }
143
- },
144
- features: {
145
- autoConfirmation: true,
146
- autoResult: true
147
- }
148
- };
149
- const combinedOptions = { ...options,
150
- _computed
151
- };
152
-
153
- if (_dev) {
154
- combinedOptions._dev = _dev;
155
- }
156
-
157
- this.options = (0, _lodash.default)(OPTIONS_DEFAULTS, combinedOptions);
158
- this.form = (0, _utils.processPropertyAsDOMElement)({
159
- prop: this.form,
160
- propName: 'form'
161
- });
162
- this.summary = (0, _utils.processPropertyAsDOMElement)({
163
- prop: this.summary,
164
- propName: 'summary',
165
- isRequired: false
166
- }); // Setup loader
167
-
168
- this.loader.addDOMElement({
169
- el: this.form
170
- });
171
- this.loader.addDOMElement({
172
- section: 'summary',
173
- el: this.summary
174
- }); // Adds base stylesheet
102
+ try {
103
+ var _state$data$transacti;
175
104
 
176
- this.mainStyle = await (0, _style.mainStyle)(((_this$configs = this.configs) === null || _this$configs === void 0 ? void 0 : _this$configs.theme) || {});
177
- (0, _utils.addDOMElement)({
178
- element: 'style',
179
- attributes: {
180
- type: 'text/css'
181
- },
182
- content: this.mainStyle,
183
- target: 'head'
184
- }); // Adds configs CSS to override any styles
105
+ state.data = {};
106
+ state.options = {}; // Setup DOM
185
107
 
186
- if (this.configs.css) {
187
- (0, _utils.addDOMElement)({
188
- element: 'style',
189
- attributes: {
190
- type: 'text/css'
191
- },
192
- content: this.configs.css,
193
- target: 'head'
108
+ state.form = (0, _setupElement.default)({
109
+ element: 'form',
110
+ options
194
111
  });
195
- } // Adds FramePay
196
-
112
+ state.summary = (0, _setupElement.default)({
113
+ element: 'summary',
114
+ options
115
+ }); // Setup loader
197
116
 
198
- if (!document.querySelectorAll('[framepay*="script"]').length) {
199
- (0, _utils.addDOMElement)({
200
- element: 'script',
201
- attributes: {
202
- 'framepay': 'script',
203
- src: framePayUrls.script
204
- },
205
- target: 'head'
117
+ state.loader.addDOMElement({
118
+ el: state.form
206
119
  });
207
- }
208
-
209
- if (!document.querySelectorAll('[framepay*="stylesheet"]').length) {
210
- (0, _utils.addDOMElement)({
211
- element: 'link',
212
- attributes: {
213
- 'framepay': 'stylesheet',
214
- href: framePayUrls.style,
215
- rel: 'stylesheet'
216
- },
217
- target: 'head'
120
+ state.loader.addDOMElement({
121
+ section: 'summary',
122
+ el: state.summary
218
123
  });
219
- }
220
-
221
- try {
222
- var _riskMetadata$browser, _this$configs2;
223
-
224
- this.loader.startLoading({
124
+ state.loader.startLoading({
225
125
  section: 'summary',
226
126
  id: 'initSummary'
227
127
  });
228
- this.loader.startLoading({
128
+ state.loader.startLoading({
229
129
  id: 'initForm'
230
- });
231
- const {
232
- riskMetadata
233
- } = await (0, _riskDataCollector.collectData)();
234
-
235
- if (this.options.locale === 'auto' && riskMetadata !== null && riskMetadata !== void 0 && (_riskMetadata$browser = riskMetadata.browserData) !== null && _riskMetadata$browser !== void 0 && _riskMetadata$browser.language) {
236
- const {
237
- browserData: {
238
- language
239
- }
240
- } = riskMetadata;
241
- this.options.locale = language;
242
- }
130
+ }); // Setup state
243
131
 
244
- const i18n = ((_this$configs2 = this.configs) === null || _this$configs2 === void 0 ? void 0 : _this$configs2.i18n) || {};
245
- this.translate.init(this.options.locale, i18n);
246
- const {
247
- readyToPay,
248
- summary: summaryData,
249
- plans,
250
- products
251
- } = await _fetchSummaryData.FetchSummaryData.call(this, {
252
- riskMetadata
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
253
153
  });
254
- this.hasMounted = true;
255
154
 
256
- if (this.form) {
257
- this.formOptions = {
258
- summary: summaryData,
259
- mainStyle: this.mainStyle,
260
- readyToPay,
261
- plans,
262
- products
263
- };
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
264
158
 
265
- this._mountMethodSelector(this.formOptions);
266
- }
267
159
 
268
- if (this.summary) {
269
- this.summaryOptions = {
270
- summary: summaryData,
271
- readyToPay,
272
- plans,
273
- products
274
- };
160
+ if (state.form) {
161
+ (0, _methodSelector.mountMethodSelector)({
162
+ state
163
+ });
164
+ }
275
165
 
276
- this._mountSummary(this.summaryOptions);
166
+ if (state.summary) {
167
+ (0, _summary.mountSummary)({
168
+ state
169
+ });
277
170
  }
171
+
172
+ i18n({
173
+ state
174
+ });
175
+ state.hasMounted = true;
278
176
  } catch (error) {
279
177
  throw error;
280
178
  }
281
179
 
282
- const i18n = ((_this$configs3 = this.configs) === null || _this$configs3 === void 0 ? void 0 : _this$configs3.i18n) || {};
283
- this.translate.init(this.options.locale, i18n);
284
- this.translate.translateItems();
285
-
286
- if (this.options.features.autoConfirmation) {
287
- this.on('instrument-ready', instrument => {
288
- this.show('confirmation', {
289
- instrument,
290
- mainStyle: this.mainStyle
291
- });
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
+ }
292
190
  });
293
191
  }
294
192
 
295
- if (this.options.features.autoResult) {
296
- this.on('purchase-completed', purchase => {
297
- this.show('result', {
298
- purchase,
299
- mainStyle: this.mainStyle
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
+ }
300
204
  });
301
- });
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
+ }
302
217
  }
303
- }
304
-
305
- ;
218
+ }