Skip to content

Commit

Permalink
Merge pull request #1226 from PrestaShopCorp/release/v7.3.6.3
Browse files Browse the repository at this point in the history
Release v7.3.6.3
  • Loading branch information
Matt75 committed Apr 12, 2024
2 parents 35e37e5 + b8dd91f commit 0266814
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 261 deletions.
22 changes: 11 additions & 11 deletions _dev/js/front/src/components/1_7/conditions-checkbox.component.js
Expand Up @@ -24,25 +24,25 @@ export class ConditionsCheckboxComponent extends BaseComponent {
};

created() {
this.conditionsCheckboxes = this.querySelectorService.getConditionsCheckboxes();
this.conditionsCheckboxes =
this.querySelectorService.getConditionsCheckboxes();
}

isActive() {
return this.conditionsCheckboxes.length > 0;
return this.conditionsCheckboxes?.length > 0;
}

isChecked() {
return this.isActive()
? this.conditionsCheckboxes
.map(({ checked }) => checked)
.filter((value) => !value).length === 0
: true;
if (this.isActive()) {
return this.conditionsCheckboxes?.every(({ checked }) => checked);
}

return true;
}

onChange(listener) {
this.isActive() &&
this.conditionsCheckboxes.forEach((checkbox) =>
checkbox.addEventListener('change', () => listener())
);
this.conditionsCheckboxes?.forEach((checkbox) =>
checkbox.addEventListener('change', listener)
);
}
}
188 changes: 5 additions & 183 deletions _dev/js/front/src/service/paypal.service.js
Expand Up @@ -75,13 +75,6 @@

import { BaseClass } from '../core/dependency-injection/base.class';

/**
* @typedef PaypalHostedFieldsEvents
* @type {*}
*
* @property {function} createOrder
*/

export class PayPalService extends BaseClass {
static Inject = {
configPayPal: 'PayPalSdkConfig',
Expand Down Expand Up @@ -142,162 +135,6 @@ export class PayPalService extends BaseClass {
return {};
}

/**
* @param {*} fieldSelectors
* @param {string} fieldSelectors.number
* @param {string} fieldSelectors.cvv
* @param {string} fieldSelectors.expirationDate
* @param {PaypalHostedFieldsEvents} events
* @returns {*}
*/
getHostedFields(fieldSelectors, events) {
const style = {
...{
input: {
'font-size': '17px',
'font-family': 'helvetica, tahoma, calibri, sans-serif',
color: '#3a3a3a'
},
':focus': {
color: 'black'
}
},
...(this.configPayPal.hostedFieldsCustomization || {}),
...(window.ps_checkout.hostedFieldsCustomization || {})
};

return this.sdk.HostedFields.render({
styles: style,
fields: {
number: {
selector: fieldSelectors.number,
placeholder: this.$('paypal.hosted-fields.placeholder.card-number')
},
cvv: {
selector: fieldSelectors.cvv,
placeholder: this.$('paypal.hosted-fields.placeholder.cvv')
},
expirationDate: {
selector: fieldSelectors.expirationDate,
placeholder: this.$(
'paypal.hosted-fields.placeholder.expiration-date'
)
}
},
...events
})
.then((hostedFields) => {
const numberField = document.querySelector(fieldSelectors.number);
const cvvField = document.querySelector(fieldSelectors.cvv);
const expirationDateField = document.querySelector(
fieldSelectors.expirationDate
);

const numberLabel = document.querySelector(
`label[for="${numberField.id}"]`
);
const cvvLabel = document.querySelector(`label[for="${cvvField.id}"]`);
const expirationDateLabel = document.querySelector(
`label[for="${expirationDateField.id}"]`
);

numberLabel.innerHTML = this.$(
'paypal.hosted-fields.label.card-number'
);
cvvLabel.innerHTML = this.$('paypal.hosted-fields.label.cvv');
expirationDateLabel.innerHTML = this.$(
'paypal.hosted-fields.label.expiration-date'
);

return hostedFields;
})
.then((hostedFields) => {
hostedFields.on('focus', (event) => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsFocus', {
detail: { ps_checkout: window.ps_checkout, event: event }
})
);
});
hostedFields.on('blur', (event) => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsBlur', {
detail: { ps_checkout: window.ps_checkout, event: event }
})
);
});
hostedFields.on('empty', (event) => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsEmpty', {
detail: { ps_checkout: window.ps_checkout, event: event }
})
);
});
hostedFields.on('notEmpty', (event) => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsNotEmpty', {
detail: { ps_checkout: window.ps_checkout, event: event }
})
);
});
hostedFields.on('validityChange', (event) => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsValidityChange', {
detail: { ps_checkout: window.ps_checkout, event: event }
})
);
});
hostedFields.on('inputSubmitRequest', () => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsInputSubmitRequest', {
detail: { ps_checkout: window.ps_checkout }
})
);
});
hostedFields.on('cardTypeChange', (event) => {
window.ps_checkout.events.dispatchEvent(
new CustomEvent('hostedFieldsCardTypeChange', {
detail: { ps_checkout: window.ps_checkout, event: event }
})
);

// Change card bg depending on card type
if (event.cards.length === 1) {
document.querySelector('.default-credit-card').style.display =
'none';

const cardImage = document.getElementById('card-image');
cardImage.className = '';
cardImage.classList.add(event.cards[0].type);

document.querySelector('header').classList.add('header-slide');

// Change the CVV length for AmericanExpress cards
if (event.cards[0].code.size === 4) {
hostedFields.setAttribute({
field: 'cvv',
attribute: 'placeholder',
value: 'XXXX'
});
}
} else {
document.querySelector('.default-credit-card').style.display =
'block';
const cardImage = document.getElementById('card-image');
cardImage.className = '';

hostedFields.setAttribute({
field: 'cvv',
attribute: 'placeholder',
value: 'XXX'
});
}
});

