@rebilly/instruments 1.0.2-beta.8 → 2.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 (211) 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 +183 -0
  11. package/dist/functions/mount/fetch-data.spec.js +189 -0
  12. package/dist/functions/mount/index.js +158 -251
  13. package/dist/functions/mount/mount.spec.js +24 -121
  14. package/dist/functions/mount/setup-element.js +40 -0
  15. package/dist/functions/mount/setup-framepay.js +46 -0
  16. package/dist/functions/mount/setup-i18n.js +33 -0
  17. package/dist/functions/mount/setup-options.js +96 -0
  18. package/dist/functions/mount/setup-options.spec.js +66 -0
  19. package/dist/functions/mount/setup-storefront.js +34 -0
  20. package/dist/functions/mount/setup-styles.js +43 -0
  21. package/dist/functions/on.js +13 -4
  22. package/dist/functions/on.spec.js +19 -5
  23. package/dist/functions/purchase.js +139 -22
  24. package/dist/functions/purchase.spec.js +23 -19
  25. package/dist/functions/setup.js +85 -0
  26. package/dist/functions/setup.spec.js +87 -0
  27. package/dist/functions/show.js +31 -14
  28. package/dist/functions/show.spec.js +47 -18
  29. package/dist/functions/update.js +53 -27
  30. package/dist/functions/update.spec.js +40 -21
  31. package/dist/i18n/en.json +4 -1
  32. package/dist/i18n/es.json +4 -1
  33. package/dist/index.js +67 -56
  34. package/dist/index.spec.js +7 -27
  35. package/dist/loader/index.js +4 -3
  36. package/dist/storefront/index.js +33 -0
  37. package/dist/storefront/invoices.js +27 -0
  38. package/dist/storefront/models/base-model.js +18 -0
  39. package/dist/storefront/models/invoice-model.js +14 -0
  40. package/dist/storefront/models/plan-model.js +4 -35
  41. package/dist/storefront/models/product-model.js +4 -23
  42. package/dist/storefront/models/summary-model.js +12 -25
  43. package/dist/storefront/models/transaction-model.js +31 -0
  44. package/dist/storefront/payment-instruments.js +47 -0
  45. package/dist/storefront/payment-instruments.spec.js +55 -0
  46. package/dist/storefront/plans.js +15 -24
  47. package/dist/storefront/plans.spec.js +17 -44
  48. package/dist/storefront/products.js +16 -20
  49. package/dist/storefront/products.spec.js +25 -49
  50. package/dist/storefront/purchase.js +28 -16
  51. package/dist/storefront/purchase.spec.js +4 -22
  52. package/dist/storefront/ready-to-pay.js +26 -22
  53. package/dist/storefront/ready-to-pay.spec.js +25 -54
  54. package/dist/storefront/storefront.spec.js +1 -1
  55. package/dist/storefront/summary.js +27 -24
  56. package/dist/storefront/summary.spec.js +44 -86
  57. package/dist/storefront/transactions.js +27 -0
  58. package/dist/style/base/theme.js +3 -3
  59. package/dist/style/components/methods.js +43 -42
  60. package/dist/style/utils/color-values.js +1 -3
  61. package/dist/style/views/confirmation.js +0 -4
  62. package/dist/style/views/method-selector.js +1 -1
  63. package/dist/style/views/modal.js +3 -1
  64. package/dist/style/views/summary.js +5 -1
  65. package/dist/utils/format-currency.js +4 -2
  66. package/dist/utils/has-valid-css-selector.js +1 -1
  67. package/dist/utils/process-property-as-dom-element.js +0 -2
  68. package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
  69. package/dist/views/common/iframe/base-iframe.js +10 -2
  70. package/dist/views/common/iframe/modal-iframe.js +44 -3
  71. package/dist/views/confirmation.js +44 -20
  72. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  73. package/dist/views/method-selector/express-methods/google-pay.js +31 -0
  74. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  75. package/dist/views/method-selector/generate-digital-wallet.js +68 -0
  76. package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
  77. package/dist/views/method-selector/get-payment-methods.js +28 -8
  78. package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
  79. package/dist/views/method-selector/index.js +55 -86
  80. package/dist/views/method-selector/method-selector.spec.js +80 -69
  81. package/dist/views/method-selector/mount-express-methods.js +38 -62
  82. package/dist/views/method-selector/mount-methods.js +18 -18
  83. package/dist/views/modal.js +21 -15
  84. package/dist/views/result.js +13 -16
  85. package/dist/views/summary.js +170 -114
  86. package/dist/views/summary.spec.js +72 -76
  87. package/package.json +5 -4
  88. package/src/events/base-event.js +15 -17
  89. package/src/events/events.spec.js +6 -4
  90. package/src/events/index.js +6 -3
  91. package/src/functions/destroy.js +12 -13
  92. package/src/functions/destroy.spec.js +30 -31
  93. package/src/functions/mount/fetch-data.js +148 -0
  94. package/src/functions/mount/fetch-data.spec.js +238 -0
  95. package/src/functions/mount/index.js +129 -244
  96. package/src/functions/mount/mount.spec.js +35 -139
  97. package/src/functions/mount/setup-element.js +26 -0
  98. package/src/functions/mount/setup-framepay.js +41 -0
  99. package/src/functions/mount/setup-i18n.js +19 -0
  100. package/src/functions/mount/setup-options.js +100 -0
  101. package/src/functions/mount/setup-options.spec.js +60 -0
  102. package/src/functions/mount/setup-storefront.js +24 -0
  103. package/src/functions/mount/setup-styles.js +30 -0
  104. package/src/functions/on.js +13 -8
  105. package/src/functions/on.spec.js +30 -17
  106. package/src/functions/purchase.js +101 -19
  107. package/src/functions/purchase.spec.js +18 -18
  108. package/src/functions/setup.js +48 -0
  109. package/src/functions/setup.spec.js +98 -0
  110. package/src/functions/show.js +20 -10
  111. package/src/functions/show.spec.js +43 -22
  112. package/src/functions/update.js +50 -27
  113. package/src/functions/update.spec.js +57 -22
  114. package/src/i18n/en.json +4 -1
  115. package/src/i18n/es.json +4 -1
  116. package/src/i18n/i18n.spec.js +6 -4
  117. package/src/i18n/index.js +14 -11
  118. package/src/index.js +41 -52
  119. package/src/index.spec.js +8 -37
  120. package/src/loader/index.js +51 -47
  121. package/src/loader/loader.spec.js +26 -19
  122. package/src/storefront/index.js +37 -7
  123. package/src/storefront/invoices.js +11 -0
  124. package/src/storefront/models/base-model.js +10 -0
  125. package/src/storefront/models/invoice-model.js +3 -0
  126. package/src/storefront/models/plan-model.js +3 -35
  127. package/src/storefront/models/product-model.js +3 -23
  128. package/src/storefront/models/ready-to-pay-model.js +3 -3
  129. package/src/storefront/models/summary-model.js +15 -29
  130. package/src/storefront/models/transaction-model.js +19 -0
  131. package/src/storefront/payment-instruments.js +30 -0
  132. package/src/storefront/payment-instruments.spec.js +69 -0
  133. package/src/storefront/plans.js +16 -23
  134. package/src/storefront/plans.spec.js +25 -54
  135. package/src/storefront/products.js +18 -22
  136. package/src/storefront/products.spec.js +23 -54
  137. package/src/storefront/purchase.js +14 -14
  138. package/src/storefront/purchase.spec.js +17 -29
  139. package/src/storefront/ready-to-pay.js +26 -23
  140. package/src/storefront/ready-to-pay.spec.js +41 -71
  141. package/src/storefront/storefront.spec.js +1 -1
  142. package/src/storefront/summary.js +26 -22
  143. package/src/storefront/summary.spec.js +60 -109
  144. package/src/storefront/transactions.js +11 -0
  145. package/src/style/base/theme.js +10 -8
  146. package/src/style/base/theme.spec.js +4 -2
  147. package/src/style/browserslist.js +1 -3
  148. package/src/style/components/button.js +3 -1
  149. package/src/style/components/forms/checkbox.js +3 -1
  150. package/src/style/components/index.js +1 -1
  151. package/src/style/components/loader.js +3 -1
  152. package/src/style/components/methods.js +43 -42
  153. package/src/style/helpers/index.js +1 -1
  154. package/src/style/index.js +2 -1
  155. package/src/style/utils/color-values.js +4 -4
  156. package/src/style/vendor/framepay.js +1 -1
  157. package/src/style/vendor/postmate.js +1 -1
  158. package/src/style/views/confirmation.js +0 -4
  159. package/src/style/views/index.js +1 -1
  160. package/src/style/views/method-selector.js +1 -1
  161. package/src/style/views/modal.js +4 -2
  162. package/src/style/views/summary.js +5 -1
  163. package/src/utils/add-dom-element.js +12 -13
  164. package/src/utils/format-currency.js +6 -2
  165. package/src/utils/has-valid-css-selector.js +2 -2
  166. package/src/utils/is-dom-element.js +1 -1
  167. package/src/utils/process-property-as-dom-element.js +27 -24
  168. package/src/utils/sleep.js +1 -1
  169. package/src/views/__snapshots__/summary.spec.js.snap +103 -113
  170. package/src/views/common/iframe/base-iframe.js +12 -4
  171. package/src/views/common/iframe/event-listeners.js +6 -6
  172. package/src/views/common/iframe/index.js +1 -1
  173. package/src/views/common/iframe/method-iframe.js +3 -6
  174. package/src/views/common/iframe/modal-iframe.js +42 -6
  175. package/src/views/common/iframe/view-iframe.js +3 -5
  176. package/src/views/common/render-utilities.js +3 -3
  177. package/src/views/confirmation.js +34 -25
  178. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  179. package/src/views/method-selector/express-methods/google-pay.js +24 -0
  180. package/src/views/method-selector/express-methods/paypal.js +7 -0
  181. package/src/views/method-selector/generate-digital-wallet.js +51 -0
  182. package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
  183. package/src/views/method-selector/get-method-data.js +7 -4
  184. package/src/views/method-selector/get-payment-methods.js +38 -29
  185. package/src/views/method-selector/get-payment-methods.spec.js +26 -33
  186. package/src/views/method-selector/index.js +70 -99
  187. package/src/views/method-selector/method-selector.spec.js +88 -78
  188. package/src/views/method-selector/mount-express-methods.js +36 -60
  189. package/src/views/method-selector/mount-methods.js +32 -21
  190. package/src/views/modal.js +37 -23
  191. package/src/views/result.js +12 -15
  192. package/src/views/summary.js +169 -101
  193. package/src/views/summary.spec.js +99 -74
  194. package/tests/async-utilities.js +22 -0
  195. package/tests/mocks/rebilly-instruments-mock.js +89 -77
  196. package/tests/mocks/storefront-api-mock.js +8 -0
  197. package/tests/mocks/storefront-mock.js +17 -0
  198. package/dist/events/purchase-completed.js +0 -24
  199. package/dist/functions/initialize.js +0 -82
  200. package/dist/functions/initialize.spec.js +0 -34
  201. package/dist/functions/mount/fetch-summary-data.js +0 -31
  202. package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
  203. package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
  204. package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
  205. package/src/events/purchase-completed.js +0 -11
  206. package/src/functions/initialize.js +0 -74
  207. package/src/functions/initialize.spec.js +0 -38
  208. package/src/functions/mount/fetch-summary-data.js +0 -26
  209. package/src/functions/mount/fetch-summary-data.spec.js +0 -46
  210. package/src/views/method-selector/process-digital-wallet-options.js +0 -16
  211. 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,29 @@
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"));
17
29
 
