@rebilly/instruments 1.0.1-beta → 1.0.2-beta.10

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 (277) hide show
  1. package/.babelrc +23 -5
  2. package/.eslintrc.js +27 -0
  3. package/.prettierrc.js +11 -0
  4. package/CONTRIBUTING.md +4 -0
  5. package/README.md +361 -2
  6. package/dist/events/base-event.js +51 -37
  7. package/dist/events/events.spec.js +18 -0
  8. package/dist/events/index.js +11 -8
  9. package/dist/functions/destroy.js +27 -5
  10. package/dist/functions/destroy.spec.js +69 -0
  11. package/dist/functions/initialize.js +60 -41
  12. package/dist/functions/initialize.spec.js +13 -13
  13. package/dist/functions/mount/fetch-summary-data.js +46 -0
  14. package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
  15. package/dist/functions/mount/index.js +346 -0
  16. package/dist/functions/mount/mount.spec.js +135 -0
  17. package/dist/functions/on.js +26 -18
  18. package/dist/functions/on.spec.js +45 -63
  19. package/dist/functions/purchase.js +41 -154
  20. package/dist/functions/purchase.spec.js +60 -76
  21. package/dist/functions/show.js +39 -43
  22. package/dist/functions/show.spec.js +57 -0
  23. package/dist/functions/update.js +60 -5
  24. package/dist/functions/update.spec.js +100 -0
  25. package/dist/i18n/en.json +19 -0
  26. package/dist/i18n/es.json +19 -0
  27. package/dist/i18n/i18n.spec.js +6 -23
  28. package/dist/i18n/index.js +44 -67
  29. package/dist/index.js +70 -71
  30. package/dist/index.spec.js +24 -44
  31. package/dist/loader/index.js +63 -62
  32. package/dist/loader/loader.spec.js +14 -11
  33. package/dist/storefront/index.js +28 -39
  34. package/dist/storefront/models/plan-model.js +37 -54
  35. package/dist/storefront/models/product-model.js +25 -36
  36. package/dist/storefront/models/ready-to-pay-model.js +38 -42
  37. package/dist/storefront/models/summary-model.js +72 -99
  38. package/dist/storefront/plans.js +37 -84
  39. package/dist/storefront/plans.spec.js +61 -151
  40. package/dist/storefront/products.js +35 -83
  41. package/dist/storefront/products.spec.js +60 -150
  42. package/dist/storefront/purchase.js +27 -64
  43. package/dist/storefront/purchase.spec.js +51 -87
  44. package/dist/storefront/ready-to-pay.js +45 -107
  45. package/dist/storefront/ready-to-pay.spec.js +72 -147
  46. package/dist/storefront/storefront.spec.js +6 -6
  47. package/dist/storefront/summary.js +37 -84
  48. package/dist/storefront/summary.spec.js +135 -240
  49. package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
  50. package/dist/style/base/index.js +72 -0
  51. package/dist/style/base/theme.js +73 -0
  52. package/dist/style/base/theme.spec.js +30 -0
  53. package/dist/style/browserslist.js +8 -0
  54. package/dist/style/components/address.js +64 -0
  55. package/dist/style/components/button.js +61 -0
  56. package/dist/style/components/divider.js +48 -0
  57. package/dist/style/components/forms/checkbox.js +83 -0
  58. package/dist/style/components/forms/field.js +53 -0
  59. package/dist/style/components/forms/form.js +28 -0
  60. package/dist/style/components/forms/input.js +45 -0
  61. package/dist/style/components/forms/label.js +43 -0
  62. package/dist/style/components/forms/select.js +63 -0
  63. package/dist/style/components/forms/validation.js +34 -0
  64. package/dist/style/components/icons.js +22 -0
  65. package/dist/style/components/index.js +57 -0
  66. package/dist/style/components/loader.js +48 -0
  67. package/dist/style/components/methods.js +104 -0
  68. package/dist/style/components/overlay.js +33 -0
  69. package/dist/style/helpers/index.js +59 -0
  70. package/dist/style/index.js +48 -0
  71. package/dist/style/payment-instruments/content.js +17 -0
  72. package/dist/style/payment-instruments/index.js +20 -0
  73. package/dist/style/payment-instruments/payment-card.js +35 -0
  74. package/dist/style/utils/color-values.js +22 -0
  75. package/dist/style/vendor/framepay.js +34 -0
  76. package/dist/style/vendor/postmate.js +17 -0
  77. package/dist/style/views/confirmation.js +85 -0
  78. package/dist/style/views/index.js +29 -0
  79. package/dist/style/views/method-selector.js +20 -0
  80. package/dist/style/views/modal.js +93 -0
  81. package/dist/style/views/result.js +61 -0
  82. package/dist/style/views/summary.js +123 -0
  83. package/dist/utils/add-dom-element.js +12 -34
  84. package/dist/utils/format-currency.js +4 -4
  85. package/dist/utils/has-valid-css-selector.js +2 -2
  86. package/dist/utils/index.js +15 -31
  87. package/dist/utils/is-dom-element.js +1 -1
  88. package/dist/utils/process-property-as-dom-element.js +12 -17
  89. package/dist/utils/sleep.js +10 -0
  90. package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
  91. package/dist/views/common/iframe/base-iframe.js +57 -0
  92. package/dist/views/common/iframe/event-listeners.js +50 -0
  93. package/dist/views/common/iframe/index.js +19 -0
  94. package/dist/views/common/iframe/method-iframe.js +33 -0
  95. package/dist/views/common/iframe/modal-iframe.js +38 -0
  96. package/dist/views/common/iframe/view-iframe.js +31 -0
  97. package/dist/views/common/render-utilities.js +11 -0
  98. package/dist/views/confirmation.js +82 -0
  99. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
  100. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  101. package/dist/views/method-selector/express-methods/google-pay.js +32 -0
  102. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  103. package/dist/views/method-selector/generate-digital-wallet.js +59 -0
  104. package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
  105. package/dist/views/method-selector/get-method-data.js +25 -0
  106. package/dist/views/method-selector/get-payment-methods.js +55 -0
  107. package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
  108. package/dist/views/method-selector/index.js +133 -0
  109. package/dist/views/method-selector/method-selector.spec.js +139 -0
  110. package/dist/views/method-selector/mount-express-methods.js +69 -0
  111. package/dist/views/method-selector/mount-methods.js +78 -0
  112. package/dist/views/modal.js +83 -0
  113. package/dist/views/result.js +42 -0
  114. package/dist/views/summary.js +162 -0
  115. package/dist/views/summary.spec.js +148 -0
  116. package/package.json +12 -6
  117. package/src/events/base-event.js +35 -12
  118. package/src/events/events.spec.js +11 -0
  119. package/src/events/index.js +12 -6
  120. package/src/functions/destroy.js +22 -3
  121. package/src/functions/destroy.spec.js +63 -0
  122. package/src/functions/initialize.js +43 -20
  123. package/src/functions/initialize.spec.js +9 -7
  124. package/src/functions/mount/fetch-summary-data.js +29 -0
  125. package/src/functions/mount/fetch-summary-data.spec.js +41 -0
  126. package/src/functions/mount/index.js +312 -0
  127. package/src/functions/mount/mount.spec.js +171 -0
  128. package/src/functions/on.js +17 -14
  129. package/src/functions/on.spec.js +39 -29
  130. package/src/functions/purchase.js +24 -64
  131. package/src/functions/purchase.spec.js +19 -17
  132. package/src/functions/show.js +27 -7
  133. package/src/functions/show.spec.js +61 -0
  134. package/src/functions/update.js +50 -3
  135. package/src/functions/update.spec.js +107 -0
  136. package/src/i18n/i18n.spec.js +6 -4
  137. package/src/i18n/index.js +20 -12
  138. package/src/index.js +43 -49
  139. package/src/index.spec.js +11 -42
  140. package/src/loader/index.js +55 -39
  141. package/src/loader/loader.spec.js +30 -23
  142. package/src/storefront/index.js +9 -7
  143. package/src/storefront/models/plan-model.js +1 -1
  144. package/src/storefront/models/product-model.js +1 -1
  145. package/src/storefront/models/ready-to-pay-model.js +10 -4
  146. package/src/storefront/models/summary-model.js +8 -15
  147. package/src/storefront/plans.js +16 -12
  148. package/src/storefront/plans.spec.js +29 -37
  149. package/src/storefront/products.js +16 -12
  150. package/src/storefront/products.spec.js +28 -39
  151. package/src/storefront/purchase.js +8 -6
  152. package/src/storefront/purchase.spec.js +18 -17
  153. package/src/storefront/ready-to-pay.js +19 -13
  154. package/src/storefront/ready-to-pay.spec.js +41 -41
  155. package/src/storefront/storefront.spec.js +1 -1
  156. package/src/storefront/summary.js +14 -12
  157. package/src/storefront/summary.spec.js +37 -50
  158. package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
  159. package/src/style/base/index.js +63 -0
  160. package/src/style/base/theme.js +61 -0
  161. package/src/style/base/theme.spec.js +32 -0
  162. package/src/style/browserslist.js +1 -0
  163. package/src/style/components/address.js +55 -0
  164. package/src/style/components/button.js +54 -0
  165. package/src/style/components/divider.js +39 -0
  166. package/src/style/components/forms/checkbox.js +76 -0
  167. package/src/style/components/forms/field.js +44 -0
  168. package/src/style/components/forms/form.js +19 -0
  169. package/src/style/components/forms/input.js +36 -0
  170. package/src/style/components/forms/label.js +34 -0
  171. package/src/style/components/forms/select.js +54 -0
  172. package/src/style/components/forms/validation.js +25 -0
  173. package/src/style/components/icons.js +13 -0
  174. package/src/style/components/index.js +35 -0
  175. package/src/style/components/loader.js +41 -0
  176. package/src/style/components/methods.js +93 -0
  177. package/src/style/components/overlay.js +24 -0
  178. package/src/style/helpers/index.js +51 -0
  179. package/src/style/index.js +30 -0
  180. package/src/style/payment-instruments/content.js +8 -0
  181. package/src/style/payment-instruments/index.js +10 -0
  182. package/src/style/payment-instruments/payment-card.js +26 -0
  183. package/src/style/utils/color-values.js +9 -0
  184. package/src/style/vendor/framepay.js +25 -0
  185. package/src/style/vendor/postmate.js +8 -0
  186. package/src/style/views/confirmation.js +76 -0
  187. package/src/style/views/index.js +16 -0
  188. package/src/style/views/method-selector.js +11 -0
  189. package/src/style/views/modal.js +84 -0
  190. package/src/style/views/result.js +52 -0
  191. package/src/style/views/summary.js +114 -0
  192. package/src/utils/add-dom-element.js +12 -13
  193. package/src/utils/format-currency.js +4 -1
  194. package/src/utils/has-valid-css-selector.js +2 -2
  195. package/src/utils/index.js +2 -6
  196. package/src/utils/is-dom-element.js +1 -1
  197. package/src/utils/process-property-as-dom-element.js +27 -24
  198. package/src/utils/sleep.js +3 -0
  199. package/src/views/__snapshots__/summary.spec.js.snap +292 -0
  200. package/src/views/common/iframe/base-iframe.js +46 -0
  201. package/src/views/common/iframe/event-listeners.js +27 -0
  202. package/src/views/common/iframe/index.js +7 -0
  203. package/src/views/common/iframe/method-iframe.js +21 -0
  204. package/src/views/common/iframe/modal-iframe.js +27 -0
  205. package/src/views/common/iframe/view-iframe.js +18 -0
  206. package/src/views/common/render-utilities.js +4 -0
  207. package/src/views/confirmation.js +57 -0
  208. package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
  209. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  210. package/src/views/method-selector/express-methods/google-pay.js +25 -0
  211. package/src/views/method-selector/express-methods/paypal.js +7 -0
  212. package/src/views/method-selector/generate-digital-wallet.js +44 -0
  213. package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
  214. package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
  215. package/src/views/method-selector/get-payment-methods.js +40 -0
  216. package/src/views/method-selector/get-payment-methods.spec.js +40 -0
  217. package/src/views/method-selector/index.js +110 -0
  218. package/src/views/method-selector/method-selector.spec.js +146 -0
  219. package/src/views/method-selector/mount-express-methods.js +53 -0
  220. package/src/views/method-selector/mount-methods.js +71 -0
  221. package/src/views/modal.js +84 -0
  222. package/src/views/result.js +30 -0
  223. package/src/{components → views}/summary.js +90 -21
  224. package/src/views/summary.spec.js +170 -0
  225. package/tests/async-utilities.js +22 -0
  226. package/tests/mocks/rebilly-instruments-mock.js +105 -7
  227. package/dist/components/confirmation.js +0 -103
  228. package/dist/components/form/form.js +0 -110
  229. package/dist/components/form/form.spec.js +0 -135
  230. package/dist/components/form/get-method-data.js +0 -21
  231. package/dist/components/form/get-payment-methods.js +0 -42
  232. package/dist/components/form/method-selector.js +0 -61
  233. package/dist/components/form/mount-express-payment-methods.js +0 -102
  234. package/dist/components/form/process-digital-wallet-options.js +0 -20
  235. package/dist/components/form/zoid-helpers.js +0 -130
  236. package/dist/components/result.js +0 -66
  237. package/dist/components/summary.js +0 -60
  238. package/dist/components/summary.spec.js +0 -144
  239. package/dist/events/instrument-ready.js +0 -51
  240. package/dist/events/purchase-complete.js +0 -51
  241. package/dist/functions/mount.js +0 -311
  242. package/dist/functions/mount.spec.js +0 -203
  243. package/dist/styles/base-styles.js +0 -12
  244. package/dist/styles/flat-theme-object.js +0 -42
  245. package/dist/styles/framepay.js +0 -15
  246. package/dist/styles/main.js +0 -25
  247. package/dist/styles/payment-card.js +0 -12
  248. package/dist/styles/shade-tint-values-helper.js +0 -28
  249. package/dist/styles/style-variables.js +0 -43
  250. package/dist/utils/camel-case.js +0 -12
  251. package/dist/utils/kebab-case.js +0 -10
  252. package/dist/utils/un-kebab-case.js +0 -10
  253. package/src/components/confirmation.js +0 -77
  254. package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
  255. package/src/components/form/form.js +0 -88
  256. package/src/components/form/form.spec.js +0 -109
  257. package/src/components/form/get-payment-methods.js +0 -32
  258. package/src/components/form/method-selector.js +0 -47
  259. package/src/components/form/mount-express-payment-methods.js +0 -84
  260. package/src/components/form/process-digital-wallet-options.js +0 -11
  261. package/src/components/form/zoid-helpers.js +0 -114
  262. package/src/components/result.js +0 -50
  263. package/src/components/summary.spec.js +0 -106
  264. package/src/events/instrument-ready.js +0 -11
  265. package/src/events/purchase-complete.js +0 -11
  266. package/src/functions/mount.js +0 -204
  267. package/src/functions/mount.spec.js +0 -172
  268. package/src/styles/base-styles.js +0 -741
  269. package/src/styles/flat-theme-object.js +0 -12
  270. package/src/styles/framepay.js +0 -30
  271. package/src/styles/main.js +0 -17
  272. package/src/styles/payment-card.js +0 -18
  273. package/src/styles/shade-tint-values-helper.js +0 -13
  274. package/src/styles/style-variables.js +0 -34
  275. package/src/utils/camel-case.js +0 -3
  276. package/src/utils/kebab-case.js +0 -3
  277. package/src/utils/un-kebab-case.js +0 -3
