@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,126 +1,53 @@
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
4
 
5
- var _framepayMock = require("tests/mocks/framepay-mock");
5
+ var _instruments = require("@rebilly/instruments");
6
6
 
7
7
  var _mswWhenThen = require("msw-when-then");
8
8
 
9
- var _server = require("tests/msw/server");
9
+ var _server = require("../../../tests/msw/server");
10
10
 
11
- var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
11
+ var _storefrontApiMock = require("../../../tests/mocks/storefront-api-mock");
12
12
 
13
- var _planModel = _interopRequireDefault(require("@/storefront/models/plan-model"));
13
+ var _planModel = _interopRequireDefault(require("../../storefront/models/plan-model"));
14
14
 
15
- var _productModel = _interopRequireDefault(require("@/storefront/models/product-model"));
15
+ var _productModel = _interopRequireDefault(require("../../storefront/models/product-model"));
16
16
 
17
- var _summaryModel = _interopRequireDefault(require("@/storefront/models/summary-model"));
17
+ var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
18
18
 
19
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
20
 
21
21
  describe('RebillyInstruments instance', () => {
22
- it('should throw error when there is no DOM element to mount the form', () => {
23
- document.body.innerHTML = `
24
- <div class="form-selector"></div>
25
- <div class="summary-selector"></div>
26
- `;
27
- const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
28
- expect(async () => {
29
- await rebillyInstruments.mount({});
30
- }).rejects.toEqual(new Error('Could not find DOM element with CSS class or id ".rebilly-instruments" to mount form'));
31
- });
32
- it('should throw error when providing the wrong type for the form property', () => {
33
- document.body.innerHTML = `
34
- <div class="form-selector"></div>
35
- <div class="summary-selector"></div>
36
- `;
37
- const options = {
38
- form: []
39
- };
40
- const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
41
- expect(async () => {
42
- await rebillyInstruments.mount(options);
43
- }).rejects.toEqual(new Error('Please provide a valid CSS class, id or DOM element for "form" property'));
44
- });
45
- it('should inject HTML to the merchant\'s website', async () => {
46
- const testPlan = new _planModel.default({
47
- name: 'Test Plan',
48
- id: 'test-plan-id-1'
49
- });
50
- const testProduct = new _productModel.default({
51
- description: 'My Awesome Product',
52
- id: 'test-product-1'
53
- });
54
- const testSummary = new _summaryModel.default({
55
- currency: 'USD',
56
- lineItems: [{
57
- description: 'test-plan-id-1',
58
- planId: 'test-plan-id-1',
59
- productId: 'test-product-1',
60
- quantity: 1
61
- }]
62
- });
22
+ it("should inject HTML to the merchant's website", async () => {
63
23
  const framePayScriptUrl = 'https://framepay.rebilly.com/rebilly.js';
64
24
  const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
65
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((() => {
66
- return (0, _mswWhenThen.ok)([{
67
- method: 'payment-card',
68
- feature: {
69
- name: 'Google Pay',
70
- merchantName: 'google-pay-merchant-name',
71
- merchantOrigin: 'google-pay-merchant-origin'
72
- },
73
- brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
74
- filters: []
75
- }]);
76
- })());
77
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((() => {
78
- return (0, _mswWhenThen.ok)(testSummary);
79
- })());
80
- (0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((() => {
81
- return (0, _mswWhenThen.ok)([testPlan]);
82
- })());
83
- (0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((() => {
84
- return (0, _mswWhenThen.ok)([testProduct]);
85
- })());
86
- document.body.innerHTML = `
87
- <div class="form-selector"></div>
88
- <div class="summary-selector"></div>
89
- `;
90
25
  const options = {
91
26
  form: '.form-selector',
92
27
  summary: '.summary-selector',
93
- _dev: {
94
- framePayStyleLink: framePayStyleUrl
95
- },
96
- options: {
97
- locale: 'auto',
98
- intent: {
99
- items: [{
100
- planId: 'test-plan-id-1',
101
- quantity: 1
102
- }]
103
- }
104
- }
105
- };
106
- const framepayMock = (0, _framepayMock.createFramepayMock)();
107
- global.Rebilly = framepayMock;
108
- const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)({
28
+ locale: 'auto',
29
+ items: [{
30
+ planId: 'test-plan-id-1',
31
+ quantity: 1
32
+ }],
109
33
  theme: {
110
34
  color: {
111
35
  background: '#000'
112
36
  }
113
37
  },
114
38
  css: `
115
- .rebilly-instruments-summary-line-item-synopsis-title {
116
- color: rgb(0, 68, 212);
117
- }
118
- `
119
- });
120
- await rebillyInstruments.mount(options); // Mounts form and summary
39
+ .rebilly-instruments-summary-line-item-synopsis-title {
40
+ color: rgb(0, 68, 212);
41
+ }
42
+ `,
43
+ _dev: {
44
+ framePayStyleLink: framePayStyleUrl
45
+ }
46
+ };
47
+ await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)(options); // Mounts form and summary
121
48
 
122
49
  const summarySelector = document.querySelector('.summary-selector');
123
- expect(summarySelector.innerHTML).toMatch(testPlan.name); // Theme config overrides initial styles
50
+ expect(summarySelector.innerHTML).toMatch('My Product'); // Theme config overrides initial styles
124
51
 
125
52
  const SUMMARY_CONTAINER = summarySelector.querySelector('.rebilly-instruments-content');
126
53
  expect(getComputedStyle(SUMMARY_CONTAINER).background).toEqual('rgb(0, 0, 0)'); // CSS config property overrides initial styles
@@ -134,30 +61,6 @@ describe('RebillyInstruments instance', () => {
134
61
 
135
62
  const STYLE_LINKS = [...document.querySelectorAll('head link')];
136
63
  const FRAMEPAY_STYLE = STYLE_LINKS.find(script => script.href === framePayStyleUrl);
137
- expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl); // objectContaining allows matching a subset (this could be done with sinon + mocha too)
138
-
139
- expect(framepayMock.initialize).toHaveBeenCalledWith(expect.objectContaining({
140
- digitalWallet: {
141
- googlePayDisplayOptions: {
142
- buttonColor: 'black',
143
- buttonHeight: '44px',
144
- buttonType: 'short'
145
- },
146
- merchantConfig: {
147
- merchantName: 'google-pay-merchant-name',
148
- merchantOrigin: 'google-pay-merchant-origin'
149
- },
150
- transactionData: {
151
- amount: 0,
152
- countryCode: 'US',
153
- currency: 'USD',
154
- label: 'test-website-id'
155
- }
156
- },
157
- organizationId: 'test-organization-id',
158
- publishableKey: 'test-api-key'
159
- })); //Simulate that framepay is ready
160
-
161
- framepayMock.simulateEvent('ready');
64
+ expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl);
162
65
  });
163
66
  });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("../../utils");
9
+
10
+ var _default = ({
11
+ element = '',
12
+ options = {}
13
+ }) => {
14
+ if (element !== 'form' && element !== 'summary') {
15
+ throw new Error('element must be "form" or "summary"');
16
+ }
17
+
18
+ const getProp = () => {
19
+ if (options[element]) {
20
+ return options[element];
21
+ }
22
+
23
+ switch (element) {
24
+ case 'summary':
25
+ return '.rebilly-instruments-summary';
26
+
27
+ case 'form':
28
+ default:
29
+ return '.rebilly-instruments';
30
+ }
31
+ };
32
+
33
+ return (0, _utils.processPropertyAsDOMElement)({
34
+ prop: getProp(),
35
+ propName: element,
36
+ isRequired: ['form'].includes(element)
37
+ });
38
+ };
39
+
40
+ exports.default = _default;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("../../utils");
9
+
10
+ var _default = ({
11
+ state: {
12
+ options: {
13
+ _dev
14
+ }
15
+ }
16
+ } = {}) => {
17
+ const framePayUrls = {
18
+ script: _dev ? _dev.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js' : 'https://framepay.rebilly.com/rebilly.js',
19
+ style: _dev ? _dev.framePayStyleLink || 'https://framepay.rebilly.com/rebilly.css' : 'https://framepay.rebilly.com/rebilly.css'
20
+ };
21
+
22
+ if (!document.querySelectorAll('[framepay*="script"]').length) {
23
+ (0, _utils.addDOMElement)({
24
+ element: 'script',
25
+ attributes: {
26
+ framepay: 'script',
27
+ src: framePayUrls.script
28
+ },
29
+ target: 'head'
30
+ });
31
+ }
32
+
33
+ if (!document.querySelectorAll('[framepay*="stylesheet"]').length) {
34
+ (0, _utils.addDOMElement)({
35
+ element: 'link',
36
+ attributes: {
37
+ framepay: 'stylesheet',
38
+ href: framePayUrls.style,
39
+ rel: 'stylesheet'
40
+ },
41
+ target: 'head'
42
+ });
43
+ }
44
+ };
45
+
46
+ exports.default = _default;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const triggerTranslations = ({
9
+ state
10
+ }) => {
11
+ state.translate.init(state.options.locale, state.options.i18n);
12
+ state.translate.translateItems();
13
+ };
14
+
15
+ var _default = ({
16
+ state = {}
17
+ }) => {
18
+ var _state$data$riskMetad, _state$data$riskMetad2;
19
+
20
+ if (state.options.locale === 'auto' && (_state$data$riskMetad = state.data.riskMetadata) !== null && _state$data$riskMetad !== void 0 && (_state$data$riskMetad2 = _state$data$riskMetad.browserData) !== null && _state$data$riskMetad2 !== void 0 && _state$data$riskMetad2.language) {
21
+ const {
22
+ browserData: {
23
+ language
24
+ }
25
+ } = state.data.riskMetadata;
26
+ state.options.locale = language;
27
+ }
28
+
29
+ state.translate.init(state.options.locale, state.options.i18n);
30
+ return triggerTranslations;
31
+ };
32
+
33
+ exports.default = _default;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateOptions = validateOptions;
7
+ exports.default = exports.defaults = void 0;
8
+
9
+ var _lodash = _interopRequireDefault(require("lodash.merge"));
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ const defaults = {
14
+ countryCode: 'US',
15
+ locale: 'auto',
16
+ paymentInstruments: {
17
+ address: {
18
+ name: 'default',
19
+ region: 'default',
20
+ hide: [],
21
+ show: [],
22
+ require: []
23
+ },
24
+ compactExpressInstruments: true,
25
+ googlePay: {
26
+ displayOptions: {
27
+ buttonColor: 'black',
28
+ buttonType: 'short',
29
+ buttonHeight: '44px'
30
+ }
31
+ },
32
+ applePay: {
33
+ displayOptions: {
34
+ buttonColor: 'black',
35
+ buttonType: 'plain',
36
+ buttonHeight: '44px'
37
+ }
38
+ },
39
+ paymentCard: {
40
+ popup: false
41
+ }
42
+ },
43
+ transactionType: 'purchase',
44
+ features: {
45
+ autoConfirmation: true,
46
+ autoResult: true
47
+ }
48
+ };
49
+ exports.defaults = defaults;
50
+
51
+ function validateOptions(options) {
52
+ // TODO: validate more options
53
+ const purchaseData = [options.items, options.invoiceId, options.money, options.transactionId].filter(v => v);
54
+
55
+ if (purchaseData.length === 0) {
56
+ throw new Error('Must provide purchase data');
57
+ }
58
+
59
+ if (purchaseData.length > 1) {
60
+ throw new Error('Must provide only one purchase data type');
61
+ }
62
+ }
63
+
64
+ var _default = ({
65
+ options = {}
66
+ } = {}) => {
67
+ validateOptions(options);
68
+ const _computed = {
69
+ paymentMethodsUrl: options._dev ? options._dev.paymentMethodsUrl || 'https://forms.local.rebilly.dev:3000' : 'https://forms.secure-payments.app'
70
+ };
71
+ const combinedOptions = (0, _lodash.default)({ ...defaults
72
+ }, {
73
+ organizationId: options.organizationId,
74
+ publishableKey: options.publishableKey,
75
+ websiteId: options.websiteId,
76
+ apiMode: options.apiMode,
77
+ i18n: options.i18n,
78
+ theme: options.theme,
79
+ css: options.css,
80
+ locale: options.locale,
81
+ countryCode: options.countryCode,
82
+ features: options.features,
83
+ paymentInstruments: options.paymentInstruments,
84
+ transactionType: options.transactionType,
85
+ _computed
86
+ }); // Add optional key's
87
+
88
+ ['items', 'money', 'invoiceId', 'transactionId', 'customerJwt', '_dev'].forEach(key => {
89
+ if (options[key]) {
90
+ combinedOptions[key] = options[key];
91
+ }
92
+ });
93
+ return combinedOptions;
94
+ };
95
+
96
+ exports.default = _default;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _rebillyInstrumentsMock = require("../../../tests/mocks/rebilly-instruments-mock");
4
+
5
+ var _setupOptions = _interopRequireWildcard(require("./setup-options"));
6
+
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); }
8
+
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; }
10
+
11
+ describe('Setup mount options', () => {
12
+ it("should fill with default options", () => {
13
+ const options = (0, _setupOptions.default)({
14
+ options: {
15
+ items: [{
16
+ planId: "test-plan-id",
17
+ quantity: 1
18
+ }]
19
+ }
20
+ });
21
+ expect(options).toMatchObject(_setupOptions.defaults);
22
+ });
23
+ it("should setup options from mount", async () => {
24
+ const options = {
25
+ publishableKey: 'test-publishable-key',
26
+ organizationId: 'test-organization-id',
27
+ websiteId: 'test-website-id',
28
+ invoiceId: 'test-invoice-id',
29
+ customerJwt: 'test-customer-jwt'
30
+ };
31
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)(options);
32
+ expect(rebillyInstruments.state.options).toMatchObject(options);
33
+ });
34
+ });
35
+ describe('Validate mount options', () => {
36
+ it("should throw an error with no purchase data", async () => {
37
+ let error = null;
38
+
39
+ try {
40
+ const options = {};
41
+ (0, _setupOptions.validateOptions)(options);
42
+ } catch (e) {
43
+ error = e;
44
+ }
45
+
46
+ expect(error.message).toBe('Must provide purchase data');
47
+ });
48
+ it("should throw error if there are more than one purchase property", () => {
49
+ let error = null;
50
+
51
+ try {
52
+ const options = {
53
+ invoiceId: "test-invoice-id",
54
+ items: [{
55
+ planId: "test-plan-id",
56
+ quantity: 1
57
+ }]
58
+ };
59
+ (0, _setupOptions.validateOptions)(options);
60
+ } catch (e) {
61
+ error = e;
62
+ }
63
+
64
+ expect(error.message).toBe('Must provide only one purchase data type');
65
+ });
66
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _storefront = _interopRequireDefault(require("../../storefront"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = ({
13
+ options: {
14
+ publishableKey,
15
+ orgnizationId,
16
+ apiMode,
17
+ _dev
18
+ }
19
+ }) => {
20
+ const storefront = {
21
+ publishableKey,
22
+ orgnizationId,
23
+ mode: apiMode || 'live'
24
+ };
25
+
26
+ if (_dev) {
27
+ storefront.liveUrl = _dev.liveUrl || 'https://api.rebilly.com';
28
+ storefront.sandboxUrl = _dev.sandboxUrl || 'https://api-sandbox.rebilly.com';
29
+ }
30
+
31
+ return (0, _storefront.default)(storefront);
32
+ };
33
+
34
+ exports.default = _default;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _style = require("../../style");
9
+
10
+ var _utils = require("../../utils");
11
+
12
+ var _default = async ({
13
+ options: {
14
+ theme = {},
15
+ css
16
+ }
17
+ } = {}) => {
18
+ // Adds base stylesheet
19
+ const style = await (0, _style.mainStyle)(theme || {});
20
+ (0, _utils.addDOMElement)({
21
+ element: 'style',
22
+ attributes: {
23
+ type: 'text/css'
24
+ },
25
+ content: style,
26
+ target: 'head'
27
+ }); // Adds options CSS to override any styles
28
+
29
+ if (css) {
30
+ (0, _utils.addDOMElement)({
31
+ element: 'style',
32
+ attributes: {
33
+ type: 'text/css'
34
+ },
35
+ content: css,
36
+ target: 'head'
37
+ });
38
+ }
39
+
40
+ return style;
41
+ };
42
+
43
+ exports.default = _default;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.On = On;
6
+ exports.on = on;
7
7
 
8
8
  var _lodash = _interopRequireDefault(require("lodash.camelcase"));
9
9
 
@@ -15,12 +15,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
+ /**
19
+ @typedef OnParams
20
+ @type {Object}
21
+ @property {string} eventName - The name of the event
22
+ @property {function} callback - The function that is triggered by the event.
23
+ */
24
+
18
25
  /**
19
26
  * Register events that will be triggered
20
- * @param {string} eventName - The name of the event
21
- * @param {function} callback - The function that is triggered by the event.
27
+ * @param {OnParams} params
22
28
  */
23
- function On(eventName, callback) {
29
+ function on({
30
+ eventName,
31
+ callback
32
+ }) {
24
33
  if (!_events.publicEventNames.includes(eventName)) {
25
34
  throw new Error(`${eventName} is not a supported event`);
26
35
  }
@@ -2,15 +2,15 @@
2
2
 
3
3
  var _lodash = _interopRequireDefault(require("lodash.camelcase"));
4
4
 
5
- var _events = _interopRequireDefault(require("../events"));
5
+ var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
6
6
 
7
- var _rebillyInstrumentsMock = require("tests/mocks/rebilly-instruments-mock");
7
+ var _events = _interopRequireDefault(require("../events"));
8
8
 
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
 
11
11
  describe('RebillyInstruments on', () => {
12
12
  it('should register event listeners', async () => {
13
- const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
13
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
14
14
  const publicEventNames = ['instrument-ready', 'purchase-completed'];
15
15
  await Promise.all(publicEventNames.map(async eventName => {
16
16
  const callback = jest.fn();
@@ -25,9 +25,23 @@ describe('RebillyInstruments on', () => {
25
25
  expect(callback).toBeCalledWith(details);
26
26
  }));
27
27
  });
28
+ it('should throw error for internal namespaced events', async () => {
29
+ const callback = jest.fn();
30
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
31
+ let error;
32
+
33
+ try {
34
+ // rebilly-instruments-purchase-completed will be used internally but not available externally
35
+ await rebillyInstruments.on('rebilly-instruments-purchase-completed', callback);
36
+ } catch (e) {
37
+ error = e;
38
+ }
39
+
40
+ expect(error).toEqual(new Error('rebilly-instruments-purchase-completed is not a supported event'));
41
+ });
28
42
  it('should throw error for a non defined event', async () => {
29
43
  const callback = jest.fn();
30
- const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
44
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
31
45
  let error;
32
46
 
33
47
  try {
@@ -36,6 +50,6 @@ describe('RebillyInstruments on', () => {
36
50
  error = e;
37
51
  }
38
52
 
39
- expect(error).toEqual(new Error(`not-an-event is not a supported event`));
53
+ expect(error).toEqual(new Error('not-an-event is not a supported event'));
40
54
  });
41
55
  });