Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions _dev/js/front/src/components/common/smart-button.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import { BaseComponent } from '../../core/dependency-injection/base.component';
import {ModalComponent} from "./modal.component";


/**
* @typedef SmartButtonComponentProps
Expand All @@ -32,7 +34,8 @@ export class SmartButtonComponent extends BaseComponent {
static Inject = {
config: 'PsCheckoutConfig',
payPalService: 'PayPalService',
psCheckoutApi: 'PsCheckoutApi'
psCheckoutApi: 'PsCheckoutApi',
$: '$'
};

created() {
Expand All @@ -44,6 +47,24 @@ export class SmartButtonComponent extends BaseComponent {
this.data.conditions = this.app.root.children.conditionsCheckbox;
this.data.loader = this.app.root.children.loader;
this.data.notification = this.app.root.children.notification;
this.data.cancelModal = null;
}

showCancelOrderModal(onConfirm) {
const modalContent = document.createElement('p');
modalContent.innerText = this.$('checkout.payment.cancel.modal.content');

this.data.cancelModal = new ModalComponent(this.app, {
header: this.$('checkout.payment.cancel.modal.header'),
content: modalContent,
confirmText: this.$('checkout.payment.cancel.modal.ok'),
cancelText: this.$('checkout.payment.cancel.modal.cancel'),
cancelType: 'danger',
onCancel: (() => {this.data.cancelModal.hide()}),
onConfirm: (() => {onConfirm()})
}).render();

this.data.cancelModal.show();
}

renderPayPalButton() {
Expand Down Expand Up @@ -141,19 +162,21 @@ export class SmartButtonComponent extends BaseComponent {
},
onCancel: (data) => {
this.data.loader.hide();
this.data.notification.showCanceled();
// this.data.notification.showCanceled();

return this.psCheckoutApi
.postCancelOrder({
...data,
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active,
reason: 'checkout_cancelled'
})
.catch((error) => {
this.data.loader.hide();
this.data.notification.showError(error.message);
});
this.showCancelOrderModal(() => {
this.psCheckoutApi
.postCancelOrder({
...data,
fundingSource: this.data.name,
isExpressCheckout: this.config.expressCheckout.active,
reason: 'checkout_cancelled'
})
.catch((error) => {
this.data.loader.hide();
this.data.notification.showError(error.message);
});
});
},
createOrder: (data) => {
return this.psCheckoutApi
Expand Down
4 changes: 4 additions & 0 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@ public function hookActionFrontControllerSetMedia()
'checkout.payment.token.delete.modal.header' => $this->l('Delete this payment method?'),
'checkout.payment.token.delete.modal.content' => $this->l('The following payment method will be deleted from your account:'),
'checkout.payment.token.delete.modal.confirm-button' => $this->l('Delete payment method'),
'checkout.payment.cancel.modal.header' => $this->l('Payment cancel'),
'checkout.payment.cancel.modal.content' => $this->l('Do you want to cancel your payment?'),
'checkout.payment.cancel.modal.cancel' => $this->l('No, I want to continue with the payment process'),
'checkout.payment.cancel.modal.ok' => $this->l('Yes'),
],
]);

Expand Down