@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
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _rebillyInstrumentsMock = require("tests/mocks/rebilly-instruments-mock");
3
+ var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
4
+
5
+ var _asyncUtilities = require("../../tests/async-utilities");
4
6
 
5
7
  describe('RebillyInstruments Update', () => {
6
8
  it('should throw an error when methods are not mounted', async () => {
7
9
  const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
8
- rebillyInstruments.hasMounted = false;
10
+ rebillyInstruments.state.hasMounted = false;
9
11
  let error;
10
12
 
11
13
  try {
@@ -15,11 +17,11 @@ describe('RebillyInstruments Update', () => {
15
17
  }
16
18
 
17
19
  expect(error).toEqual(new Error('Update method cannot be called before mounting instruments'));
18
- }); // TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
20
+ }); // TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
19
21
 
20
22
  it.skip('should call changeLocale when updating locale options', async () => {
21
23
  const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
22
- const call = jest.fn(); //Simulate mounted iframe
24
+ const call = jest.fn(); // Simulate mounted iframe
23
25
 
24
26
  const fakeIFrameComponent = {
25
27
  destroy: jest.fn(),
@@ -27,16 +29,14 @@ describe('RebillyInstruments Update', () => {
27
29
  call
28
30
  }
29
31
  };
30
- rebillyInstruments.iframeComponents = [fakeIFrameComponent];
32
+ rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
31
33
  await rebillyInstruments.update({
32
- options: {
33
- locale: 'ja'
34
- }
34
+ locale: 'ja'
35
35
  });
36
- expect(call).toBeCalledWith('changeLocale', 'ja'); // It would be better to match real UI instead of implementation state
36
+ expect(call).toBeCalledWith('changeLocale', 'ja'); // It would be better to match real UI instead of implementation state
37
37
 
38
- expect(rebillyInstruments.options.locale).toBe('ja');
39
- expect(rebillyInstruments.translate.locale).toBe('ja');
38
+ expect(rebillyInstruments.state.options.locale).toBe('ja');
39
+ expect(rebillyInstruments.state.translate.locale).toBe('ja');
40
40
  });
41
41
  it('should destroy and update when updating options different than locale', async () => {
42
42
  const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
@@ -44,24 +44,43 @@ describe('RebillyInstruments Update', () => {
44
44
  const summaryElement = document.querySelector('.summary-selector');
45
45
  expect(formElement.innerHTML).not.toEqual('');
46
46
  expect(summaryElement.innerHTML).not.toEqual('');
47
- const call = jest.fn(); //Simulate mounted iframe
47
+ const call = jest.fn(); // Simulate mounted iframe
48
48
 
49
49
  const fakeIFrameComponent = {
50
+ destroy: jest.fn(),
50
51
  component: {
51
- destroy: jest.fn(),
52
52
  call
53
53
  }
54
54
  };
55
- rebillyInstruments.iframeComponents = [fakeIFrameComponent];
55
+ rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
56
56
  await rebillyInstruments.update({
57
- options: {
58
- intent: {
59
- countryCode: 'ES'
60
- }
57
+ countryCode: 'ES'
58
+ });
59
+ expect(rebillyInstruments.state.options.countryCode).toEqual('ES');
60
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
61
+ });
62
+ it('should replace the items with different options', async () => {
63
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
64
+ const formElement = document.querySelector('.form-selector');
65
+ const summaryElement = document.querySelector('.summary-selector');
66
+ expect(formElement.innerHTML).not.toEqual('');
67
+ expect(summaryElement.innerHTML).not.toEqual('');
68
+ const call = jest.fn(); // Simulate mounted iframe
69
+
70
+ const fakeIFrameComponent = {
71
+ destroy: jest.fn(),
72
+ component: {
73
+ call
61
74
  }
75
+ };
76
+ rebillyInstruments.iframeComponents = [fakeIFrameComponent];
77
+ await rebillyInstruments.update({
78
+ items: [{
79
+ planId: 'test-plan-id-1',
80
+ quantity: 5
81
+ }]
62
82
  });
63
- expect(rebillyInstruments.options.intent.countryCode).toEqual('ES');
64
- expect(formElement.innerHTML).toEqual('');
65
- expect(summaryElement.innerHTML).toEqual('');
83
+ expect(rebillyInstruments.state.options.items[0].quantity).toEqual(5);
84
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
66
85
  });
67
86
  });
package/dist/i18n/en.json CHANGED
@@ -10,7 +10,10 @@
10
10
  "form": {
11
11
  "expressCheckout": "Express checkout",
12
12
  "or": "Or",
13
- "popupOverlayText": "Click here to show popup window"
13
+ "popupOverlayText": "Click here to show popup window",
14
+ "error": {
15
+ "noPaymentMethods": "No payment methods available for this transaction, please contact support."
16
+ }
14
17
  },
15
18
  "paymentMethods": {
16
19
  "payment-card": "Payment card"
package/dist/i18n/es.json CHANGED
@@ -10,7 +10,10 @@
10
10
  "form": {
11
11
  "expressCheckout": "Chequeo rápido",
12
12
  "or": "O pague con",
13
- "popupOverlayText": "Haga clic aquí para mostrar la ventana emergente"
13
+ "popupOverlayText": "Haga clic aquí para mostrar la ventana emergente",
14
+ "error": {
15
+ "noPaymentMethods": "No hay métodos de pago disponibles para esta transacción, por favor, póngase en contacto con el servicio de asistencia."
16
+ }
14
17
  },
15
18
  "paymentMethods": {
16
19
  "payment-card": "Tarjeta de crédito"
package/dist/index.js CHANGED
@@ -3,15 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.RebillyInstrumentsInstance = void 0;
7
-
8
- var _initialize = require("./functions/initialize");
6
+ exports.default = exports.RebillyInstrumentsInstance = exports.InstrumentsState = void 0;
9
7
 
10
8
  var _mount = require("./functions/mount");
11
9
 
12
10
  var _purchase = require("./functions/purchase");
13
11
 
14
- var _show = require("./functions/show");
12
+ var _setup = require("./functions/setup");
15
13
 
16
14
  var _on = require("./functions/on");
17
15
 
@@ -19,34 +17,16 @@ var _update = require("./functions/update");
19
17
 
20
18
  var _destroy = require("./functions/destroy");
21
19
 
22
- var _readyToPay = require("./storefront/ready-to-pay");
23
-
24
- var _summary = require("./storefront/summary");
25
-
26
- var _plans = require("./storefront/plans");
27
-
28
- var _products = require("./storefront/products");
29
-
30
- var _purchase2 = require("./storefront/purchase");
31
-
32
- var _summary2 = require("./views/summary");
33
-
34
- var _methodSelector = require("./views/method-selector");
35
-
36
- var _confirmation = require("./views/confirmation");
37
-
38
- var _result = require("./views/result");
39
-
40
- var _modal = require("./views/modal");
41
-
42
20
  var _loader = require("./loader");
43
21
 
44
22
  var _i18n = require("./i18n");
45
23
 
46
- class RebillyInstrumentsInstance {
24
+ var _show = require("./functions/show");
25
+
26
+ class InstrumentsState {
47
27
  constructor() {
48
- this.configs = null;
49
28
  this.options = null;
29
+ this.data = {};
50
30
  this.mountingPoints = null;
51
31
  this.storefront = null;
52
32
  this.form = null;
@@ -55,36 +35,67 @@ class RebillyInstrumentsInstance {
55
35
  this.translate = new _i18n.Translate();
56
36
  this.iframeComponents = [];
57
37
  this.hasMounted = false;
58
- const functionsMap = {
59
- // "Private" functions
60
- _fetchReadyToPay: _readyToPay.FetchReadyToPay,
61
- _fetchSummary: _summary.FetchSummary,
62
- _fetchPlans: _plans.FetchPlans,
63
- _fetchProducts: _products.FetchProducts,
64
- _postPurchase: _purchase2.PostPurchase,
65
- _mountSummary: _summary2.MountSummary,
66
- _mountMethodSelector: _methodSelector.MountMethodSelector,
67
- _mountConfirmation: _confirmation.MountConfirmation,
68
- _mountResult: _result.MountResult,
69
- _mountModal: _modal.MountModal,
70
- _updateSummary: _summary2.UpdateSummary,
71
- _updateSelector: _methodSelector.UpdateMethodSelector,
72
- // Public Functions
73
- initialize: _initialize.Initialize,
74
- mount: _mount.Mount,
75
- destroy: _destroy.Destroy,
76
- update: _update.Update,
77
- purchase: _purchase.Purchase,
78
- show: _show.Show,
79
- on: _on.On
80
- }; // eslint-disable-next-line no-restricted-syntax
81
-
82
- for (const local of Object.keys(functionsMap)) {
83
- // eslint-disable-next-line func-names
84
- this[local] = function (...args) {
85
- return functionsMap[local].apply(this, args);
86
- };
87
- }
38
+ }
39
+
40
+ }
41
+
42
+ exports.InstrumentsState = InstrumentsState;
43
+
44
+ class RebillyInstrumentsInstance {
45
+ constructor() {
46
+ this.state = new InstrumentsState(); // TODO: mountConfirmation, mountResult have different contract shape when they look similar
47
+ // TODO: review test coverage of UpdateSummary and UpdateMethodSelector as no tests were broken
48
+ // when commenting them
49
+ }
50
+
51
+ async mount(options) {
52
+ await (0, _mount.mount)({
53
+ state: this.state,
54
+ ...options
55
+ });
56
+ }
57
+
58
+ async destroy() {
59
+ await (0, _destroy.destroy)({
60
+ state: this.state
61
+ });
62
+ }
63
+
64
+ async update(newOptions) {
65
+ await (0, _update.update)({
66
+ state: this.state,
67
+ newOptions
68
+ });
69
+ }
70
+
71
+ async purchase(payload) {
72
+ await (0, _purchase.purchase)({
73
+ state: this.state,
74
+ payload
75
+ });
76
+ }
77
+
78
+ async setup(payload) {
79
+ await (0, _setup.setup)({
80
+ state: this.state,
81
+ payload
82
+ });
83
+ }
84
+
85
+ async show(componentName, payload) {
86
+ await (0, _show.show)({
87
+ state: this.state,
88
+ componentName,
89
+ payload
90
+ });
91
+ }
92
+
93
+ on(eventName, callback) {
94
+ (0, _on.on)({
95
+ state: this.state,
96
+ eventName,
97
+ callback
98
+ });
88
99
  }
89
100
 
90
101
  }
@@ -2,35 +2,21 @@
2
2
 
3
3
  var _index = _interopRequireWildcard(require("./index"));
4
4
 
5
+ var _asyncUtilities = require("../tests/async-utilities");
6
+
5
7
  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); }
6
8
 
7
9
  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; }
8
10
 
9
11
  describe('RebillyInstruments instance', () => {
10
12
  let rebillyInstruments;
11
-
12
- function setupInstance(config = {
13
- test: 'value'
14
- }) {
15
- rebillyInstruments.initialize(config);
16
- }
17
-
18
13
  beforeEach(() => {
19
14
  rebillyInstruments = _index.default;
20
15
  });
21
16
  it('should have default export as instance of class', () => {
22
17
  expect(_index.default).toBeInstanceOf(_index.RebillyInstrumentsInstance);
23
18
  });
24
- it('should be initializable', () => {
25
- jest.spyOn(rebillyInstruments, 'initialize');
26
- const config = {
27
- test: 'value'
28
- };
29
- rebillyInstruments.initialize(config);
30
- expect(rebillyInstruments.initialize).toHaveBeenCalledTimes(1);
31
- expect(rebillyInstruments.initialize).toHaveBeenCalledWith(config);
32
- });
33
- it('should be mountable', () => {
19
+ it('should be mountable', async () => {
34
20
  jest.spyOn(rebillyInstruments, 'mount');
35
21
  document.body.innerHTML = `
36
22
  <div class="form-selector"></div>
@@ -38,18 +24,12 @@ describe('RebillyInstruments instance', () => {
38
24
  `;
39
25
  const options = {
40
26
  form: '.form-selector',
41
- test: 'value'
27
+ summary: '.summary-selector',
28
+ items: []
42
29
  };
43
- setupInstance();
44
- rebillyInstruments.mount(options);
30
+ await rebillyInstruments.mount(options);
45
31
  expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
46
32
  expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
47
- });
48
- it('should be able to trigger a purchase', () => {
49
- jest.spyOn(rebillyInstruments, 'purchase');
50
- const instrument = {};
51
- setupInstance();
52
- rebillyInstruments.purchase(instrument);
53
- expect(rebillyInstruments.purchase).toHaveBeenCalledTimes(1);
33
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
54
34
  });
55
35
  });
@@ -27,11 +27,8 @@ class Loader {
27
27
  section = 'form',
28
28
  el = null
29
29
  } = {}) {
30
- const minHeight = '200px';
31
-
32
30
  if ((0, _isDomElement.default)(el)) {
33
31
  el.style.position = 'relative';
34
- el.style.minHeight = minHeight;
35
32
  this.DOM[section] = el;
36
33
  }
37
34
  }
@@ -42,6 +39,7 @@ class Loader {
42
39
  } = {}) {
43
40
  var _this$DOM;
44
41
 
42
+ const minHeight = '200px';
45
43
  this[section].push(id);
46
44
 
47
45
  if ((_this$DOM = this.DOM) !== null && _this$DOM !== void 0 && _this$DOM[section]) {
@@ -50,6 +48,8 @@ class Loader {
50
48
  } else {
51
49
  this.DOM[section].querySelector('.rebilly-instruments-loader').classList.add('is-active');
52
50
  }
51
+
52
+ this.DOM[section].style.minHeight = minHeight;
53
53
  }
54
54
  }
55
55
 
@@ -65,6 +65,7 @@ class Loader {
65
65
 
66
66
  if (!this[section].length && this.DOM[section].querySelector('.rebilly-instruments-loader')) {
67
67
  this.DOM[section].querySelector('.rebilly-instruments-loader').classList.remove('is-active');
68
+ this.DOM[section].style.minHeight = '';
68
69
  }
69
70
  }
70
71
 
@@ -3,10 +3,43 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.validateStateForStorefront = validateStateForStorefront;
7
+ exports.Endpoint = Endpoint;
6
8
  exports.default = exports.StorefrontInstance = void 0;
7
9
 
8
10
  var _rebillyJsSdk = require("rebilly-js-sdk");
9
11
 
12
+ function validateStateForStorefront({
13
+ state
14
+ }) {
15
+ if (!state.storefront) {
16
+ throw new Error('Could not access rebilly-js-sdk instance');
17
+ }
18
+
19
+ if (!state.options) {
20
+ throw new Error('Could not use Rebilly Instruments mount options to fetch Rebilly data');
21
+ }
22
+ }
23
+
24
+ async function Endpoint({
25
+ state
26
+ } = {}, callback) {
27
+ try {
28
+ validateStateForStorefront({
29
+ state
30
+ });
31
+ return await callback();
32
+ } catch (error) {
33
+ // TODO: standard error handling for all endpoints
34
+ // console.error(error);
35
+ if (error.status === 422) {
36
+ error.details.forEach(e => console.error(e));
37
+ }
38
+
39
+ throw error;
40
+ }
41
+ }
42
+
10
43
  class StorefrontInstance {
11
44
  constructor({
12
45
  publishableKey = null,
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fetchInvoice = fetchInvoice;
7
+
8
+ var _invoiceModel = _interopRequireDefault(require("./models/invoice-model"));
9
+
10
+ var _index = require("./index");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ async function fetchInvoice({
15
+ data = null,
16
+ state = null
17
+ }) {
18
+ return (0, _index.Endpoint)({
19
+ state
20
+ }, async () => {
21
+ state.storefront.setSessionToken(state.options.customerJwt);
22
+ const {
23
+ fields
24
+ } = await state.storefront.invoices.get(data);
25
+ return new _invoiceModel.default(fields);
26
+ });
27
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ class BaseModel {
9
+ constructor({ ...fields
10
+ } = {}) {
11
+ Object.entries(fields).forEach(([key, value]) => {
12
+ this[key] = value;
13
+ });
14
+ }
15
+
16
+ }
17
+
18
+ exports.default = BaseModel;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _baseModel = _interopRequireDefault(require("./base-model"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ class InvoiceModel extends _baseModel.default {}
13
+
14
+ exports.default = InvoiceModel;
@@ -5,41 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- class PlanModel {
9
- constructor({
10
- id = '',
11
- name = '',
12
- productId = '',
13
- productOptions = {},
14
- currency = '',
15
- currencySign = '',
16
- pricing = {},
17
- recurringInterval = {},
18
- trial = null,
19
- isTrialOnly = false,
20
- setup = null,
21
- customFields = {},
22
- createdTime = '',
23
- updatedTime = '',
24
- invoiceTimeShift = {}
25
- } = {}) {
26
- this.id = id;
27
- this.name = name;
28
- this.productId = productId;
29
- this.productOptions = productOptions;
30
- this.currency = currency;
31
- this.currencySign = currencySign;
32
- this.pricing = pricing;
33
- this.recurringInterval = recurringInterval;
34
- this.trial = trial;
35
- this.isTrialOnly = isTrialOnly;
36
- this.setup = setup;
37
- this.customFields = customFields;
38
- this.createdTime = createdTime;
39
- this.updatedTime = updatedTime;
40
- this.invoiceTimeShift = invoiceTimeShift;
41
- }
8
+ var _baseModel = _interopRequireDefault(require("./base-model"));
42
9
 
43
- }
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ class PlanModel extends _baseModel.default {}
44
13
 
45
14
  exports.default = PlanModel;
@@ -5,29 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- class ProductModel {
9
- constructor({
10
- id = '',
11
- name = '',
12
- unitLabel = '',
13
- description = {},
14
- requiresShipping = false,
15
- options = [],
16
- customFields = {},
17
- createdTime = '',
18
- updatedTime = ''
19
- } = {}) {
20
- this.id = id;
21
- this.name = name;
22
- this.unitLabel = unitLabel;
23
- this.description = description;
24
- this.requiresShipping = requiresShipping;
25
- this.options = options;
26
- this.customFields = customFields;
27
- this.createdTime = createdTime;
28
- this.updatedTime = updatedTime;
29
- }
8
+ var _baseModel = _interopRequireDefault(require("./base-model"));
30
9
 
31
- }
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ class ProductModel extends _baseModel.default {}
32
13
 
33
14
  exports.default = ProductModel;
@@ -5,51 +5,38 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = exports.SummaryDiscountModel = exports.SummaryTaxModel = exports.SummaryLineItemModel = void 0;
7
7
 
8
- class SummaryLineItemModel {
8
+ var _baseModel = _interopRequireDefault(require("./base-model"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ class SummaryLineItemModel extends _baseModel.default {
9
13
  constructor({
10
- type = '',
11
- description = '',
12
14
  unitPrice = 0.0,
13
15
  quantity = 0,
14
16
  price = 0.0,
15
- planId = '',
16
- productId = ''
17
+ ...fields
17
18
  } = {}) {
18
- this.type = type;
19
- this.description = description;
19
+ super(fields);
20
20
  this.unitPrice = unitPrice;
21
21
  this.quantity = quantity;
22
22
  this.price = price;
23
- this.planId = planId;
24
- this.productId = productId;
25
23
  }
26
24
 
27
25
  }
28
26
 
29
27
  exports.SummaryLineItemModel = SummaryLineItemModel;
30
28
 
31
- class SummaryTaxModel {
32
- constructor({
33
- amount = '',
34
- description = ''
35
- } = {}) {
36
- this.amount = amount;
37
- this.description = description;
38
- }
39
-
40
- }
29
+ class SummaryTaxModel extends _baseModel.default {}
41
30
 
42
31
  exports.SummaryTaxModel = SummaryTaxModel;
43
32
 
44
- class SummaryDiscountModel {
33
+ class SummaryDiscountModel extends _baseModel.default {
45
34
  constructor({
46
- couponId = '',
47
35
  amount = 0,
48
- description = ''
49
- } = {}) {
50
- this.couponId = couponId;
36
+ ...fields
37
+ }) {
38
+ super(fields);
51
39
  this.amount = amount;
52
- this.description = description;
53
40
  }
54
41
 
55
42
  }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _baseModel = _interopRequireDefault(require("./base-model"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ class TransactionModel extends _baseModel.default {
13
+ constructor({
14
+ invoiceIds = [],
15
+ ...fields
16
+ }) {
17
+ super(fields);
18
+ this.invoiceIds = invoiceIds || [];
19
+ }
20
+
21
+ get invoiceId() {
22
+ return this.invoiceIds[0] || null;
23
+ }
24
+
25
+ get hasInvoice() {
26
+ return !!this.invoiceId;
27
+ }
28
+
29
+ }
30
+
31
+ exports.default = TransactionModel;