2024-03-12 09:23:42 +00:00
|
|
|
import FormFieldGroup from "../Components/FormFieldGroup";
|
2024-03-08 17:41:21 +00:00
|
|
|
|
|
|
|
class CardView {
|
|
|
|
|
2024-03-12 09:23:42 +00:00
|
|
|
constructor(selector, elements, manager) {
|
|
|
|
this.el = elements;
|
2024-03-08 17:41:21 +00:00
|
|
|
this.manager = manager;
|
|
|
|
|
2024-04-10 18:27:21 +01:00
|
|
|
this.group = new FormFieldGroup({
|
2024-03-08 17:41:21 +00:00
|
|
|
baseSelector: '.ppcp-axo-payment-container',
|
|
|
|
contentSelector: selector,
|
|
|
|
template: (data) => {
|
|
|
|
const selectOtherPaymentMethod = () => {
|
|
|
|
if (!this.manager.hideGatewaySelection) {
|
|
|
|
return '';
|
|
|
|
}
|
2024-03-12 09:23:42 +00:00
|
|
|
return `<p style="margin-top: 40px; text-align: center;"><a href="javascript:void(0)" ${this.el.showGatewaySelectionLink.attributes}>Select other payment method</a></p>`;
|
2024-03-08 17:41:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (data.isEmpty()) {
|
|
|
|
return `
|
|
|
|
<div style="margin-bottom: 20px; text-align: center;">
|
|
|
|
${selectOtherPaymentMethod()}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2024-03-14 10:54:15 +00:00
|
|
|
|
|
|
|
const expiry = data.value('expiry').split('-');
|
|
|
|
|
|
|
|
const cardIcons = {
|
2024-05-10 10:51:19 +02:00
|
|
|
'VISA': 'visa-light.svg',
|
|
|
|
'MASTER_CARD': 'mastercard-light.svg',
|
2024-05-14 13:51:20 +02:00
|
|
|
'AMEX': 'amex-light.svg',
|
|
|
|
'DISCOVER': 'discover-light.svg',
|
2024-05-10 10:51:19 +02:00
|
|
|
'DINERS': 'dinersclub-light.svg',
|
|
|
|
'JCB': 'jcb-light.svg',
|
|
|
|
'UNIONPAY': 'unionpay-light.svg',
|
2024-03-14 10:54:15 +00:00
|
|
|
};
|
|
|
|
|
2024-03-08 17:41:21 +00:00
|
|
|
return `
|
|
|
|
<div style="margin-bottom: 20px;">
|
2024-04-30 14:50:38 +02:00
|
|
|
<div class="axo-checkout-header-section">
|
|
|
|
<h3>Card Details</h3>
|
|
|
|
<a href="javascript:void(0)" ${this.el.changeCardLink.attributes}>Edit</a>
|
|
|
|
</div>
|
2024-03-14 10:54:15 +00:00
|
|
|
<div style="border:2px solid #cccccc; border-radius: 10px; padding: 16px 20px; background-color:#f6f6f6">
|
|
|
|
<div style="float: right;">
|
|
|
|
<img
|
|
|
|
class="ppcp-card-icon"
|
|
|
|
title="${data.value('brand')}"
|
2024-05-14 13:51:20 +02:00
|
|
|
src="${window.wc_ppcp_axo.icons_directory}${cardIcons[data.value('brand')]}"
|
2024-03-14 10:54:15 +00:00
|
|
|
alt="${data.value('brand')}"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
<div style="font-family: monospace; font-size: 1rem; margin-top: 10px;">${data.value('lastDigits') ? '**** **** **** ' + data.value('lastDigits'): ''}</div>
|
|
|
|
<div>${expiry[1]}/${expiry[0]}</div>
|
|
|
|
<div style="text-transform: uppercase">${data.value('name')}</div>
|
|
|
|
</div>
|
2024-03-08 17:41:21 +00:00
|
|
|
${selectOtherPaymentMethod()}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
},
|
|
|
|
fields: {
|
|
|
|
brand: {
|
|
|
|
'valuePath': 'card.paymentSource.card.brand',
|
|
|
|
},
|
|
|
|
expiry: {
|
|
|
|
'valuePath': 'card.paymentSource.card.expiry',
|
|
|
|
},
|
|
|
|
lastDigits: {
|
|
|
|
'valuePath': 'card.paymentSource.card.lastDigits',
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
'valuePath': 'card.paymentSource.card.name',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
activate() {
|
2024-04-10 18:27:21 +01:00
|
|
|
this.group.activate();
|
2024-03-08 17:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deactivate() {
|
2024-04-10 18:27:21 +01:00
|
|
|
this.group.deactivate();
|
2024-03-08 17:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
2024-04-10 18:27:21 +01:00
|
|
|
this.group.refresh();
|
2024-03-08 17:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setData(data) {
|
2024-04-10 18:27:21 +01:00
|
|
|
this.group.setData(data);
|
|
|
|
}
|
|
|
|
|
2024-04-15 17:20:02 +01:00
|
|
|
toSubmitData(data) {
|
2024-04-10 18:27:21 +01:00
|
|
|
const name = this.group.dataValue('name');
|
|
|
|
const { firstName, lastName } = this.splitName(name);
|
|
|
|
|
2024-04-17 10:14:27 +01:00
|
|
|
data['billing_first_name'] = firstName;
|
|
|
|
data['billing_last_name'] = lastName ? lastName : firstName;
|
2024-04-10 18:27:21 +01:00
|
|
|
|
2024-04-15 17:20:02 +01:00
|
|
|
return this.group.toSubmitData(data);
|
2024-04-10 18:27:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
splitName(fullName) {
|
|
|
|
let nameParts = fullName.trim().split(' ');
|
|
|
|
let firstName = nameParts[0];
|
|
|
|
let lastName = nameParts.length > 1 ? nameParts[nameParts.length - 1] : '';
|
|
|
|
|
|
|
|
return { firstName, lastName };
|
2024-03-08 17:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CardView;
|