Skip to content

Commit

Permalink
Refactor and fix Guzzle5 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Feb 28, 2024
1 parent b54c149 commit 706115c
Show file tree
Hide file tree
Showing 54 changed files with 3,306 additions and 562 deletions.
39 changes: 25 additions & 14 deletions _dev/js/front/src/components/1_6/payment-options.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class PaymentOptionsComponent extends BaseComponent {
}

renderPaymentOptionListener() {
const HTMLListenerElements = this.children.paymentOptions.map((paymentOption) => {
const HTMLListenerElements = this.children.paymentOptions.map(
(paymentOption) => {
const HTMLElement = paymentOption.data.HTMLElementContainer;
const [button, form] = Array.prototype.slice.call(
HTMLElement.querySelectorAll('.payment_module')
Expand All @@ -74,21 +75,28 @@ export class PaymentOptionsComponent extends BaseComponent {
this.data.notification.hideError();
});

if (this.config.expressCheckout.active && (('ps_checkout-' + this.payPalService.getFundingSource()) !== HTMLListenerElements[index].button.dataset.moduleName)) {
this.psCheckoutApi.postCancelOrder(
{
if (
this.config.expressCheckout.active &&
'ps_checkout-' + this.payPalService.getFundingSource() !==
HTMLListenerElements[index].button.dataset.moduleName
) {
this.psCheckoutApi
.postCancelOrder({
orderID: this.payPalService.getOrderId(),
fundingSource: this.payPalService.getFundingSource(),
isExpressCheckout: true
}
).then(() => {
this.config.expressCheckout.active = false;
isExpressCheckout: true,
reason: 'payment_option_changed'
})
.then(() => {
this.config.expressCheckout.active = false;

const expressCheckoutContainer = document.querySelector('#ps_checkout-express-checkout-banner');
if (expressCheckoutContainer) {
expressCheckoutContainer.style.display = 'none';
}
});
const expressCheckoutContainer = document.querySelector(
'#ps_checkout-express-checkout-banner'
);
if (expressCheckoutContainer) {
expressCheckoutContainer.style.display = 'none';
}
});
}

HTMLListenerElements[index].button.classList.add('open');
Expand All @@ -100,7 +108,10 @@ export class PaymentOptionsComponent extends BaseComponent {

if (this.config.expressCheckout.active) {
HTMLListenerElements.forEach(({ button, form }) => {
if (button.dataset.moduleName === ('ps_checkout-' + this.payPalService.getFundingSource())) {
if (
button.dataset.moduleName ===
'ps_checkout-' + this.payPalService.getFundingSource()
) {
button.classList.add('open');
button.classList.remove('closed');
form.classList.add('open');
Expand Down
36 changes: 23 additions & 13 deletions _dev/js/front/src/components/1_7/payment-options.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export class PaymentOptionsComponent extends BaseComponent {
`[data-module-name^="ps_checkout-${fundingSource.name}"]`
);

if (this.config.expressCheckout.active && this.payPalService.getFundingSource() === fundingSource.name) {
if (
this.config.expressCheckout.active &&
this.payPalService.getFundingSource() === fundingSource.name
) {
HTMLElement.click();
}

Expand All @@ -63,21 +66,28 @@ export class PaymentOptionsComponent extends BaseComponent {
this.data.notification.hideCancelled();
this.data.notification.hideError();

if (this.config.expressCheckout.active && (('ps_checkout-' + this.payPalService.getFundingSource()) !== radio.dataset.moduleName)) {
this.psCheckoutApi.postCancelOrder(
{
if (
this.config.expressCheckout.active &&
'ps_checkout-' + this.payPalService.getFundingSource() !==
radio.dataset.moduleName
) {
this.psCheckoutApi
.postCancelOrder({
orderID: this.payPalService.getOrderId(),
fundingSource: this.payPalService.getFundingSource(),
isExpressCheckout: true
}
).then(() => {
this.config.expressCheckout.active = false;
isExpressCheckout: true,
reason: 'payment_option_changed'
})
.then(() => {
this.config.expressCheckout.active = false;

const expressCheckoutContainer = document.querySelector('#ps_checkout-express-checkout-banner');
if (expressCheckoutContainer) {
expressCheckoutContainer.style.display = 'none';
}
});
const expressCheckoutContainer = document.querySelector(
'#ps_checkout-express-checkout-banner'
);
if (expressCheckoutContainer) {
expressCheckoutContainer.style.display = 'none';
}
});
}
});
});
Expand Down
9 changes: 9 additions & 0 deletions _dev/js/front/src/components/common/card-fields.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ export class CardFieldsComponent extends BaseComponent {
let message = error.message || this.$('checkout.form.error.label');
this.data.notification.showError(message);
this.data.HTMLElementButton.removeAttribute('disabled');

return this.psCheckoutApi
.postCancelOrder({
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active,
reason: 'card_fields_error',
error: error instanceof Error ? error.message : error
})
.catch((error) => console.error(error));
},
inputEvents: {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ExpressCheckoutButtonComponent extends BaseComponent {
...data,
fundingSource: this.props.fundingSource,
isExpressCheckout: true,
orderID: this.payPalService.getOrderId(),
orderID: this.payPalService.getOrderId()
},
actions
)
Expand All @@ -48,7 +48,16 @@ export class ExpressCheckoutButtonComponent extends BaseComponent {
}

onError(error) {
return console.error(error);
console.error(error);

return this.psCheckoutApi
.postCancelOrder({
fundingSource: this.props.fundingSource,
isExpressCheckout: true,
reason: 'express_checkout_error',
error: error instanceof Error ? error.message : error
})
.catch((error) => console.error(error));
}

onApprove(data, actions) {
Expand All @@ -66,7 +75,8 @@ export class ExpressCheckoutButtonComponent extends BaseComponent {
return this.psCheckoutApi.postCancelOrder({
...data,
fundingSource: this.props.fundingSource,
isExpressCheckout: true
isExpressCheckout: true,
reason: 'express_checkout_cancelled'
});
}

Expand Down
51 changes: 35 additions & 16 deletions _dev/js/front/src/components/common/smart-button.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,63 +91,76 @@ export class SmartButtonComponent extends BaseComponent {
}

return this.psCheckoutApi
.postCheckCartOrder({
.postCheckCartOrder(
{
...data,
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active,
orderID: this.payPalService.getOrderId(),
orderID: this.payPalService.getOrderId()
},
actions
)
.catch(error => {
.catch((error) => {
this.data.loader.hide();
this.data.notification.showError(error.message);
return actions.reject();
});
},
onError: error => {
onError: (error) => {
let errorMessage = this.handleError(error);
console.error(error);
this.data.loader.hide();
this.data.notification.showError(this.handleError(error));
this.data.notification.showError(errorMessage);

return this.psCheckoutApi
.postCancelOrder({
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active,
reason: 'checkout_error',
error: errorMessage
})
.catch((error) => console.error(error));
},
onApprove: (data, actions) => {
this.data.loader.show();
return this.psCheckoutApi
.postValidateOrder({
.postValidateOrder(
{
...data,
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active
},
actions
)
.catch(error => {
.catch((error) => {
this.data.loader.hide();
this.data.notification.showError(error.message);
});
},
onCancel: data => {
onCancel: (data) => {
this.data.loader.hide();
this.data.notification.showCanceled();

return this.psCheckoutApi
.postCancelOrder({
...data,
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active
isExpressCheckout: this.config.expressCheckout.active,
reason: 'checkout_cancelled'
})
.catch(error => {
.catch((error) => {
this.data.loader.hide();
this.data.notification.showError(error.message);
});
},
createOrder: data => {
createOrder: (data) => {
return this.psCheckoutApi
.postCreateOrder({
...data,
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active
})
.catch(error => {
.catch((error) => {
this.data.loader.hide();
this.data.notification.showError(
`${error.message} ${error.name}`
Expand All @@ -165,10 +178,16 @@ export class SmartButtonComponent extends BaseComponent {
if (error.message) {
errorMessage = error.message;

if (error.message.includes('CURRENCY_NOT_SUPPORTED_BY_PAYMENT_SOURCE')) {
errorMessage = 'Provided currency is not supported by the selected payment method.';
} else if (error.message.includes('COUNTRY_NOT_SUPPORTED_BY_PAYMENT_SOURCE')) {
errorMessage = 'Provided country is not supported by the selected payment method.';
if (
error.message.includes('CURRENCY_NOT_SUPPORTED_BY_PAYMENT_SOURCE')
) {
errorMessage =
'Provided currency is not supported by the selected payment method.';
} else if (
error.message.includes('COUNTRY_NOT_SUPPORTED_BY_PAYMENT_SOURCE')
) {
errorMessage =
'Provided country is not supported by the selected payment method.';
}
}
}
Expand Down
Loading

0 comments on commit 706115c

Please sign in to comment.