@rebilly/instruments 3.13.2-beta.0 → 3.13.4-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 (84) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +66 -43
  3. package/dist/index.min.js +66 -43
  4. package/package.json +6 -3
  5. package/src/functions/destroy.js +2 -8
  6. package/src/functions/mount/fetch-data.js +2 -9
  7. package/src/functions/mount/index.js +10 -15
  8. package/src/functions/mount/mount.spec.js +11 -10
  9. package/src/functions/mount/setup-framepay-theme.js +72 -30
  10. package/src/functions/mount/setup-options.js +2 -2
  11. package/src/functions/mount/{setup-styles-vars.js → setup-styles.js} +7 -9
  12. package/src/functions/purchase.js +5 -2
  13. package/src/functions/setup.js +6 -3
  14. package/src/functions/show.js +2 -2
  15. package/src/functions/show.spec.js +4 -4
  16. package/src/functions/update.spec.js +3 -4
  17. package/src/instance.js +1 -4
  18. package/src/loader/index.js +33 -57
  19. package/src/storefront/index.js +5 -2
  20. package/src/storefront/payment-instruments.js +0 -7
  21. package/src/style/base/__snapshots__/theme.spec.js.snap +220 -136
  22. package/src/style/base/default-theme.js +14 -187
  23. package/src/style/base/index.js +79 -487
  24. package/src/style/base/theme.js +4 -3
  25. package/src/style/base/theme.spec.js +3 -2
  26. package/src/style/browserslist.js +1 -0
  27. package/src/style/components/accordion.js +140 -0
  28. package/src/style/components/address.js +55 -0
  29. package/src/style/components/button.js +117 -0
  30. package/src/style/components/divider.js +39 -0
  31. package/src/style/components/forms/checkbox.js +75 -0
  32. package/src/style/components/forms/field.js +56 -0
  33. package/src/style/components/forms/form.js +18 -0
  34. package/src/style/components/forms/input.js +77 -0
  35. package/src/style/components/forms/label.js +55 -0
  36. package/src/style/components/forms/radio.js +80 -0
  37. package/src/style/components/forms/select.js +86 -0
  38. package/src/style/components/forms/validation.js +72 -0
  39. package/src/style/components/icons.js +13 -0
  40. package/src/style/components/index.js +39 -0
  41. package/src/style/components/loader.js +41 -0
  42. package/src/style/components/methods.js +97 -0
  43. package/src/style/components/overlay.js +24 -0
  44. package/src/style/helpers/index.js +54 -0
  45. package/src/style/index.js +24 -4
  46. package/src/style/payment-instruments/content.js +8 -0
  47. package/src/style/payment-instruments/index.js +14 -0
  48. package/src/style/payment-instruments/payment-card.js +27 -0
  49. package/src/style/payment-instruments/payment-instrument-list.js +44 -0
  50. package/src/style/payment-instruments/payment-instrument.js +55 -0
  51. package/src/style/utils/color-values.js +1 -1
  52. package/src/style/utils/remove-empty-null.js +10 -0
  53. package/src/style/vendor/framepay.js +28 -0
  54. package/src/style/vendor/postmate.js +18 -0
  55. package/src/style/views/confirmation.js +26 -0
  56. package/src/style/views/index.js +16 -0
  57. package/src/style/views/method-selector.js +11 -0
  58. package/src/style/views/modal.js +91 -0
  59. package/src/style/views/result.js +52 -0
  60. package/src/style/views/summary.js +118 -0
  61. package/src/views/__snapshots__/summary.spec.js.snap +246 -0
  62. package/src/views/common/iframe/base-iframe.js +2 -3
  63. package/src/views/common/iframe/event-listeners.js +9 -12
  64. package/src/views/common/iframe/method-iframe.js +1 -3
  65. package/src/views/common/iframe/modal-iframe.js +2 -4
  66. package/src/views/common/iframe/view-iframe.js +1 -3
  67. package/src/views/confirmation.js +7 -12
  68. package/src/views/method-selector/express-methods/apple-pay.js +92 -0
  69. package/src/views/method-selector/express-methods/index.js +25 -0
  70. package/src/views/method-selector/get-payment-methods.js +1 -0
  71. package/src/views/method-selector/index.js +58 -45
  72. package/src/views/method-selector/method-selector.spec.js +1 -1
  73. package/src/views/method-selector/mount-express-methods.js +26 -66
  74. package/src/views/method-selector/mount-methods.js +178 -0
  75. package/src/views/modal.js +1 -1
  76. package/src/views/result.js +3 -3
  77. package/src/views/summary.js +190 -24
  78. package/src/views/summary.spec.js +145 -0
  79. package/tests/mocks/storefront-api-mock.js +27 -48
  80. package/src/style/utils/minifyCss.js +0 -14
  81. package/src/views/errors.js +0 -95
  82. package/src/views/method-selector/express-methods.js +0 -51
  83. package/src/views/method-selector/generate-framepay-config.js +0 -54
  84. package/src/views/method-selector/generate-framepay-config.spec.js +0 -195
