@rebilly/instruments 2.0.0-beta → 3.0.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 (197) hide show
  1. package/dist/events/index.js +2 -1
  2. package/dist/functions/mount/fetch-data.js +187 -0
  3. package/dist/functions/mount/fetch-data.spec.js +189 -0
  4. package/dist/functions/mount/index.js +132 -164
  5. package/dist/functions/mount/mount.spec.js +2 -4
  6. package/dist/functions/mount/setup-element.js +40 -0
  7. package/dist/functions/mount/setup-framepay-theme.js +95 -0
  8. package/dist/functions/mount/setup-framepay.js +5 -1
  9. package/dist/functions/mount/setup-i18n.js +33 -0
  10. package/dist/functions/mount/setup-options.js +68 -47
  11. package/dist/functions/mount/setup-options.spec.js +66 -0
  12. package/dist/functions/mount/setup-storefront.js +6 -4
  13. package/dist/functions/mount/setup-styles.js +4 -2
  14. package/dist/functions/purchase.js +129 -24
  15. package/dist/functions/purchase.spec.js +13 -10
  16. package/dist/functions/setup.js +85 -0
  17. package/dist/functions/setup.spec.js +87 -0
  18. package/dist/functions/show.js +8 -4
  19. package/dist/functions/show.spec.js +9 -5
  20. package/dist/functions/update.js +39 -24
  21. package/dist/functions/update.spec.js +0 -4
  22. package/dist/i18n/en.json +5 -2
  23. package/dist/i18n/es.json +4 -1
  24. package/dist/index.js +17 -3
  25. package/dist/index.spec.js +3 -16
  26. package/dist/loader/index.js +4 -3
  27. package/dist/storefront/index.js +33 -0
  28. package/dist/storefront/invoices.js +27 -0
  29. package/dist/storefront/models/base-model.js +18 -0
  30. package/dist/storefront/models/invoice-model.js +14 -0
  31. package/dist/storefront/models/plan-model.js +4 -35
  32. package/dist/storefront/models/product-model.js +4 -23
  33. package/dist/storefront/models/summary-model.js +12 -25
  34. package/dist/storefront/models/transaction-model.js +31 -0
  35. package/dist/storefront/payment-instruments.js +47 -0
  36. package/dist/storefront/payment-instruments.spec.js +55 -0
  37. package/dist/storefront/plans.js +10 -18
  38. package/dist/storefront/plans.spec.js +3 -13
  39. package/dist/storefront/products.js +10 -13
  40. package/dist/storefront/products.spec.js +12 -19
  41. package/dist/storefront/purchase.js +23 -12
  42. package/dist/storefront/purchase.spec.js +1 -20
  43. package/dist/storefront/ready-to-pay.js +18 -15
  44. package/dist/storefront/ready-to-pay.spec.js +2 -12
  45. package/dist/storefront/summary.js +21 -17
  46. package/dist/storefront/summary.spec.js +4 -15
  47. package/dist/storefront/transactions.js +27 -0
  48. package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
  49. package/dist/style/base/default-theme.js +699 -0
  50. package/dist/style/base/index.js +48 -16
  51. package/dist/style/base/theme.js +16 -48
  52. package/dist/style/base/theme.spec.js +4 -15
  53. package/dist/style/components/address.js +3 -3
  54. package/dist/style/components/button.js +32 -22
  55. package/dist/style/components/divider.js +9 -9
  56. package/dist/style/components/forms/checkbox.js +12 -9
  57. package/dist/style/components/forms/field.js +18 -6
  58. package/dist/style/components/forms/form.js +2 -2
  59. package/dist/style/components/forms/input.js +54 -13
  60. package/dist/style/components/forms/label.js +39 -18
  61. package/dist/style/components/forms/select.js +54 -22
  62. package/dist/style/components/forms/validation.js +53 -6
  63. package/dist/style/components/icons.js +4 -4
  64. package/dist/style/components/loader.js +5 -3
  65. package/dist/style/components/methods.js +18 -15
  66. package/dist/style/components/overlay.js +5 -5
  67. package/dist/style/helpers/index.js +46 -46
  68. package/dist/style/index.js +3 -1
  69. package/dist/style/payment-instruments/payment-card.js +4 -4
  70. package/dist/style/utils/border.js +47 -0
  71. package/dist/style/utils/color-values.js +39 -3
  72. package/dist/style/utils/remove-empty-null.js +20 -0
  73. package/dist/style/vendor/framepay.js +11 -8
  74. package/dist/style/vendor/postmate.js +2 -2
  75. package/dist/style/views/confirmation.js +13 -13
  76. package/dist/style/views/method-selector.js +2 -2
  77. package/dist/style/views/modal.js +6 -6
  78. package/dist/style/views/result.js +4 -4
  79. package/dist/style/views/summary.js +26 -22
  80. package/dist/views/__snapshots__/summary.spec.js.snap +77 -119
  81. package/dist/views/common/iframe/base-iframe.js +2 -0
  82. package/dist/views/common/iframe/modal-iframe.js +50 -4
  83. package/dist/views/confirmation.js +19 -8
  84. package/dist/views/method-selector/generate-digital-wallet.js +12 -3
  85. package/dist/views/method-selector/generate-digital-wallet.spec.js +11 -0
  86. package/dist/views/method-selector/get-payment-methods.js +13 -2
  87. package/dist/views/method-selector/get-payment-methods.spec.js +21 -19
  88. package/dist/views/method-selector/index.js +23 -34
  89. package/dist/views/method-selector/method-selector.spec.js +50 -55
  90. package/dist/views/method-selector/mount-methods.js +5 -8
  91. package/dist/views/modal.js +8 -2
  92. package/dist/views/result.js +3 -4
  93. package/dist/views/summary.js +156 -97
  94. package/dist/views/summary.spec.js +53 -58
  95. package/package.json +4 -2
  96. package/src/events/index.js +2 -1
  97. package/src/functions/mount/fetch-data.js +152 -0
  98. package/src/functions/mount/fetch-data.spec.js +238 -0
  99. package/src/functions/mount/index.js +101 -158
  100. package/src/functions/mount/mount.spec.js +3 -5
  101. package/src/functions/mount/setup-element.js +26 -0
  102. package/src/functions/mount/setup-framepay-theme.js +82 -0
  103. package/src/functions/mount/setup-framepay.js +5 -1
  104. package/src/functions/mount/setup-i18n.js +19 -0
  105. package/src/functions/mount/setup-options.js +78 -48
  106. package/src/functions/mount/setup-options.spec.js +60 -0
  107. package/src/functions/mount/setup-storefront.js +6 -4
  108. package/src/functions/mount/setup-styles.js +4 -2
  109. package/src/functions/on.spec.js +1 -1
  110. package/src/functions/purchase.js +99 -23
  111. package/src/functions/purchase.spec.js +10 -10
  112. package/src/functions/setup.js +48 -0
  113. package/src/functions/setup.spec.js +98 -0
  114. package/src/functions/show.js +2 -4
  115. package/src/functions/show.spec.js +3 -4
  116. package/src/functions/update.js +40 -25
  117. package/src/functions/update.spec.js +0 -4
  118. package/src/i18n/en.json +5 -2
  119. package/src/i18n/es.json +4 -1
  120. package/src/index.js +9 -3
  121. package/src/index.spec.js +3 -21
  122. package/src/loader/index.js +3 -3
  123. package/src/storefront/index.js +28 -0
  124. package/src/storefront/invoices.js +11 -0
  125. package/src/storefront/models/base-model.js +10 -0
  126. package/src/storefront/models/invoice-model.js +3 -0
  127. package/src/storefront/models/plan-model.js +3 -35
  128. package/src/storefront/models/product-model.js +3 -23
  129. package/src/storefront/models/summary-model.js +12 -19
  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 +6 -17
  134. package/src/storefront/plans.spec.js +4 -11
  135. package/src/storefront/products.js +8 -16
  136. package/src/storefront/products.spec.js +16 -22
  137. package/src/storefront/purchase.js +14 -16
  138. package/src/storefront/purchase.spec.js +2 -14
  139. package/src/storefront/ready-to-pay.js +13 -16
  140. package/src/storefront/ready-to-pay.spec.js +3 -10
  141. package/src/storefront/summary.js +19 -17
  142. package/src/storefront/summary.spec.js +5 -12
  143. package/src/storefront/transactions.js +11 -0
  144. package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
  145. package/src/style/base/default-theme.js +674 -0
  146. package/src/style/base/index.js +48 -16
  147. package/src/style/base/theme.js +17 -47
  148. package/src/style/base/theme.spec.js +4 -16
  149. package/src/style/components/address.js +3 -3
  150. package/src/style/components/button.js +32 -24
  151. package/src/style/components/divider.js +9 -9
  152. package/src/style/components/forms/checkbox.js +11 -11
  153. package/src/style/components/forms/field.js +18 -6
  154. package/src/style/components/forms/form.js +2 -2
  155. package/src/style/components/forms/input.js +54 -13
  156. package/src/style/components/forms/label.js +39 -18
  157. package/src/style/components/forms/select.js +54 -22
  158. package/src/style/components/forms/validation.js +53 -6
  159. package/src/style/components/icons.js +4 -4
  160. package/src/style/components/loader.js +4 -5
  161. package/src/style/components/methods.js +18 -15
  162. package/src/style/components/overlay.js +5 -5
  163. package/src/style/helpers/index.js +46 -46
  164. package/src/style/index.js +2 -1
  165. package/src/style/payment-instruments/payment-card.js +4 -4
  166. package/src/style/utils/border.js +34 -0
  167. package/src/style/utils/color-values.js +27 -1
  168. package/src/style/utils/remove-empty-null.js +10 -0
  169. package/src/style/vendor/framepay.js +11 -8
  170. package/src/style/vendor/postmate.js +2 -2
  171. package/src/style/views/confirmation.js +13 -13
  172. package/src/style/views/method-selector.js +2 -2
  173. package/src/style/views/modal.js +6 -6
  174. package/src/style/views/result.js +4 -4
  175. package/src/style/views/summary.js +26 -22
  176. package/src/views/__snapshots__/summary.spec.js.snap +77 -119
  177. package/src/views/common/iframe/base-iframe.js +2 -0
  178. package/src/views/common/iframe/modal-iframe.js +45 -3
  179. package/src/views/confirmation.js +15 -5
  180. package/src/views/method-selector/generate-digital-wallet.js +10 -3
  181. package/src/views/method-selector/generate-digital-wallet.spec.js +10 -0
  182. package/src/views/method-selector/get-payment-methods.js +7 -2
  183. package/src/views/method-selector/get-payment-methods.spec.js +26 -23
  184. package/src/views/method-selector/index.js +21 -28
  185. package/src/views/method-selector/method-selector.spec.js +49 -64
  186. package/src/views/method-selector/mount-methods.js +5 -8
  187. package/src/views/modal.js +6 -2
  188. package/src/views/result.js +4 -3
  189. package/src/views/summary.js +161 -117
  190. package/src/views/summary.spec.js +60 -75
  191. package/tests/mocks/rebilly-instruments-mock.js +37 -7
  192. package/tests/mocks/storefront-api-mock.js +8 -0
  193. package/tests/mocks/storefront-mock.js +17 -0
  194. package/dist/functions/mount/fetch-summary-data.js +0 -46
  195. package/dist/functions/mount/fetch-summary-data.spec.js +0 -43
  196. package/src/functions/mount/fetch-summary-data.js +0 -29
  197. package/src/functions/mount/fetch-summary-data.spec.js +0 -40
