Skip to content

Commit

Permalink
Fixes for iframe event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Apr 2, 2024
1 parent ce981d4 commit cc98a5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
41 changes: 18 additions & 23 deletions _dev/js/front/src/components/common/payment-token.component.js
Expand Up @@ -58,19 +58,8 @@ export class PaymentTokenComponent extends BaseComponent {
this.data.modal = null;
this.data.iframe = null;

window.document.addEventListener('3DS-success', this.validateOrder)
window.document.addEventListener('3DS-close', (event) => {this.data.iframe.hide();})
}

validateOrder(e) {
console.log(e);
this.data.iframe.hide();
// this.psCheckoutApi.postValidateOrder(
// {
// fundingSource: this.getVaultFormData().fundingSource,
// orderID: this.data.orderId
// }
// ).catch((error) => this.handleError(error));
window.document.addEventListener('3DS-success', (e) => this.validateOrder(), false);
window.document.addEventListener('3DS-close', (e) => this.hideIframe(), false);
}

showModal() {
Expand Down Expand Up @@ -98,8 +87,7 @@ export class PaymentTokenComponent extends BaseComponent {

showIframe() {
const confirmationUrl = new URL(this.config.paymentUrl);
// confirmationUrl.searchParams.append('orderID', this.data.orderId);
confirmationUrl.searchParams.append('orderID', '4H913400R2970140U');
confirmationUrl.searchParams.append('orderID', this.data.orderId);

if (!this.data.iframe) {
this.data.iframe = new IframeComponent(this.app, {
Expand All @@ -111,6 +99,10 @@ export class PaymentTokenComponent extends BaseComponent {
this.data.iframe.show();
}

hideIframe() {
this.data.iframe.hide();
}

onDeleteConfirm() {
const vaultId = this.getVaultFormData().vaultId;
this.psCheckoutApi.postDeleteVaultedToken({vaultId}).then(() => {
Expand Down Expand Up @@ -171,15 +163,19 @@ export class PaymentTokenComponent extends BaseComponent {
this.psCheckoutApi.postCreateOrder(this.getVaultFormData())
.then((data) => {
this.data.orderId = data;
this.redirectToPaymentPage();
this.showIframe();
})
.catch((error) => this.handleError(error));
}

redirectToPaymentPage() {
const confirmationUrl = new URL(this.config.paymentUrl);
confirmationUrl.searchParams.append('orderID', this.data.orderId);
window.location.href = confirmationUrl.toString();
validateOrder() {
this.hideIframe();
this.psCheckoutApi.postValidateOrder(
{
fundingSource: this.getVaultFormData().fundingSource,
orderID: this.data.orderId
}
).catch((error) => this.handleError(error));
}

renderButton() {
Expand All @@ -202,11 +198,10 @@ export class PaymentTokenComponent extends BaseComponent {
this.data.HTMLElementButton.addEventListener('click', (event) => {
event.preventDefault();

// this.data.loader.show();
this.data.loader.show();
this.data.HTMLElementButton.setAttribute('disabled', '');

this.showIframe();
// this.createOrder();
this.createOrder();
});
}

Expand Down
9 changes: 4 additions & 5 deletions controllers/front/payment.php
Expand Up @@ -99,10 +99,9 @@ public function postProcess()
throw new Exception('PayPal order does not belong to this customer');
}

// $payPalOrderFromCache = $payPalOrderProvider->getById($payPalOrder->getId()->getValue());
$payPalOrderFromCache = [
'status' => 'TEST'
];
$payPalOrderFromCache = $payPalOrderProvider->getById($payPalOrder->getId()->getValue());
$payPalOrderFromCache = ['status' => 'TEST'];

if ($payPalOrderFromCache['status'] === 'COMPLETED') {

Check failure on line 105 in controllers/front/payment.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Strict comparison using === between 'TEST' and 'COMPLETED' will always evaluate to false.

Check failure on line 105 in controllers/front/payment.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Strict comparison using === between 'TEST' and 'COMPLETED' will always evaluate to false.
$capture = $payPalOrderFromCache['purchase_units'][0]['payments']['captures'][0];

Check failure on line 106 in controllers/front/payment.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Offset 'purchase_units' does not exist on array('status' => *NEVER*).

Check failure on line 106 in controllers/front/payment.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Offset 'purchase_units' does not exist on array('status' => *NEVER*).
if ($capture['status'] === 'COMPLETED') {
Expand Down Expand Up @@ -141,7 +140,7 @@ public function postProcess()
} catch (Exception $exception) {
$this->context->smarty->assign('error', $exception->getMessage());
}
// $this->context->smarty->assign('success3DS', true);
$this->context->smarty->assign('success3DS', true);
}

/**
Expand Down
Expand Up @@ -115,7 +115,7 @@ public function handle(CreatePayPalOrderCommand $command)
$builder = new OrderPayloadBuilder($cartPresenter);

$cart = new \Cart($command->getCartId()->getValue());
$payPalCustomerId = $this->payPalCustomerRepository->findPayPalCustomerIdByCustomerId(new CustomerId($cart->id_customer));
$payPalCustomerId = $this->payPalCustomerRepository->findPayPalCustomerIdByCustomerId(new CustomerId((int) $cart->id_customer));

$customerIntent = [];

Expand Down

0 comments on commit cc98a5e

Please sign in to comment.