@rebilly/instruments 3.3.0-beta.0 → 3.5.0-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.
- package/dist/index.js +8 -8
- package/dist/index.min.js +8 -8
- package/package.json +1 -1
- package/src/functions/mount/index.js +4 -2
- package/src/functions/mount/mount.spec.js +5 -7
- package/src/functions/mount/setup-framepay.js +17 -38
- package/src/functions/purchase.js +12 -3
- package/src/functions/setup.js +20 -2
- package/src/instance.spec.js +4 -2
- package/src/storefront/models/ready-to-pay-model.js +6 -0
- package/src/storefront/payment-instruments.js +2 -2
- package/src/storefront/ready-to-pay.js +2 -0
- package/src/style/components/accordion.js +41 -41
- package/src/style/components/button.js +17 -0
- package/src/style/components/forms/checkbox.js +18 -19
- package/src/style/components/forms/radio.js +80 -0
- package/src/style/components/index.js +5 -3
- package/src/style/helpers/index.js +3 -0
- package/src/style/payment-instruments/index.js +4 -0
- package/src/style/payment-instruments/payment-instrument-list.js +44 -0
- package/src/style/payment-instruments/payment-instrument.js +43 -0
- package/src/style/views/confirmation.js +0 -51
- package/src/views/method-selector/express-methods/apple-pay.js +4 -2
- package/src/views/method-selector/mount-methods.js +27 -27
- package/tests/mocks/rebilly-instruments-mock.js +22 -18
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// -----------------------------------------------------------------------------
|
|
2
|
+
// This file contains all styles related to the payment instrument list component.
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
4
|
+
export const paymentInstrumentList = () => `
|
|
5
|
+
.rebilly-instruments-payment-instrument-list {
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.rebilly-instruments-payment-instrument-list > li {
|
|
11
|
+
display: flex;
|
|
12
|
+
width: 100%;
|
|
13
|
+
align-items: center;
|
|
14
|
+
list-style-type: none;
|
|
15
|
+
padding: var(--rebilly-spacings-xs) 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.rebilly-instruments-payment-instrument-list > li:first-child {
|
|
19
|
+
padding-top: 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.rebilly-instruments-payment-instrument-list > li:last-child {
|
|
23
|
+
padding-bottom: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.rebilly-instruments-payment-instrument-list > li + li {
|
|
27
|
+
border-top: 1px solid var(--rebilly-colorMutedBorder);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.rebilly-instruments-payment-instrument-list.is-relaxed > li {
|
|
31
|
+
min-height: var(--rebilly-spacings-form-element-min-height);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.rebilly-instruments-payment-instrument-list .rebilly-instruments-form-field {
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.rebilly-instruments-payment-instrument-list > li .rebilly-instruments-payment-instrument-list-container {
|
|
39
|
+
display: flex;
|
|
40
|
+
justify-content: space-between;
|
|
41
|
+
align-items: center;
|
|
42
|
+
width: 100%;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// -----------------------------------------------------------------------------
|
|
2
|
+
// This file contains all styles related to the payment instrument component.
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
4
|
+
export const paymentInstrument = () => `
|
|
5
|
+
.rebilly-instruments-payment-instrument {
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
height: 26px;
|
|
10
|
+
margin: 0 0 var(--rebilly-spacings-l);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.rebilly-instruments-payment-instrument figure {
|
|
14
|
+
margin: 0 var(--rebilly-spacings-2xs) 0 0;
|
|
15
|
+
height: 26px;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.rebilly-instruments-payment-instrument figure img {
|
|
20
|
+
width: auto;
|
|
21
|
+
height: 100%;
|
|
22
|
+
border-radius: 4px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.rebilly-instruments-payment-instrument-brand,
|
|
26
|
+
.rebilly-instruments-payment-instrument-exp,
|
|
27
|
+
.rebilly-instruments-payment-instrument-last4 {
|
|
28
|
+
display: inline-block;
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.rebilly-instruments-payment-instrument-brand {
|
|
33
|
+
margin: 0 0 0 var(--rebilly-spacings-s);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.rebilly-instruments-payment-instrument-last4 {
|
|
37
|
+
margin: 0 var(--rebilly-spacings-s);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rebilly-instruments-payment-instrument-exp {
|
|
41
|
+
color: var(--rebilly-colorMutedText);
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
@@ -23,55 +23,4 @@ export const confirmation = () => `
|
|
|
23
23
|
.rebilly-instruments-confirmation-address-title .rebilly-instruments-link {
|
|
24
24
|
margin-left: var(--rebilly-spacings-s);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
.rebilly-instruments-confirmation-address-actions {
|
|
28
|
-
margin-top: var(--rebilly-spacings-base);
|
|
29
|
-
display: flex;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.rebilly-instruments-confirmation-address-actions :first-child {
|
|
33
|
-
margin: 0 var(--rebilly-spacings-xs) 0 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.rebilly-instruments-confirmation-address-actions :last-child {
|
|
37
|
-
margin: 0 0 0 var(--rebilly-spacings-xs);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.rebilly-instruments-confirmation-payment-method {
|
|
41
|
-
display: inline-flex;
|
|
42
|
-
align-items: center;
|
|
43
|
-
justify-content: space-between;
|
|
44
|
-
height: 26px;
|
|
45
|
-
margin: 0 0 var(--rebilly-spacings-l);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.rebilly-instruments-confirmation-payment-method figure {
|
|
49
|
-
margin: 0 var(--rebilly-spacings-2xs) 0 0;
|
|
50
|
-
height: 26px;
|
|
51
|
-
padding: 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.rebilly-instruments-confirmation-payment-method figure img {
|
|
55
|
-
width: auto;
|
|
56
|
-
height: 100%;
|
|
57
|
-
border-radius: 4px;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.rebilly-instruments-confirmation-payment-method-brand,
|
|
61
|
-
.rebilly-instruments-confirmation-payment-method-exp,
|
|
62
|
-
.rebilly-instruments-confirmation-payment-method-last4 {
|
|
63
|
-
display: inline-block;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.rebilly-instruments-confirmation-payment-method-brand {
|
|
67
|
-
margin: 0 0 0 var(--rebilly-spacings-s);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.rebilly-instruments-confirmation-payment-method-last4 {
|
|
71
|
-
margin: 0 var(--rebilly-spacings-s);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.rebilly-instruments-confirmation-payment-method-exp {
|
|
75
|
-
color: var(--rebilly-colorMutedText);
|
|
76
|
-
}
|
|
77
26
|
`;
|
|
@@ -43,7 +43,9 @@ export default function mountApplePay({
|
|
|
43
43
|
Rebilly.initialize({
|
|
44
44
|
publishableKey: state.options.publishableKey,
|
|
45
45
|
organizationId: state.options.organizationId,
|
|
46
|
-
digitalWallet
|
|
46
|
+
transactionData: digitalWallet.transactionData,
|
|
47
|
+
methods: state.data.readyToPay,
|
|
48
|
+
applePay: digitalWallet.applePayDisplayOptions,
|
|
47
49
|
});
|
|
48
50
|
} else {
|
|
49
51
|
mountApplePayButton();
|
|
@@ -75,4 +77,4 @@ export default function mountApplePay({
|
|
|
75
77
|
Rebilly.on('error', error => {
|
|
76
78
|
console.error(error)
|
|
77
79
|
});
|
|
78
|
-
}
|
|
80
|
+
}
|
|
@@ -33,8 +33,8 @@ function displayBrands({summary, method}) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const {brands} = method;
|
|
36
|
-
summary.insertAdjacentHTML(
|
|
37
|
-
'
|
|
36
|
+
summary.querySelector('.rebilly-instruments-accordion-title').insertAdjacentHTML(
|
|
37
|
+
'afterend',
|
|
38
38
|
`<div class="rebilly-instruments-accordion-brands">${(() => {
|
|
39
39
|
if (brands.length >= 4) {
|
|
40
40
|
const truncatedBrands = brands.slice(0, 3);
|
|
@@ -61,15 +61,16 @@ export function MountMethods({
|
|
|
61
61
|
state.options._computed || 'https://www.example.com';
|
|
62
62
|
|
|
63
63
|
const selector = `rebilly-instruments-${methodId}`;
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const isPopup = [
|
|
65
|
+
'payment-card'
|
|
66
|
+
].includes(methodId) && state.options.paymentInstruments[methodType]?.popup;
|
|
67
67
|
const model = {
|
|
68
68
|
options: state.options,
|
|
69
69
|
mainStyle: state.mainStyle,
|
|
70
70
|
plans: state.data.plans,
|
|
71
71
|
products: state.data.products,
|
|
72
|
-
method
|
|
72
|
+
method,
|
|
73
|
+
readyToPay: state.data.readyToPay,
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
if (isAccordion) {
|
|
@@ -77,9 +78,9 @@ export function MountMethods({
|
|
|
77
78
|
'beforeend',
|
|
78
79
|
`<details class="rebilly-instruments-accordion for-${methodId}">
|
|
79
80
|
<summary class="rebilly-instruments-accordion-summary">
|
|
80
|
-
<span class="rebilly-instruments-accordion-summary-radio"></span>
|
|
81
81
|
<img class="rebilly-instruments-accordion-${method.method}-img" src="${method.metadata.logo}" alt="${method.method}"/>
|
|
82
82
|
<span class="rebilly-instruments-accordion-title" data-rebilly-i18n="paymentMethods.${method.method}">${method.metadata.name}</span>
|
|
83
|
+
<span class="rebilly-instruments-accordion-summary-checkmark"></span>
|
|
83
84
|
</summary>
|
|
84
85
|
<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>
|
|
85
86
|
</details>`
|
|
@@ -91,23 +92,8 @@ export function MountMethods({
|
|
|
91
92
|
const summary = document.querySelector(`.for-${methodId} > .rebilly-instruments-accordion-summary`);
|
|
92
93
|
displayBrands({summary, method});
|
|
93
94
|
}
|
|
94
|
-
|
|
95
95
|
state.loader.stopLoading({ id: method.method });
|
|
96
|
-
METHODS_CONTAINER.insertAdjacentHTML(
|
|
97
|
-
'beforeend',
|
|
98
|
-
`<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`
|
|
99
|
-
);
|
|
100
|
-
const container = document.querySelector(`#${selector}`);
|
|
101
96
|
|
|
102
|
-
state.loader.stopLoading({ id: method.method });
|
|
103
|
-
mountInline(state, {
|
|
104
|
-
methodId,
|
|
105
|
-
paymentMethodsUrl,
|
|
106
|
-
container,
|
|
107
|
-
model,
|
|
108
|
-
method
|
|
109
|
-
});
|
|
110
|
-
} else if (isiFrame) {
|
|
111
97
|
METHODS_CONTAINER.insertAdjacentHTML(
|
|
112
98
|
'beforeend',
|
|
113
99
|
`<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`
|
|
@@ -122,7 +108,7 @@ export function MountMethods({
|
|
|
122
108
|
model,
|
|
123
109
|
method
|
|
124
110
|
});
|
|
125
|
-
} else {
|
|
111
|
+
} else if (isPopup) {
|
|
126
112
|
METHODS_CONTAINER.insertAdjacentHTML(
|
|
127
113
|
'beforeend',
|
|
128
114
|
`<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`
|
|
@@ -135,8 +121,8 @@ export function MountMethods({
|
|
|
135
121
|
method.method
|
|
136
122
|
}">${camelCase(method.method)}</button>`
|
|
137
123
|
);
|
|
138
|
-
const
|
|
139
|
-
|
|
124
|
+
const button = document.querySelector(`.${selector}`);
|
|
125
|
+
button.addEventListener('click', async () => {
|
|
140
126
|
const iframe = await mountModal({
|
|
141
127
|
state,
|
|
142
128
|
name: methodId,
|
|
@@ -145,8 +131,22 @@ export function MountMethods({
|
|
|
145
131
|
});
|
|
146
132
|
state.iframeComponents.push(iframe);
|
|
147
133
|
});
|
|
148
|
-
|
|
134
|
+
} else {
|
|
135
|
+
METHODS_CONTAINER.insertAdjacentHTML(
|
|
136
|
+
'beforeend',
|
|
137
|
+
`<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`
|
|
138
|
+
);
|
|
139
|
+
const container = document.querySelector(`#${selector}`);
|
|
140
|
+
|
|
141
|
+
mountInline(state, {
|
|
142
|
+
methodId,
|
|
143
|
+
paymentMethodsUrl,
|
|
144
|
+
container,
|
|
145
|
+
model,
|
|
146
|
+
method
|
|
147
|
+
});
|
|
149
148
|
}
|
|
149
|
+
state.loader.stopLoading({ id: method.method });
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
if (isAccordion) {
|
|
@@ -154,7 +154,7 @@ export function MountMethods({
|
|
|
154
154
|
const details = document.querySelectorAll('.rebilly-instruments-accordion');
|
|
155
155
|
// Add the onclick listeners.
|
|
156
156
|
details.forEach((targetDetail) => {
|
|
157
|
-
targetDetail.addEventListener('click', () => {
|
|
157
|
+
targetDetail.querySelector('summary').addEventListener('click', () => {
|
|
158
158
|
// Close all the accordion that are not targetDetail.
|
|
159
159
|
details.forEach((detail) => {
|
|
160
160
|
detail.removeAttribute('open');
|
|
@@ -8,7 +8,18 @@ import ProductModel from '@/storefront/models/product-model';
|
|
|
8
8
|
import SummaryModel from '@/storefront/models/summary-model';
|
|
9
9
|
import InvoiceModel from '@/storefront/models/invoice-model';
|
|
10
10
|
import merge from 'lodash.merge';
|
|
11
|
-
import { DataInstance } from '
|
|
11
|
+
import { DataInstance } from 'src/functions/mount/fetch-data';
|
|
12
|
+
import { sleep } from 'src/utils';
|
|
13
|
+
import setupFramepay from 'src/functions/mount/setup-framepay';
|
|
14
|
+
|
|
15
|
+
export const setupFramepayMock = async () => {
|
|
16
|
+
/*
|
|
17
|
+
* onload() is never called in JSDOM context but we want to test the rest of the setupFramepay code,
|
|
18
|
+
* so we run it asynchonously and wait for 10 ms
|
|
19
|
+
*/
|
|
20
|
+
setupFramepay()
|
|
21
|
+
await sleep(10);
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
export async function RenderMockRebillyInstruments(options = {}) {
|
|
14
25
|
const testInvoice = new InvoiceModel({
|
|
@@ -34,14 +45,11 @@ export async function RenderMockRebillyInstruments(options = {}) {
|
|
|
34
45
|
const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
|
|
35
46
|
|
|
36
47
|
when(get(`${storefrontURL}/invoices/*`)).thenReturn(
|
|
37
|
-
(() =>
|
|
38
|
-
return ok(testInvoice);
|
|
39
|
-
})()
|
|
48
|
+
(() => ok(testInvoice))()
|
|
40
49
|
);
|
|
41
50
|
|
|
42
51
|
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
43
|
-
(() =>
|
|
44
|
-
return ok([
|
|
52
|
+
(() => ok([
|
|
45
53
|
{
|
|
46
54
|
method: 'payment-card',
|
|
47
55
|
feature: {
|
|
@@ -52,26 +60,19 @@ export async function RenderMockRebillyInstruments(options = {}) {
|
|
|
52
60
|
brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
|
|
53
61
|
filters: []
|
|
54
62
|
}
|
|
55
|
-
])
|
|
56
|
-
})()
|
|
63
|
+
]))()
|
|
57
64
|
);
|
|
58
65
|
|
|
59
66
|
when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
|
|
60
|
-
(() =>
|
|
61
|
-
return ok(testSummary);
|
|
62
|
-
})()
|
|
67
|
+
(() => ok(testSummary))()
|
|
63
68
|
);
|
|
64
69
|
|
|
65
70
|
when(get(`${storefrontURL}/plans`)).thenReturn(
|
|
66
|
-
(() =>
|
|
67
|
-
return ok([testPlan]);
|
|
68
|
-
})()
|
|
71
|
+
(() => ok([testPlan]))()
|
|
69
72
|
);
|
|
70
73
|
|
|
71
74
|
when(get(`${storefrontURL}/products`)).thenReturn(
|
|
72
|
-
(() =>
|
|
73
|
-
return ok([testProduct]);
|
|
74
|
-
})()
|
|
75
|
+
(() => ok([testProduct]))()
|
|
75
76
|
);
|
|
76
77
|
|
|
77
78
|
const defaultOptions = {
|
|
@@ -111,7 +112,10 @@ export async function RenderMockRebillyInstruments(options = {}) {
|
|
|
111
112
|
<div class="${mergedOptions.summary.replace('.', '')}"></div>
|
|
112
113
|
`;
|
|
113
114
|
|
|
114
|
-
await rebillyInstruments.mount(
|
|
115
|
+
await rebillyInstruments.mount({
|
|
116
|
+
setupFramepay: setupFramepayMock,
|
|
117
|
+
...mergedOptions,
|
|
118
|
+
});
|
|
115
119
|
|
|
116
120
|
rebillyInstruments.mock = {
|
|
117
121
|
data: (data) => {
|