@@ -6,8 +6,6 @@ var confirmation = _interopRequireWildcard(require("../views/confirmation"));
6
6
 
7
7
  var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
8
8
 
9
- var _show = require("./show");
10
-
11
9
  var _index = require("../index");
12
10
 
13
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -27,7 +25,10 @@ describe('RebillyInstruments show', () => {
27
25
  };
28
26
  await instance.show('result', payload);
29
27
  expect(mountResult).toBeCalledTimes(1);
30
- expect(mountResult).toBeCalledWith(payload);
28
+ expect(mountResult).toBeCalledWith({
29
+ payload,
30
+ state: instance.state
31
+ });
31
32
  expect(instance.state.iframeComponents).toEqual([]);
32
33
  });
33
34
  it('should show confirmation component', async () => {
@@ -39,11 +40,14 @@ describe('RebillyInstruments show', () => {
39
40
  };
40
41
  await instance.show('confirmation', payload);
41
42
  expect(mountConfirmation).toBeCalledTimes(1);
42
- expect(mountConfirmation).toBeCalledWith(payload);
43
+ expect(mountConfirmation).toBeCalledWith({
44
+ payload,
45
+ state: instance.state
46
+ });
43
47
  expect(instance.state.iframeComponents).toEqual([]);
44
48
  });
45
49
  it('should fail for non supported component', async () => {
46
- const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
50
+ const rebillyInstruments = new _index.RebillyInstrumentsInstance();
47
51
  let error;
48
52
 
49
53
  try {
@@ -7,17 +7,32 @@ exports.update = update;
7
7
 
8
8
  var _lodash = _interopRequireDefault(require("lodash.merge"));
9
9
 
10
- var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
11
-
12
10
  var _destroy = require("./destroy");
13
11
 
14
12
  var _mount = require("./mount");
15
13
 
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
- async function update(state, newConfig = {}) {
19
- var _state$options;
16
+ function sanitizeOldPurchaseData({
17
+ newOptions
18
+ }) {
19
+ let purchaseData = {};
20
+ const hasPurchaseDataKeys = Object.keys(newOptions).some(key => ['items', 'money', 'invoiceId', 'transactionId'].includes(key));
21
+ purchaseData = hasPurchaseDataKeys ? {
22
+ items: null,
23
+ money: null,
24
+ invoiceId: null,
25
+ transactionId: null
26
+ } : purchaseData;
27
+ return purchaseData;
28
+ }
29
+
30
+ ;
20
31
 
32
+ async function update({
33
+ state,
34
+ newOptions = {}
35
+ }) {
21
36
  if (!state.hasMounted) {
22
37
  throw Error('Update method cannot be called before mounting instruments');
23
38
  }
@@ -26,26 +41,27 @@ async function update(state, newConfig = {}) {
26
41
  * https://github.com/Rebilly/framepay/issues/450
27
42
  * That's why this toggle disables real time locale update until that issue is fixed.
28
43
  */
44
+ // const updatingJustLocale =
45
+ // newOptions?.options && isEqual(Object.keys(newOptions), ['locale']);
46
+ // if (updatingJustLocale) {
47
+ // const updatedOptions = merge(state.options, newOptions);
48
+ // const newLocale = newOptions?.locale;
49
+ // state.options = updatedOptions;
50
+ // state.translate.updateTranslationsToNewLocale(newLocale);
51
+ // state.iframeComponents.forEach((iframe) =>
52
+ // iframe.component.call('changeLocale', newLocale)
53
+ // );
54
+ // return;
55
+ // }
29
56
 
30
57
 
31
- const temporaryDisableRealTimeLocaleUpdate = true;
32
- const updatingJustLocale = (newConfig === null || newConfig === void 0 ? void 0 : newConfig.options) && (0, _lodash2.default)(Object.keys(newConfig), ['locale']);
33
-
34
- if (updatingJustLocale && !temporaryDisableRealTimeLocaleUpdate) {
35
- const updatedOptions = (0, _lodash.default)(state.options, newConfig);
36
- const newLocale = newConfig === null || newConfig === void 0 ? void 0 : newConfig.locale;
37
- state.options = updatedOptions;
38
- state.translate.updateTranslationsToNewLocale(newLocale);
39
- state.iframeComponents.forEach(iframe => iframe.component.call('changeLocale', newLocale));
40
- return;
41
- } // Check if the provided intent items object is different to avoid merging the items entries
42
-
43
-
44
- if (newConfig !== null && newConfig !== void 0 && newConfig.items && !(0, _lodash2.default)((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.items, newConfig === null || newConfig === void 0 ? void 0 : newConfig.items)) {
45
- state.options.items = newConfig === null || newConfig === void 0 ? void 0 : newConfig.items;
46
- }
47
-
48
- const updatedOptions = (0, _lodash.default)(state.options, newConfig);
58
+ const oldOptions = { ...state.options,
59
+ ...sanitizeOldPurchaseData({
60
+ newOptions
61
+ })
62
+ };
63
+ const updatedOptions = (0, _lodash.default)({ ...oldOptions
64
+ }, newOptions);
49
65
  await (0, _destroy.destroy)({
50
66
  state
51
67
  });
@@ -53,7 +69,6 @@ async function update(state, newConfig = {}) {
53
69
  state,
54
70
  form: state.form,
55
71
  summary: state.summary,
56
- ...updatedOptions,
57
- _dev: state._dev
72
+ ...updatedOptions
58
73
  });
59
74
  }
@@ -57,8 +57,6 @@ describe('RebillyInstruments Update', () => {
57
57
  countryCode: 'ES'
58
58
  });
59
59
  expect(rebillyInstruments.state.options.countryCode).toEqual('ES');
60
- expect(formElement.innerHTML).toEqual('');
61
- expect(summaryElement.innerHTML).toEqual('');
62
60
  await (0, _asyncUtilities.avoidUnhandledPromises)();
63
61
  });
64
62
  it('should replace the items with different options', async () => {
@@ -83,8 +81,6 @@ describe('RebillyInstruments Update', () => {
83
81
  }]
84
82
  });
85
83
  expect(rebillyInstruments.state.options.items[0].quantity).toEqual(5);
86
- expect(formElement.innerHTML).toEqual('');
87
- expect(summaryElement.innerHTML).toEqual('');
88
84
  await (0, _asyncUtilities.avoidUnhandledPromises)();
89
85
  });
90
86
  });