@@ -1,89 +1,73 @@
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
5
  var _mswWhenThen = require("msw-when-then");
6
6
 
7
- var _server = require("tests/msw/server");
7
+ var _server = require("../../tests/msw/server");
8
8
 
9
- var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
9
+ var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
10
 
11
11
  var _events = _interopRequireDefault(require("../events"));
12
12
 
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+ var _asyncUtilities = require("../../tests/async-utilities");
14
14
 
15
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
18
-
19
- describe('RebillyInstruments purchase', function () {
20
- it('should be able to make a purchase', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
21
- var configs, options, token, billingAddress, deliveryAddress, fields, rebillyInstruments, purchaseCompleteListener, purchasePayload;
22
- return regeneratorRuntime.wrap(function _callee$(_context) {
23
- while (1) {
24
- switch (_context.prev = _context.next) {
25
- case 0:
26
- configs = {
27
- websiteId: 'test-website-id'
28
- };
29
- options = {
30
- intent: {
31
- items: [{
32
- planId: 'test-plan-id',
33
- quantity: 1
34
- }]
35
- }
36
- };
37
- token = {
38
- id: 'test-token-id'
39
- };
40
- billingAddress = {
41
- billing: 'address'
42
- };
43
- deliveryAddress = {
44
- delivery: 'address'
45
- };
46
- fields = {
47
- orderId: 'test-order-id',
48
- invoice: {
49
- id: 'test-invoice-id'
50
- },
51
- transaction: {
52
- id: 'test-transaction-id'
53
- }
54
- };
55
- (0, _server.when)((0, _mswWhenThen.post)("".concat(_storefrontApiMock.storefrontURL, "/purchase"))).thenReturn((0, _mswWhenThen.ok)(fields));
56
- rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)(configs, options);
57
- jest.spyOn(rebillyInstruments.storefront.purchase, 'purchase');
58
- jest.spyOn(_events["default"].purchaseComplete, 'dispatch');
59
- purchaseCompleteListener = jest.fn();
60
- rebillyInstruments.on('purchase-complete', purchaseCompleteListener);
61
- purchasePayload = {
62
- websiteId: rebillyInstruments.configs.websiteId,
63
- items: rebillyInstruments.options.intent.items,
64
- billingAddress: billingAddress,
65
- deliveryAddress: deliveryAddress,
66
- paymentInstruction: {
67
- token: token.id
68
- }
69
- };
70
- _context.next = 15;
71
- return rebillyInstruments.purchase(purchasePayload);
72
-
73
- case 15:
74
- expect(rebillyInstruments.storefront.purchase.purchase).toBeCalledTimes(1);
75
- expect(rebillyInstruments.storefront.purchase.purchase).toBeCalledWith(expect.objectContaining({
76
- data: purchasePayload
77
- }));
78
- expect(_events["default"].purchaseComplete.dispatch).toBeCalledTimes(1);
79
- expect(purchaseCompleteListener).toBeCalledTimes(1);
80
- expect(purchaseCompleteListener).toBeCalledWith(expect.objectContaining(fields));
81
-
82
- case 20:
83
- case "end":
84
- return _context.stop();
85
- }
17
+ describe('RebillyInstruments purchase', () => {
18
+ it('should be able to make a purchase', async () => {
19
+ const configs = {
20
+ websiteId: 'test-website-id'
21
+ };
22
+ const options = {
23
+ intent: {
24
+ items: [{
25
+ planId: 'test-plan-id',
26
+ quantity: 1
27
+ }]
28
+ }
29
+ };
30
+ const token = {
31
+ id: 'test-token-id'
32
+ };
33
+ const billingAddress = {
34
+ billing: 'address'
35
+ };
36
+ const deliveryAddress = {
37
+ delivery: 'address'
38
+ };
39
+ const fields = {
40
+ orderId: 'test-order-id',
41
+ invoice: {
42
+ id: 'test-invoice-id'
43
+ },
44
+ transaction: {
45
+ id: 'test-transaction-id'
46
+ }
47
+ };
48
+ (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/purchase`)).thenReturn((0, _mswWhenThen.ok)(fields));
49
+ const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)(configs, options);
50
+ jest.spyOn(rebillyInstruments.state.storefront.purchase, 'purchase');
51
+ jest.spyOn(_events.default.purchaseCompleted, 'dispatch');
52
+ const purchaseCompletedListener = jest.fn();
53
+ rebillyInstruments.on('purchase-completed', purchaseCompletedListener);
54
+ const purchasePayload = {
55
+ websiteId: rebillyInstruments.state.configs.websiteId,
56
+ items: rebillyInstruments.state.options.intent.items,
57
+ billingAddress,
58
+ deliveryAddress,
59
+ paymentInstruction: {
60
+ token: token.id
86
61
  }
87
- }, _callee);
88
- })));
62
+ };
63
+ await rebillyInstruments.purchase(purchasePayload);
64
+ expect(rebillyInstruments.state.storefront.purchase.purchase).toBeCalledTimes(1);
65
+ expect(rebillyInstruments.state.storefront.purchase.purchase).toBeCalledWith(expect.objectContaining({
66
+ data: purchasePayload
67
+ }));
68
+ expect(_events.default.purchaseCompleted.dispatch).toBeCalledTimes(1);
69
+ expect(purchaseCompletedListener).toBeCalledTimes(1);
70
+ expect(purchaseCompletedListener).toBeCalledWith(expect.objectContaining(fields));
71
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
72
+ });
89
73
  });
@@ -3,53 +3,49 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Show = Show;
6
+ exports.show = show;
7
7
 
8
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
+ var _confirmation = require("../views/confirmation");
9
9
 
10
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ var _result = require("../views/result");
11
11
 
12
12
  /**
13
- * Register events that will be triggered
14
- * @param {string} componentName - The name of the component to render to the form
15
- * @param {function} payload - The extra data to provide the component
13
+ @typedef ShowParams
14
+ @type {Object}
15
+ @property {string} componentName - The name of the component to render to the form.
16
+ @property {object} payload - The extra data to provide the component.
17
+ @property {object} state - The global state.
16
18
  */
17
- function Show(_x) {
18
- return _Show.apply(this, arguments);
19
- }
20
-
21
- function _Show() {
22
- _Show = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(componentName) {
23
- var payload,
24
- _args = arguments;
25
- return regeneratorRuntime.wrap(function _callee$(_context) {
26
- while (1) {
27
- switch (_context.prev = _context.next) {
28
- case 0:
29
- payload = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
30
- _context.t0 = componentName;
31
- _context.next = _context.t0 === 'result' ? 4 : _context.t0 === 'confirmation' ? 6 : 8;
32
- break;
33
-
34
- case 4:
35
- this._mountResult.call(this, payload);
36
-
37
- return _context.abrupt("break", 9);
38
-
39
- case 6:
40
- this._mountConfirmation.call(this, payload);
41
19
 
42
- return _context.abrupt("break", 9);
43
-
44
- case 8:
45
- throw new Error("'".concat(componentName, "' not a supported component'"));
46
-
47
- case 9:
48
- case "end":
49
- return _context.stop();
50
- }
51
- }
52
- }, _callee, this);
53
- }));
54
- return _Show.apply(this, arguments);
20
+ /**
21
+ * Register events that will be triggered
22
+ * @param {ShowParams} params
23
+ */
24
+ async function show({
25
+ componentName,
26
+ payload,
27
+ state
28
+ }) {
29
+ switch (componentName) {
30
+ case 'result':
31
+ state.iframeComponents = state.iframeComponents.filter(iframe => {
32
+ iframe.destroy();
33
+ return false;
34
+ });
35
+ payload.state = state;
36
+ (0, _result.mountResult)(payload);
37
+ break;
38
+
39
+ case 'confirmation':
40
+ state.iframeComponents = state.iframeComponents.filter(iframe => {
41
+ iframe.destroy();
42
+ return false;
43
+ });
44
+ payload.state = state;
45
+ (0, _confirmation.mountConfirmation)(payload);
46
+ break;
47
+
48
+ default:
49
+ throw new Error(`'${componentName}' not a supported component`);
50
+ }
55
51
  }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var result = _interopRequireWildcard(require("../views/result"));
4
+
5
+ var confirmation = _interopRequireWildcard(require("../views/confirmation"));
6
+
7
+ var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
8
+
9
+ var _show = require("./show");
10
+
11
+ var _index = require("../index");
12
+
13
+ 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); }
14
+
15
+ 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; }
16
+
17
+ const iframeMock = {
18
+ destroy: jest.fn()
19
+ };
20
+ describe('RebillyInstruments show', () => {
21
+ it('should show result component', async () => {
22
+ const mountResult = jest.spyOn(result, 'mountResult').mockReturnValue(Promise.resolve());
23
+ const instance = new _index.RebillyInstrumentsInstance();
24
+ instance.state.iframeComponents.push(iframeMock);
25
+ const payload = {
26
+ test: 'value'
27
+ };
28
+ await instance.show('result', payload);
29
+ expect(mountResult).toBeCalledTimes(1);
30
+ expect(mountResult).toBeCalledWith(payload);
31
+ expect(instance.state.iframeComponents).toEqual([]);
32
+ });
33
+ it('should show confirmation component', async () => {
34
+ const mountConfirmation = jest.spyOn(confirmation, 'mountConfirmation').mockReturnValue(Promise.resolve());
35
+ const instance = new _index.RebillyInstrumentsInstance();
36
+ instance.state.iframeComponents.push(iframeMock);
37
+ const payload = {
38
+ test: 'value'
39
+ };
40
+ await instance.show('confirmation', payload);
41
+ expect(mountConfirmation).toBeCalledTimes(1);
42
+ expect(mountConfirmation).toBeCalledWith(payload);
43
+ expect(instance.state.iframeComponents).toEqual([]);
44
+ });
45
+ it('should fail for non supported component', async () => {
46
+ const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
47
+ let error;
48
+
49
+ try {
50
+ await rebillyInstruments.show('not-a-component', 'any payload');
51
+ } catch (e) {
52
+ error = e;
53
+ }
54
+
55
+ expect(error.toString()).toBe(`Error: 'not-a-component' not a supported component`);
56
+ });
57
+ });
@@ -3,10 +3,65 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Update = Update;
6
+ exports.update = update;
7
7
 
8
- function Update() {
9
- console.error('Update no yet implemented');
10
- }
8
+ var _lodash = _interopRequireDefault(require("lodash.merge"));
11
9
 
12
- ;
10
+ var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
11
+
12
+ var _destroy = require("./destroy");
13
+
14
+ var _initialize = require("./initialize");
15
+
16
+ var _mount = require("./mount");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ async function update(state, newConfig) {
21
+ var _newConfig$options, _newConfig$options$in, _newConfig$options2, _newConfig$options2$i;
22
+
23
+ if (!state.hasMounted) {
24
+ throw Error('Update method cannot be called before mounting instruments');
25
+ }
26
+ /**
27
+ * Framepay locale option is almost but not fully updatable yet:
28
+ * https://github.com/Rebilly/framepay/issues/450
29
+ * That's why this toggle disables real time locale update until that issue is fixed.
30
+ */
31
+
32
+
33
+ const temporaryDisableRealTimeLocaleUpdate = true;
34
+ const updatingJustLocale = (newConfig === null || newConfig === void 0 ? void 0 : newConfig.options) && (0, _lodash2.default)(Object.keys(newConfig === null || newConfig === void 0 ? void 0 : newConfig.options), ['locale']);
35
+
36
+ if (updatingJustLocale && !temporaryDisableRealTimeLocaleUpdate) {
37
+ const updatedOptions = (0, _lodash.default)(state.options, newConfig.options);
38
+ const newLocale = newConfig === null || newConfig === void 0 ? void 0 : newConfig.options.locale;
39
+ state.options = updatedOptions;
40
+ state.translate.updateTranslationsToNewLocale(newLocale);
41
+ state.iframeComponents.forEach(iframe => iframe.component.call('changeLocale', newLocale));
42
+ return;
43
+ } // Check if the provided intent items object is different to avoid merging the items entries
44
+
45
+
46
+ if (newConfig !== null && newConfig !== void 0 && (_newConfig$options = newConfig.options) !== null && _newConfig$options !== void 0 && (_newConfig$options$in = _newConfig$options.intent) !== null && _newConfig$options$in !== void 0 && _newConfig$options$in.items && !(0, _lodash2.default)(state.options.intent.items, newConfig === null || newConfig === void 0 ? void 0 : (_newConfig$options2 = newConfig.options) === null || _newConfig$options2 === void 0 ? void 0 : (_newConfig$options2$i = _newConfig$options2.intent) === null || _newConfig$options2$i === void 0 ? void 0 : _newConfig$options2$i.items)) {
47
+ var _newConfig$options3, _newConfig$options3$i;
48
+
49
+ state.options.intent.items = newConfig === null || newConfig === void 0 ? void 0 : (_newConfig$options3 = newConfig.options) === null || _newConfig$options3 === void 0 ? void 0 : (_newConfig$options3$i = _newConfig$options3.intent) === null || _newConfig$options3$i === void 0 ? void 0 : _newConfig$options3$i.items;
50
+ }
51
+
52
+ const updatedOptions = (0, _lodash.default)(state.options, newConfig.options);
53
+ await (0, _destroy.destroy)({
54
+ state
55
+ });
56
+ (0, _initialize.initialize)({
57
+ state,
58
+ configs: state.configs
59
+ });
60
+ (0, _mount.mount)({
61
+ state,
62
+ form: state.form,
63
+ summary: state.summary,
64
+ options: updatedOptions,
65
+ _dev: state._dev
66
+ });
67
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
4
+
5
+ var _asyncUtilities = require("../../tests/async-utilities");
6
+
7
+ describe('RebillyInstruments Update', () => {
8
+ it('should throw an error when methods are not mounted', async () => {
9
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
10
+ rebillyInstruments.state.hasMounted = false;
11
+ let error;
12
+
13
+ try {
14
+ await rebillyInstruments.update();
15
+ } catch (e) {
16
+ error = e;
17
+ }
18
+
19
+ expect(error).toEqual(new Error('Update method cannot be called before mounting instruments'));
20
+ }); // TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
21
+
22
+ it.skip('should call changeLocale when updating locale options', async () => {
23
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
24
+ const call = jest.fn(); // Simulate mounted iframe
25
+
26
+ const fakeIFrameComponent = {
27
+ destroy: jest.fn(),
28
+ component: {
29
+ call
30
+ }
31
+ };
32
+ rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
33
+ await rebillyInstruments.update({
34
+ options: {
35
+ locale: 'ja'
36
+ }
37
+ });
38
+ expect(call).toBeCalledWith('changeLocale', 'ja'); // It would be better to match real UI instead of implementation state
39
+
40
+ expect(rebillyInstruments.state.options.locale).toBe('ja');
41
+ expect(rebillyInstruments.state.translate.locale).toBe('ja');
42
+ });
43
+ it('should destroy and update when updating options different than locale', async () => {
44
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
45
+ const formElement = document.querySelector('.form-selector');
46
+ const summaryElement = document.querySelector('.summary-selector');
47
+ expect(formElement.innerHTML).not.toEqual('');
48
+ expect(summaryElement.innerHTML).not.toEqual('');
49
+ const call = jest.fn(); // Simulate mounted iframe
50
+
51
+ const fakeIFrameComponent = {
52
+ destroy: jest.fn(),
53
+ component: {
54
+ call
55
+ }
56
+ };
57
+ rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
58
+ await rebillyInstruments.update({
59
+ options: {
60
+ intent: {
61
+ countryCode: 'ES'
62
+ }
63
+ }
64
+ });
65
+ expect(rebillyInstruments.state.options.intent.countryCode).toEqual('ES');
66
+ expect(formElement.innerHTML).toEqual('');
67
+ expect(summaryElement.innerHTML).toEqual('');
68
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
69
+ });
70
+ it('should replace the intent items with different options', async () => {
71
+ const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
72
+ const formElement = document.querySelector('.form-selector');
73
+ const summaryElement = document.querySelector('.summary-selector');
74
+ expect(formElement.innerHTML).not.toEqual('');
75
+ expect(summaryElement.innerHTML).not.toEqual('');
76
+ const call = jest.fn(); // Simulate mounted iframe
77
+
78
+ const fakeIFrameComponent = {
79
+ destroy: jest.fn(),
80
+ component: {
81
+ call
82
+ }
83
+ };
84
+ rebillyInstruments.iframeComponents = [fakeIFrameComponent];
85
+ await rebillyInstruments.update({
86
+ options: {
87
+ intent: {
88
+ items: [{
89
+ planId: 'test-plan-id-1',
90
+ quantity: 5
91
+ }]
92
+ }
93
+ }
94
+ });
95
+ expect(rebillyInstruments.state.options.intent.items[0].quantity).toEqual(5);
96
+ expect(formElement.innerHTML).toEqual('');
97
+ expect(summaryElement.innerHTML).toEqual('');
98
+ await (0, _asyncUtilities.avoidUnhandledPromises)();
99
+ });
100
+ });
@@ -0,0 +1,19 @@
1
+ {
2
+ "en": {
3
+ "summary": {
4
+ "subTotal": "Sub Total",
5
+ "discounts": "Discouts",
6
+ "taxes": "Taxes",
7
+ "shipping": "Shipping",
8
+ "total": "Total"
9
+ },
10
+ "form": {
11
+ "expressCheckout": "Express checkout",
12
+ "or": "Or",
13
+ "popupOverlayText": "Click here to show popup window"
14
+ },
15
+ "paymentMethods": {
16
+ "payment-card": "Payment card"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "es": {
3
+ "summary": {
4
+ "subTotal": "Sub Total",
5
+ "discounts": "Descuentos",
6
+ "taxes": "Impuestos",
7
+ "shipping": "Envío",
8
+ "total": "Total"
9
+ },
10
+ "form": {
11
+ "expressCheckout": "Chequeo rápido",
12
+ "or": "O pague con",
13
+ "popupOverlayText": "Haga clic aquí para mostrar la ventana emergente"
14
+ },
15
+ "paymentMethods": {
16
+ "payment-card": "Tarjeta de crédito"
17
+ }
18
+ }
19
+ }
@@ -2,37 +2,20 @@
2
2
 
3
3
  var _index = require("./index");
4
4
 
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
-
7
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
-
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
14
-
15
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
-
17
- describe('i18n Class', function () {
18
- var canTranslate = document.createElement('div');
5
+ describe('i18n Class', () => {
6
+ const canTranslate = document.createElement('div');
19
7
  canTranslate.innerHTML = 'Discounts';
20
8
  canTranslate.setAttribute('data-rebilly-i18n', 'summary.discounts');
21
- var canNotTranslate = document.createElement('div');
9
+ const canNotTranslate = document.createElement('div');
22
10
  canNotTranslate.innerHTML = 'Untouched';
23
11
  canNotTranslate.setAttribute('data-rebilly-i18n', 'does.not.exist');
24
12
  document.body.append(canTranslate);
25
13
  document.body.append(canNotTranslate);
26
- it('can translate element with proper data attribute and skip wrong translation path or languages', function () {
27
- var translate = new _index.Translate();
14
+ it('can translate element with proper data attribute and skip wrong translation path or languages', () => {
15
+ const translate = new _index.Translate();
28
16
  translate.init('es-US');
29
17
  translate.translateItems();
30
-
31
- var _document$querySelect = document.querySelectorAll('[data-rebilly-i18n]'),
32
- _document$querySelect2 = _slicedToArray(_document$querySelect, 2),
33
- translated = _document$querySelect2[0],
34
- untouched = _document$querySelect2[1];
35
-
18
+ const [translated, untouched] = document.querySelectorAll('[data-rebilly-i18n]');
36
19
  expect(translated.innerHTML).toEqual('Descuentos');
37
20
  expect(untouched.innerHTML).toEqual('Untouched');
38
21
  });