18
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
31
 
@@ -24,282 +36,177 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
36
  * @property {string} planId - The Rebilly id of the plan.
25
37
  * @property {number} quantity - The number of the plans to be purchased.
26
38
  * @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
- /**
39
+ *
40
+ * @typedef {object} GooglePayDisplayOptions
41
+ * @property {"back" | "white"} [buttonColor=black] - Color of google pay button
42
+ * @property {"short" | "long"} [buttonType=short] - The length of the button
43
+ * @property {string} [buttonHeight=44px] - The value and units of the button to match other payment buttons
44
+ *
45
+ * @typedef {object} ApplePayDisplayOptions
46
+ * @property {"back" | "white"} [buttonColor=black] - Color of apple pay button
47
+ * @property {"short" | "long"} [buttonType=short] - The length of the button
48
+ * @property {string} [buttonHeight=44px] - The value and units of the button to match other payment buttons
49
+ *
50
+ * @typedef {object} ApplePayMerchantOptions
51
+ * @property {string} merchantName - The name of the merchant store.
52
+ *
53
+ * @typedef {object} GooglePay
54
+ * @property {GooglePayDisplayOptions} displayOptions - display options for google pay instrument
55
+ *
56
+ * @typedef {object} ApplePay
57
+ * @property {ApplePayDisplayOptions} displayOptions - display options for apple pay instrument
58
+ * @property {ApplePayMerchantOptions} merchantOptions - merchant options for apple pay instrument
59
+ *
60
+ * @typedef {object} PaymentCard
61
+ * @property {boolean} [popup=true] - Show method as a button with a form popup. Otherwise the form will be mounted inline.
62
+ *
57
63
  * @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
- /**
64
+ * @property {string} [name=default] - One of default, combined, or stacked.
65
+ * @property {string} [region=default] - One of default, split, or stacked.
66
+ * @property {Array.<"organization" | "phoneNumber">} show - Show extra fields listed.
67
+ * @property {Array.<"address" | "address2" | "email | "country" | "region" | "postalCode"">} hide - Hide the listed fields.
68
+ * @property {Array.<"organization" | "address" | "address2" | "email" | "phoneNumber" | "country" | "region" | "postalCode">} require - Require the listed fields.
69
+ *
68
70
  * @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
71
+ * @property {boolean} [compactExpressInstruments=true] - Show express methods as inline pill buttons, or list of full width button.
72
+ * @property {PaymentCard} paymentCard - settings for payment card instruments
73
+ * @property {GooglePay} googlePay - settings for google pay instruments
74
+ * @property {ApplePay} applePay - settings for apple pay instruments
75
+ * @property {Address} address - customization for address components for all payment instruments.
76
+ *
77
+ * @typedef {object} Features
78
+ * @property {boolean} [autoConfirmation=true] - Will mount the confirmation screen after `instrument-ready` event is triggered.
79
+ * @property {boolean} [autoResult=true] - Show results of transaction after `purchase-completed` event is triggered
92
80
  */