return hostedFields;
});
}

/**
* @param {*} fieldSelectors
* @param {string} fieldSelectors.name
Expand Down Expand Up @@ -325,17 +162,6 @@ export class PayPalService extends BaseClass {
placeholder: this.$('paypal.hosted-fields.placeholder.cvv')
});

// await Promise.all(
// [
// cardNameField.render(nameField),
// cardNumberField.render(numberField),
// cardCvvField.render(cvvField),
// cardExpiryField.render(expirationDateField)
// ]
// ).catch(e => {
// return console.error("Failed to render CardFields", e);
// }) ;

try {
await numberField.render(fieldSelectors.number);
await expiryField.render(fieldSelectors.expiry);
Expand Down Expand Up @@ -374,17 +200,15 @@ export class PayPalService extends BaseClass {
this.eligibleFundingSources = (
this.configPrestaShop.fundingSourcesSorted || paypalFundingSources
)
.filter(
(fundingSource) => paypalFundingSources.indexOf(fundingSource) >= 0
)
.filter((fundingSource) => paypalFundingSources.includes(fundingSource))
.map((fundingSource) => ({
name: fundingSource,
mark: this.sdk.Marks({ fundingSource })
}))
.filter((fundingSource) => {
if (
fundingSource.name === 'card' &&
this.configPrestaShop.hostedFieldsEnabled &&
this.isCardFieldsEnabled() &&
!this.isCardFieldsEligible()
) {
console.warn(
Expand All @@ -404,8 +228,8 @@ export class PayPalService extends BaseClass {
return this.getEligibleFundingSources().contains(fundingSource);
}

isHostedFieldsEligible() {
return this.sdk.HostedFields && this.sdk.HostedFields.isEligible();
isCardFieldsEnabled() {
return this.sdk.CardFields && this.configPrestaShop.hostedFieldsEnabled;
}

isCardFieldsEligible() {
Expand Down Expand Up @@ -477,9 +301,7 @@ export class PayPalService extends BaseClass {
}

/**
* @param {string} placement
* @param {string} amount
* @param {PaypalPayLaterOfferEvents} events
* @returns {object}
*/
getPaymentFieldsCustomizationStyle() {
return {
Expand Down

0 comments on commit 0266814

Please sign in to comment.