Skip to content

Commit

Permalink
Merge pull request #1196 from PrestaShopCorp/release/v7.3.6.0
Browse files Browse the repository at this point in the history
Release/v7.3.6.0
  • Loading branch information
Matt75 authored Mar 5, 2024
2 parents c700a1f + ac16006 commit 8cad7cf
Show file tree
Hide file tree
Showing 148 changed files with 16,574 additions and 18,677 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $config
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('_dev')
->exclude('vendor');

return $config;
24,144 changes: 8,848 additions & 15,296 deletions _dev/js/front/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions _dev/js/front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"webpack-merge": "^5.3.0"
},
"dependencies": {
"@paypal/paypal-js": "^8.0.0",
"@ungap/event-target": "^0.2.2",
"classlist-polyfill": "^1.2.0",
"promise-polyfill": "8.1.3",
Expand Down
75 changes: 19 additions & 56 deletions _dev/js/front/src/api/ps-checkout.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { BaseClass } from '../core/dependency-injection/base.class';

export class PsCheckoutApi extends BaseClass {
static Inject = {
config: 'PsCheckoutConfig'
config: 'PsCheckoutConfig',
$: '$'
};

postCancelOrder(data) {
Expand All @@ -42,11 +43,11 @@ export class PsCheckoutApi extends BaseClass {
return response.json().then((response) => {
throw response.body && response.body.error
? response.body.error
: { message: 'Unknown error' };
: { message: this.$('checkout.form.error.label') };
});
}

throw new Error('Invalid response');
throw new Error(this.$('checkout.form.error.label'));
}
});
}
Expand All @@ -72,14 +73,14 @@ export class PsCheckoutApi extends BaseClass {
return response.json().then((response) => {
throw response.body && response.body.error
? response.body.error
: { message: 'Unknown error' };
: { message: this.$('checkout.form.error.label') };
});
}

return response.json();
}