@@ -1,95 +0,0 @@
1
- const errorTemplate = (error) => {
2
- const title = 'Error';
3
-
4
- function displayString(message = null) {
5
- if (message === null) {
6
- message = 'An unexpected error occurred';
7
-
8
- if (typeof error === 'string') {
9
- message = error;
10
- }
11
-
12
- if (error.error) {
13
- message = error.error;
14
- }
15
-
16
- if (error.message) {
17
- message = error.message;
18
- }
19
- }
20
-
21
- return `<p class="rebilly-instruments-error-card-message">${message}</p>`;
22
- }
23
-
24
- function displayList() {
25
- function displayDetail(detail) {
26
- let detailMessage = detail;
27
- if (detail['data-rebilly']) {
28
- detailMessage = `"${detail['data-rebilly']}" ${detail.error}`
29
- }
30
- return detailMessage;
31
- }
32
-
33
- if (error.details.length > 1) {
34
- return `<ul class="rebilly-instruments-error-card-details">
35
- ${error.details.map(detail => `<li>${displayDetail(detail)}</li>`).join('')}
36
- </ul>`
37
- }
38
-
39
- return displayString(displayDetail(error.details[0]));
40
- }
41
-
42
- return `<div class="rebilly-instruments-error-card">
43
- <header class="rebilly-instruments-error-card-header">
44
- <p class="rebilly-instruments-error-card-title">${title}</p>
45
- <button class="rebilly-instruments-error-card-close-button">
46
- <svg class="rebilly-instruments-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
47
- <path d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z" fill-rule="nonzero"/>
48
- </svg>
49
- </button>
50
- </header>
51
- ${error.details ? displayList() : displayString()}
52
- </div>`
53
- };
54
-
55
- export function clearError() {
56
- const errorContainer = document.querySelector('#rebilly-instruments-error');
57
- if (!errorContainer) return ;
58
-
59
- errorContainer.innerHTML = '';
60
- }
61
-
62
- export function showError(error) {
63
- const errorContainer = document.querySelector('#rebilly-instruments-error');
64
- if (!errorContainer) return ;
65
-
66
- errorContainer.innerHTML = errorTemplate(error);
67
-
68
- const closeButton = document.querySelector('.rebilly-instruments-error-card-close-button');
69
- closeButton.addEventListener('click', clearError);
70
-
71
- function clickOutsideError(e) {
72
- if (errorContainer.contains(e.target)) return;
73
-
74
- window.removeEventListener('click', clickOutsideError, false);
75
- clearError();
76
- }
77
-
78
- function windowBlur() {
79
- setTimeout(() => {
80
- if (document.activeElement.tagName === 'IFRAME') {
81
- window.removeEventListener('click', windowBlur, false);
82
- clearError();
83
- }
84
- });
85
- }
86
-
87
- window.addEventListener('click', clickOutsideError);
88
- window.addEventListener('blur', windowBlur, { once: true });
89
-
90
- errorContainer.scrollIntoView({behavior: 'smooth', block: 'end', inline: 'nearest'});
91
- console.error('Rebilly Instruments Error', error);
92
-
93
- // Must focus to ensure window blur event will trigger
94
- window.focus();
95
- }
@@ -1,51 +0,0 @@
1
- export default function mountExpressMethod({
2
- state,
3
- id
4
- }) {
5
- const {Rebilly} = window;
6
- const container = document.querySelector(`.rebilly-instruments-${id}-method`);
7
-
8
- // Hack: The correct way to do this is to accept the options via the framepay package
9
- // Will remove once these options are added to framepay
10
- function updateApplePayStyling() {
11
- const applePayButton = document.querySelector('#rebilly-apple-pay-button');
12
- const {
13
- applePayDisplayOptions: {
14
- buttonHeight
15
- }
16
- } = state.options.digitalWallet.applePay;
17
-
18
- applePayButton.style.margin = '0px';
19
- applePayButton.style.width = '100%';
20
- applePayButton.style.height = buttonHeight;
21
- applePayButton.style.cursor = 'pointer';
22
- }
23
-
24
- function mountButton() {
25
- if(!container.children.length) {
26
- const rebillyMountFunction = {
27
- 'google-pay': 'googlePay',
28
- 'pay-pal-billing-agreement': 'paypal',
29
- 'apple-pay': 'applePay'
30
- }
31
-
32
- if (rebillyMountFunction[id]) {
33
- Rebilly[rebillyMountFunction[id]].mount(`.rebilly-instruments-${id}-method`);
34
-
35
- if (id === 'apple-pay') {
36
- updateApplePayStyling();
37
- }
38
- } else {
39
- console.warn(`method '${id}' is not supported`);
40
- }
41
- }
42
- }
43
-
44
- Rebilly?.on('ready', () => {
45
- mountButton();
46
- });
47
-
48
- Rebilly?.on('error', error => {
49
- console.error(error)
50
- });
51
- }
@@ -1,54 +0,0 @@
1
- import merge from 'lodash.merge';
2
-
3
- export function generateFramepayConfig ({
4
- state,
5
- methodIds
6
- } = {}) {
7
- const {
8
- options,
9
- data
10
- } = state;
11
-
12
- const config = {
13
- style: options.themeFramepay,
14
- locale: options?.locale || 'auto',
15
- organizationId: options.organizationId,
16
- websiteId: options.websiteId,
17
- methods: data.readyToPay,
18
- };
19
-
20
- if (methodIds.includes('pay-pal-billing-agreement')) {
21
- config.transactionData = merge(
22
- typeof config.transactionData === 'object' ? config.transactionData : {},
23
- data.amountAndCurrency
24
- );
25
- config.paypal = options.paymentInstruments.paypal;
26
- }
27
-
28
- if (methodIds.includes('google-pay')) {
29
- config.transactionData = merge(
30
- typeof config.transactionData === 'object' ? config.transactionData : {},
31
- options.digitalWallet.googlePay?.transactionData
32
- );
33
- config.googlePay = options.digitalWallet.googlePay.googlePayDisplayOptions;
34
- }
35
-
36
- if (methodIds.includes('apple-pay')) {
37
- config.transactionData = merge(
38
- typeof config.transactionData === 'object' ? config.transactionData : {},
39
- options.digitalWallet.applePay?.transactionData
40
- );
41
- config.applePay = options.digitalWallet.applePay.applePayDisplayOptions;
42
- }
43
-
44
- if (options.publishableKey) {
45
- config.publishableKey = options.publishableKey;
46
- }
47
-
48
- if (options.jwt) {
49
- config.jwt = options.jwt;
50
- config.sandbox = options.apiMode === 'sandbox';
51
- }
52
-
53
- return config;
54
- }
@@ -1,195 +0,0 @@
1
- import {generateFramepayConfig} from './generate-framepay-config';
2
-
3
- describe('Generate FramePay Config', () => {
4
- let state;
5
-
6
- beforeEach(() => {
7
- state = {
8
- options: {
9
- themeFramepay: {},
10
- locale: 'en-CA',
11
- organizationId: 'test-organization-id',
12
- websiteId: 'test-website-id'
13
- },
14
- data: {
15
- readyToPay: []
16
- }
17
- };
18
- });
19
-
20
- it('should generate default config', () => {
21
- const config = generateFramepayConfig({
22
- state,
23
- methodIds: []
24
- });
25
-
26
- const {options, data} = state;
27
-
28
- expect(config).toEqual(expect.objectContaining ({
29
- style: options.themeFramepay,
30
- locale: options.locale,
31
- organizationId: options.organizationId,
32
- websiteId: options.websiteId,
33
- methods: data.readyToPay,
34
- }))
35
- });
36
-
37
- it('should add publishableKey', () => {
38
- state.options.publishableKey = 'test-publishable-key';
39
-
40
- const config = generateFramepayConfig({
41
- state,
42
- methodIds: []
43
- });
44
-
45
- expect(config).toEqual(expect.objectContaining ({
46
- publishableKey: state.options.publishableKey
47
- }));
48
- });
49
-
50
- it('should add jwt', () => {
51
- state.options.jwt = 'test-jwt';
52
- state.options.apiMode = 'sandbox';
53
-
54
- const config = generateFramepayConfig({
55
- state,
56
- methodIds: []
57
- });
58
-
59
- expect(config).toEqual(expect.objectContaining ({
60
- jwt: state.options.jwt,
61
- sandbox: true
62
- }));
63
- });
64
-
65
- it('should add configurations for PayPal', () => {
66
- state.data.amountAndCurrency = {
67
- amount: 10,
68
- currency: 'CAD'
69
- };
70
- state.options.paymentInstruments = {
71
- paypal: {
72
- test: 'key'
73
- }
74
- }
75
-
76
- const config = generateFramepayConfig({
77
- state,
78
- methodIds: ['pay-pal-billing-agreement']
79
- });
80
-
81
- expect(config).toEqual(expect.objectContaining ({
82
- transactionData: expect.objectContaining(
83
- state.data.amountAndCurrency
84
- ),
85
- paypal: state.options.paymentInstruments.paypal
86
- }));
87
- });
88
-
89
- it('should add configurations for Google Pay', () => {
90
- state.options.digitalWallet = {
91
- googlePay: {
92
- transactionData: {
93
- test: 'key'
94
- },
95
- googlePayDisplayOptions: {
96
- test: 'key'
97
- }
98
- }
99
- }
100
-
101
- const config = generateFramepayConfig({
102
- state,
103
- methodIds: ['google-pay']
104
- });
105
-
106
- expect(config).toEqual(expect.objectContaining ({
107
- transactionData: expect.objectContaining(
108
- state.options.digitalWallet.googlePay.transactionData
109
- ),
110
- googlePay: state.options.digitalWallet.googlePay.googlePayDisplayOptions
111
- }));
112
- });
113
-
114
- it('should add configurations for Apple Pay', () => {
115
- state.options.digitalWallet = {
116
- applePay: {
117
- transactionData: {
118
- test: 'key'
119
- },
120
- applePayDisplayOptions: {
121
- test: 'key'
122
- }
123
- }
124
- }
125
-
126
- const config = generateFramepayConfig({
127
- state,
128
- methodIds: ['apple-pay']
129
- });
130
-
131
- expect(config).toEqual(expect.objectContaining ({
132
- transactionData: expect.objectContaining(
133
- state.options.digitalWallet.applePay.transactionData
134
- ),
135
- applePay: state.options.digitalWallet.applePay.applePayDisplayOptions
136
- }));
137
- });
138
-
139
- it('should add all instrument methods together', () => {
140
- state.data.amountAndCurrency = {
141
- test: 'key'
142
- };
143
- state.options = {
144
- paymentInstruments: {
145
- paypal: {
146
- test: 'key'
147
- }
148
- },
149
- digitalWallet: {
150
- googlePay: {
151
- transactionData: {
152
- test: 'key'
153
- },
154
- googlePayDisplayOptions: {
155
- test: 'key'
156
- }
157
- },
158
- applePay: {
159
- transactionData: {
160
- test: 'key'
161
- },
162
- applePayDisplayOptions: {
163
- test: 'key'
164
- }
165
- }
166
- }
167
- }
168
-
169
- const config = generateFramepayConfig({
170
- state,
171
- methodIds: ['pay-pal-billing-agreement', 'google-pay', 'apple-pay']
172
- });
173
-
174
- expect(config).toEqual(expect.objectContaining ({
175
- transactionData: expect.objectContaining(
176
- state.data.amountAndCurrency
177
- ),
178
- paypal: state.options.paymentInstruments.paypal
179
- }));
180
-
181
- expect(config).toEqual(expect.objectContaining ({
182
- transactionData: expect.objectContaining(
183
- state.options.digitalWallet.googlePay.transactionData
184
- ),
185
- googlePay: state.options.digitalWallet.googlePay.googlePayDisplayOptions
186
- }));
187
-
188
- expect(config).toEqual(expect.objectContaining ({
189
- transactionData: expect.objectContaining(
190
- state.options.digitalWallet.applePay.transactionData
191
- ),
192
- applePay: state.options.digitalWallet.applePay.applePayDisplayOptions
193
- }));
194
- });
195
- });