93
81
 
94
82
  /**
95
83
  * 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.
84
+ * @param {object} options - The options object
85
+ * @param {object} options.state - Global state
86
+ * @param {string | HTMLElement} options.form - The CSS class or HTML element were the form will be mounted.
87
+ * @param {string | HTMLElement} options.summary - The CSS class or HTML element were the summary will be mounted.
88
+ * @param {Item[]} options.items - Which plans the customer is purchasing.
89
+ * @param {string} options.invoiceId - The Rebilly id of the invoice used for purchasing.
90
+ * @param {string} options.customerJwt - The customer token to access the invoice.
91
+ * @param {string} [options.countryCode=USD] - The country code for the transaction
92
+ * @param {PaymentInstruments} options.paymentInstruments - settings for various payment instruments
93
+ * @param {Features} options.features - flags to enable and disable different features
94
+ * @param {string} options.locale - default: auto. Language to render component text
99
95
  */
100
- async function Mount({
101
- form = '.rebilly-instruments',
102
- summary = '.rebilly-instruments-summary',
103
- options = {},
104
- _dev = null
96
+ async function mount({
97
+ state,
98
+ ...options
105
99
  } = {}) {
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
100
+ try {
101
+ var _state$data$transacti;
175
102
 
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
103
+ state.data = {};
104
+ state.options = {}; // Setup DOM
185
105
 
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'
106
+ state.form = (0, _setupElement.default)({
107
+ element: 'form',
108
+ options
194
109
  });
195
- } // Adds FramePay
196
-
110
+ state.summary = (0, _setupElement.default)({
111
+ element: 'summary',
112
+ options
113
+ }); // Setup loader
197
114
 
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'
115
+ state.loader.addDOMElement({
116
+ el: state.form
206
117
  });
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'
118
+ state.loader.addDOMElement({
119
+ section: 'summary',
120
+ el: state.summary
218
121
  });
219
- }
220
-
221
- try {
222
- var _riskMetadata$browser, _this$configs2;
223
-
224
- this.loader.startLoading({
122
+ state.loader.startLoading({
225
123
  section: 'summary',
226
124
  id: 'initSummary'
227
125
  });
228
- this.loader.startLoading({
126
+ state.loader.startLoading({
229
127
  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
- }
128
+ }); // Setup state
243
129
 
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
130
+ state.storefront = (0, _setupStorefront.default)({
131
+ options
132
+ });
133
+ state.options = (0, _setupOptions.default)({
134
+ options
135
+ });
136
+ state.mainStyle = await (0, _setupStyles.default)({
137
+ options
138
+ });
139
+ state.data = await (0, _fetchData.fetchData)({
140
+ state
141
+ });
142
+ const i18n = (0, _setupI18n.default)({
143
+ state
144
+ });
145
+ (0, _setupFramepay.default)({
146
+ state
253
147
  });
254
- this.hasMounted = true;
255
148
 
256
- if (this.form) {
257
- this.formOptions = {
258
- summary: summaryData,
259
- mainStyle: this.mainStyle,
260
- readyToPay,
261
- plans,
262
- products
263
- };
149
+ if (state.data.transaction && ((_state$data$transacti = state.data.transaction) === null || _state$data$transacti === void 0 ? void 0 : _state$data$transacti.type) === 'setup') {
150
+ state.options.transactionType = 'setup';
151
+ } // Mount content
264
152
 
265
- this._mountMethodSelector(this.formOptions);
266
- }
267
153
 
268
- if (this.summary) {
269
- this.summaryOptions = {
270
- summary: summaryData,
271
- readyToPay,
272
- plans,
273
- products
274
- };
154
+ if (state.form) {
155
+ (0, _methodSelector.mountMethodSelector)({
156
+ state
157
+ });
158
+ }
275
159
 
276
- this._mountSummary(this.summaryOptions);
160
+ if (state.summary) {
161
+ (0, _summary.mountSummary)({
162
+ state
163
+ });
277
164
  }
165
+
166
+ i18n({
167
+ state
168
+ });
169
+ state.hasMounted = true;
278
170
  } catch (error) {
279
171
  throw error;
280
172
  }
281
173
 
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
- });
174
+ if (state.options.features.autoConfirmation) {
175
+ (0, _on.on)({
176
+ eventName: 'instrument-ready',
177
+ callback: payload => {
178
+ (0, _show.show)({
179
+ componentName: 'confirmation',
180
+ payload,
181
+ state
182
+ });
183
+ }
292
184
  });
293
185
  }
294
186
 
295
- if (this.options.features.autoResult) {
296
- this.on('purchase-completed', purchase => {
297
- this.show('result', {
298
- purchase,
299
- mainStyle: this.mainStyle
187
+ if (state.options.features.autoResult) {
188
+ if (state.options.transactionType === 'setup') {
189
+ (0, _on.on)({
190
+ eventName: 'setup-completed',
191
+ callback: payload => {
192
+ (0, _show.show)({
193
+ componentName: 'result',
194
+ payload,
195
+ state
196
+ });
197
+ }
300
198
  });
301
- });
199
+ } else {
200
+ (0, _on.on)({
201
+ eventName: 'purchase-completed',
202
+ callback: payload => {
203
+ (0, _show.show)({
204
+ componentName: 'result',
205
+ payload,
206
+ state
207
+ });
208
+ }
209
+ });
210
+ }
302
211
  }
303
- }
304
-
305
- ;
212
+ }