throw new Error('Invalid response');
throw new Error(this.$('checkout.form.error.label'));
})
.then((data) => {
if (!data) {
Expand Down Expand Up @@ -111,60 +112,22 @@ export class PsCheckoutApi extends BaseClass {
contentType && contentType.indexOf('application/json') !== -1;

if (isJsonResponse) {
if (false === response.ok) {
if (false === response.ok || response.status >= 400) {
return response.json().then((response) => {
throw response.body && response.body.error
? response.body.error
: { message: 'Unknown error' };
: { message: this.$('checkout.form.error.label') };
});
}

return response.json();
}

throw new Error('Invalid response');
throw new Error(this.$('checkout.form.error.label'));
})
.then(({ body: { orderID } }) => orderID);
}

getGetToken() {
return (
fetch(this.config.getTokenUrl, {
method: 'get',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
}
})
.then((response) => {
const contentType = response.headers.get('content-type');
const isJsonResponse =
contentType && contentType.indexOf('application/json') !== -1;

if (isJsonResponse) {
if (false === response.ok) {
return response.json().then((response) => {
throw response.body && response.body.error
? response.body.error
: { message: 'Unknown error' };
});
}

return response.json();
}

throw new Error('Invalid response');
})
.then(({ body: { token } }) => {
window.ps_checkoutPayPalClientToken = token;
return token;
})
// TODO: Handle error
.catch(() => {})
);
}

postValidateOrder(data, actions) {
return fetch(this.config.validateOrderUrl, {
method: 'post',
Expand All @@ -181,18 +144,22 @@ export class PsCheckoutApi extends BaseClass {
contentType && contentType.indexOf('application/json') !== -1;

if (isJsonResponse) {
if (false === response.ok) {
if (false === response.ok || response.status >= 400) {
return response.json().then((response) => {
if (actions?.restart && response.body && 85 === response.body.error.code) {
return actions.restart();
}

throw response.body && response.body.error
? response.body.error
: { message: 'Unknown error' };
: { message: this.$('checkout.form.error.label') };
});
}

return response.json();
}

throw new Error('Invalid response');
throw new Error(this.$('checkout.form.error.label'));
})
.then((response) => {
if (response.body && response.body.id_order) {
Expand All @@ -218,10 +185,6 @@ export class PsCheckoutApi extends BaseClass {

window.location.href = confirmationUrl.toString();
}

if (response.error && 'INSTRUMENT_DECLINED' === response.error) {
return actions.restart();
}
});
}

Expand All @@ -247,11 +210,11 @@ export class PsCheckoutApi extends BaseClass {
contentType && contentType.indexOf('application/json') !== -1;

if (isJsonResponse) {
if (false === response.ok) {
if (false === response.ok || response.status >= 400) {
return response.json().then((response) => {
throw response.body && response.body.error
? response.body.error
: { message: 'Unknown error' };
: { message: this.$('checkout.form.error.label') };
});
}

Expand All @@ -260,7 +223,7 @@ export class PsCheckoutApi extends BaseClass {
).toString();
}

throw new Error('Invalid response');
throw new Error(this.$('checkout.form.error.label'));
})
);
}
Expand Down
18 changes: 6 additions & 12 deletions _dev/js/front/src/components/1_6/express-button-cart.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class ExpressButtonCartComponent extends BaseComponent {
};

created() {
this.buttonReferenceContainer = this.querySelectorService.getExpressCheckoutButtonContainerCart();
this.buttonReferenceContainer =
this.querySelectorService.getExpressCheckoutButtonContainerCart();
}

renderComponent() {
Expand All @@ -50,14 +51,7 @@ export class ExpressButtonCartComponent extends BaseComponent {
this.app,
{
fundingSource: 'paypal',
// TODO: Move this to constant when ExpressCheckoutButton component is created
querySelector: '#ps_checkout-express-button-cart',
createOrder: (data) =>
this.psCheckoutApi.postCreateOrder({
...data,
fundingSource: 'paypal',
isExpressCheckout: true
})
querySelector: '#ps_checkout-express-button-cart'
}
).render();
}
Expand All @@ -67,9 +61,9 @@ export class ExpressButtonCartComponent extends BaseComponent {

this.renderComponent();
this.prestashopService.onUpdatedShoppingCartExtra(() => {
if (null === document.querySelector('#ps_checkout-express-button-cart')) {
this.renderComponent();
}
if (null === document.querySelector('#ps_checkout-express-button-cart')) {
this.renderComponent();
}
});

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class ExpressButtonCheckoutComponent extends BaseComponent {
};

created() {
this.buttonReferenceContainer = this.querySelectorService.getExpressCheckoutButtonContainerCheckout();
this.buttonReferenceContainer =
this.querySelectorService.getExpressCheckoutButtonContainerCheckout();
}

renderTitle() {
Expand All @@ -53,13 +54,7 @@ export class ExpressButtonCheckoutComponent extends BaseComponent {
this.app,
{
fundingSource: 'paypal',
querySelector: '#ps_checkout-express-button-checkout',
createOrder: (data) =>
this.psCheckoutApi.postCreateOrder({
...data,
fundingSource: 'paypal',
isExpressCheckout: true
})
querySelector: '#ps_checkout-express-button-checkout'
}
).render();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class ExpressButtonProductComponent extends BaseComponent {
};

created() {
this.buttonReferenceContainer = this.querySelectorService.getExpressCheckoutButtonContainerProduct();
this.buttonReferenceContainer =
this.querySelectorService.getExpressCheckoutButtonContainerProduct();
}

render() {
Expand All @@ -42,28 +43,23 @@ export class ExpressButtonProductComponent extends BaseComponent {

buttonContainer.append(this.checkoutExpressButton);

const {
id_product,
id_product_attribute,
id_customization,
quantity_wanted
} = this.prestashopService.getProductDetails();

this.children.expressCheckoutButton = new ExpressCheckoutButtonComponent(
this.app,
{
fundingSource: 'paypal',
// TODO: Move this to constant when ExpressCheckoutButton component is created
querySelector: '#ps-checkout-express-button',
createOrder: () => {
const {
id_product,
id_product_attribute,
id_customization,
quantity_wanted
} = this.prestashopService.getProductDetails();

return this.psCheckoutApi.postCreateOrder({
id_product,
id_product_attribute,
id_customization,
quantity_wanted,
fundingSource: 'paypal',
isExpressCheckout: true
});
data: {
id_product,
id_product_attribute,
id_customization,
quantity_wanted
}
}
).render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export class PayLaterButtonCartComponent extends BaseComponent {
querySelectorService: 'QuerySelectorService',
prestashopService: 'PrestashopService',
psCheckoutApi: 'PsCheckoutApi',
payPalService: 'PayPalService',
$: '$'
};

created() {
this.buttonReferenceContainer = this.querySelectorService.getExpressCheckoutButtonContainerCart();
this.buttonReferenceContainer =
this.querySelectorService.getExpressCheckoutButtonContainerCart();
this.data.orderId = this.payPalService.getOrderId();
}

renderComponent() {
Expand All @@ -52,14 +55,7 @@ export class PayLaterButtonCartComponent extends BaseComponent {
this.app,
{
fundingSource: 'paylater',
// TODO: Move this to constant when ExpressCheckoutButton component is created
querySelector: '#ps_checkout-express-button-cart',
createOrder: (data) =>
this.psCheckoutApi.postCreateOrder({
...data,
fundingSource: 'paylater',
isExpressCheckout: true
})
querySelector: '#ps_checkout-express-button-cart'
}
).render();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export class PayLaterButtonCheckoutComponent extends BaseComponent {
querySelectorService: 'QuerySelectorService',
prestashopService: 'PrestashopService',
psCheckoutApi: 'PsCheckoutApi',
payPalService: 'PayPalService',
$: '$'
};

created() {
this.buttonReferenceContainer = this.querySelectorService.getExpressCheckoutButtonContainerCheckout();
this.buttonReferenceContainer =
this.querySelectorService.getExpressCheckoutButtonContainerCheckout();
this.data.orderId = this.payPalService.getOrderId();
}

renderTitle() {
Expand All @@ -55,19 +58,13 @@ export class PayLaterButtonCheckoutComponent extends BaseComponent {
this.app,
{
fundingSource: 'paylater',
querySelector: '#ps_checkout-express-button-checkout',
createOrder: (data) =>
this.psCheckoutApi.postCreateOrder({
...data,
fundingSource: 'paylater',
isExpressCheckout: true
})
querySelector: '#ps_checkout-express-button-checkout'
}
).render();

if (
this.prestashopService.isNativeOnePageCheckoutPage()
&& !document.getElementById('ps_checkout-express-button-checkout')
this.prestashopService.isNativeOnePageCheckoutPage() &&
!document.getElementById('ps_checkout-express-button-checkout')
) {
const separatorText = document.createElement('div');
separatorText.classList.add('ps_checkout-express-separator');
Expand Down
Loading

0 comments on commit 8cad7cf

Please sign in to comment.