@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,38 +0,0 @@
1
- import { MockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
2
-
3
- describe('RebillyInstruments instance', () => {
4
- it('should should set configs', () => {
5
- const testConfigs = {
6
- apiMode: 'live',
7
- organizationId: 'test-organization-id',
8
- publishableKey: 'test-publishable-key',
9
- websiteId: 'test-website-id',
10
- _dev: {
11
- liveUrl: null,
12
- sandboxUrl: null,
13
- },
14
- };
15
-
16
- const rebillyInstruments = MockRebillyInstruments(testConfigs);
17
-
18
- expect(rebillyInstruments.configs).toEqual(testConfigs);
19
- });
20
-
21
- it('should setup api instance', () => {
22
- const rebillyInstruments = MockRebillyInstruments();
23
-
24
- expect(rebillyInstruments.storefront).toHaveProperty('setPublishableKey');
25
- });
26
-
27
- it('should have the right developer settings', () => {
28
- const devOptions = {
29
- _dev: {
30
- liveUrl: 'https://api.rebilly.com',
31
- sandboxUrl: 'https://api-sandbox.rebilly.com',
32
- }
33
- }
34
-
35
- const rebillyInstruments = MockRebillyInstruments(devOptions);
36
- expect(rebillyInstruments.configs._dev).toEqual(devOptions._dev);
37
- });
38
- });
@@ -1,26 +0,0 @@
1
- export async function FetchSummaryData({
2
- riskMetadata,
3
- summaryPayload = null
4
- } = {}) {
5
- if (!riskMetadata) {
6
- throw new Error('riskMetadata is required for FetchSummaryData')
7
- }
8
-
9
- const [
10
- readyToPay,
11
- summary,
12
- ] = await Promise.all([
13
- this._fetchReadyToPay(riskMetadata),
14
- this._fetchSummary({ data: summaryPayload })
15
- ]);
16
-
17
- const plans = await this._fetchPlans({data: summary});
18
- const products = await this._fetchProducts({data: plans});
19
-
20
- return {
21
- readyToPay,
22
- summary,
23
- plans,
24
- products
25
- }
26
- }
@@ -1,46 +0,0 @@
1
- import { FetchSummaryData } from './fetch-summary-data';
2
-
3
- describe('Fetch Summary Data function helper', () => {
4
- class TestInstance {
5
- constructor() {
6
- this._fetchReadyToPay = jest.fn();
7
- this._fetchSummary = jest.fn(() => {
8
- return new Promise(resolve => resolve(
9
- {}
10
- ));
11
- });
12
- this._fetchPlans = jest.fn(() => {
13
- return new Promise(resolve => resolve(
14
- [{}]
15
- ));
16
- });
17
- this._fetchProducts = jest.fn();
18
- }
19
-
20
- _FetchSummaryData() {
21
- return FetchSummaryData.apply(this, arguments);
22
- }
23
- }
24
-
25
- it('should fetch all the data', async () => {
26
- const instance = new TestInstance();
27
- await instance._FetchSummaryData({riskMetadata: {}});
28
- expect(instance._fetchReadyToPay).toBeCalledTimes(1);
29
- expect(instance._fetchSummary).toBeCalledTimes(1);
30
- expect(instance._fetchPlans).toBeCalledTimes(1);
31
- expect(instance._fetchProducts).toBeCalledTimes(1);
32
- });
33
-
34
- it('should pass riskMetadata to ready to pay', async () => {
35
- const testRiskMetadata = {};
36
- const instance = new TestInstance();
37
-
38
- await instance._FetchSummaryData({riskMetadata: testRiskMetadata });
39
- expect(instance._fetchReadyToPay).toBeCalledWith(testRiskMetadata);
40
-
41
-
42
- expect(async () => {
43
- await instance._FetchSummaryData();
44
- }).rejects.toEqual(new Error('riskMetadata is required for FetchSummaryData'));
45
- });
46
- });
@@ -1,16 +0,0 @@
1
- export function processDigitalWalletOptions(options, methods) {
2
- const {paymentInstruments} = options;
3
- const digitalWalletOptions = {};
4
- const googlePayMethod = methods.find(method => method.feature?.name === 'Google Pay');
5
-
6
- if (paymentInstruments?.googlePay && googlePayMethod) {
7
- const {googlePay} = paymentInstruments;
8
- const {merchantName, merchantOrigin} = googlePayMethod.feature;
9
- digitalWalletOptions.merchantConfig = {
10
- merchantName,
11
- merchantOrigin
12
- };
13
- digitalWalletOptions.googlePayDisplayOptions = googlePay.displayOptions;
14
- }
15
- return digitalWalletOptions;
16
- }
@@ -1,94 +0,0 @@
1
- import { processDigitalWalletOptions } from './process-digital-wallet-options'
2
- import ReadyToPayModel from '@/storefront/models/ready-to-pay-model'
3
-
4
- describe('processDigitalWalletOptions', () => {
5
- describe('Google Pay', () => {
6
- it('should return the correct google pay configs when google pay is configured and the payment method is found', () => {
7
- const options = {
8
- paymentInstruments: {
9
- googlePay: {
10
- displayOptions: {
11
- buttonColor: 'black',
12
- buttonType: 'short',
13
- buttonHeight: '44px',
14
- },
15
- },
16
- },
17
- }
18
-
19
- const availablePaymentMethods = [
20
- new ReadyToPayModel({
21
- method: 'payment-card',
22
- feature: {
23
- name: 'Google Pay',
24
- merchantName: 'google-pay-merchant-name',
25
- merchantOrigin: 'google-pay-merchant-origin',
26
- },
27
- brands: ['Visa'],
28
- }),
29
- ]
30
-
31
- expect(processDigitalWalletOptions(options, availablePaymentMethods))
32
- .toMatchInlineSnapshot(`
33
- Object {
34
- "googlePayDisplayOptions": Object {
35
- "buttonColor": "black",
36
- "buttonHeight": "44px",
37
- "buttonType": "short",
38
- },
39
- "merchantConfig": Object {
40
- "merchantName": "google-pay-merchant-name",
41
- "merchantOrigin": "google-pay-merchant-origin",
42
- },
43
- }
44
- `);
45
- })
46
-
47
- it('should not return any google pay options if google pay is not found in the ready to pay results', () => {
48
- const options = {
49
- paymentInstruments: {
50
- googlePay: {
51
- displayOptions: {
52
- buttonColor: 'black',
53
- buttonType: 'short',
54
- buttonHeight: '44px',
55
- },
56
- },
57
- },
58
- }
59
-
60
- const availablePaymentMethods = [
61
- new ReadyToPayModel({
62
- method: 'payment-card',
63
- brands: ['Visa'],
64
- }),
65
- ]
66
-
67
- expect(
68
- processDigitalWalletOptions(options, availablePaymentMethods),
69
- ).toEqual({});
70
- });
71
-
72
- it('should not return any google pay options if google pay is not configured in options', () => {
73
- const options = {
74
- paymentInstruments: {},
75
- }
76
-
77
- const availablePaymentMethods = [
78
- new ReadyToPayModel({
79
- method: 'payment-card',
80
- feature: {
81
- name: 'Google Pay',
82
- merchantName: 'google-pay-merchant-name',
83
- merchantOrigin: 'google-pay-merchant-origin',
84
- },
85
- brands: ['Visa'],
86
- }),
87
- ]
88
-
89
- expect(
90
- processDigitalWalletOptions(options, availablePaymentMethods),
91
- ).toEqual({});
92
- });
93
- });
94
- });