package/dist/i18n/en.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "en": {
3
3
  "summary": {
4
4
  "subTotal": "Sub Total",
5
- "discounts": "Discouts",
5
+ "discounts": "Discounts",
6
6
  "taxes": "Taxes",
7
7
  "shipping": "Shipping",
8
8
  "total": "Total"
@@ -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
@@ -9,6 +9,8 @@ var _mount = require("./functions/mount");
9
9
 
10
10
  var _purchase = require("./functions/purchase");
11
11
 
12
+ var _setup = require("./functions/setup");
13
+
12
14
  var _on = require("./functions/on");
13
15
 
14
16
  var _update = require("./functions/update");
@@ -24,6 +26,7 @@ var _show = require("./functions/show");
24
26
  class InstrumentsState {
25
27
  constructor() {
26
28
  this.options = null;
29
+ this.data = {};
27
30
  this.mountingPoints = null;
28
31
  this.storefront = null;
29
32
  this.form = null;
@@ -59,7 +62,10 @@ class RebillyInstrumentsInstance {
59
62
  }
60
63
 
61
64
  async update(newOptions) {
62
- await (0, _update.update)(this.state, newOptions);
65
+ await (0, _update.update)({
66
+ state: this.state,
67
+ newOptions
68
+ });
63
69
  }
64
70
 
65
71
  async purchase(payload) {
@@ -69,16 +75,24 @@ class RebillyInstrumentsInstance {
69
75
  });
70
76
  }
71
77
 
78
+ async setup(payload) {
79
+ await (0, _setup.setup)({
80
+ state: this.state,
81
+ payload
82
+ });
83
+ }
84
+
72
85
  async show(componentName, payload) {
73
86
  await (0, _show.show)({
87
+ state: this.state,
74
88
  componentName,
75
- payload,
76
- state: this.state
89
+ payload
77
90
  });
78
91
  }
79
92
 
80
93
  on(eventName, callback) {
81
94
  (0, _on.on)({
95
+ state: this.state,
82
96
  eventName,
83
97
  callback
84
98
  });
@@ -10,13 +10,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
10
10
 
11
11
  describe('RebillyInstruments instance', () => {
12
12
  let rebillyInstruments;
13
-
14
- function setupInstance(options = {
15
- test: 'value'
16
- }) {
17
- rebillyInstruments.mount(options);
18
- }
19
-
20
13
  beforeEach(() => {
21
14
  rebillyInstruments = _index.default;
22
15
  });
@@ -31,18 +24,12 @@ describe('RebillyInstruments instance', () => {
31
24
  `;
32
25
  const options = {
33
26
  form: '.form-selector',
34
- test: 'value'
27
+ summary: '.summary-selector',
28
+ items: []
35
29
  };
36
- setupInstance(options);
30
+ await rebillyInstruments.mount(options);
37
31
  expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
38
32
  expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
39
33
  await (0, _asyncUtilities.avoidUnhandledPromises)();
40
34
  });
41
- it('should be able to trigger a purchase', () => {
42
- jest.spyOn(rebillyInstruments, 'purchase');
43
- const instrument = {};
44
- setupInstance();
45
- rebillyInstruments.purchase(instrument);
46
- expect(rebillyInstruments.purchase).toHaveBeenCalledTimes(1);
47
- });
48
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;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupPaymentInstrument = setupPaymentInstrument;
7
+
8
+ var _index = require("./index");
9
+
10
+ async function setupPaymentInstrument({
11
+ data,
12
+ state
13
+ }) {
14
+ return (0, _index.Endpoint)({
15
+ state
16
+ }, async () => {
17
+ // Create payment instrument
18
+ const {
19
+ fields: instrument
20
+ } = await state.storefront.paymentInstruments.create({
21
+ data
22
+ }); // Setup the payment instrument
23
+
24
+ state.storefront.setSessionToken(instrument.token);
25
+ const setupPayload = {
26
+ id: instrument.id,
27
+ data: {
28
+ websiteId: state.options.websiteId,
29
+ ...data
30
+ }
31
+ };
32
+
33
+ if (state.data.getAmountAndCurrency) {
34
+ setupPayload.data = { ...setupPayload.data,
35
+ ...state.data.getAmountAndCurrency
36
+ };
37
+ }
38
+
39
+ const {
40
+ fields: transaction
41
+ } = await state.storefront.paymentInstruments.setup(setupPayload);
42
+ return {
43
+ instrument,
44
+ transaction
45
+ };
46
+ });
47
+ }