Skip to content

Commit

Permalink
examples - upgrade to bootstrap 5 and remove jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Jun 6, 2024
1 parent 507aabf commit fb4b775
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 150 deletions.
45 changes: 27 additions & 18 deletions docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,28 @@ $renderedForm = ob_get_clean();
</pre>
<script>
$('#result-alert').hide();
document.getElementById('result-alert').style.display = 'none';
let messageReceived = false;
/**
* Bankadan geri websitenize yönlendirme yapıldıktan sonra alınan sonuca göre başarılı/başarısız alert box'u gösterir.
*/
let displayResponse = function (event) {
let alertBox = $('#result-alert');
let alertBox = document.getElementById('result-alert');
let data = JSON.parse(atob(event.data));
$('#result-response').append(JSON.stringify(data, null, '\t'));
let resultResponse = document.getElementById('result-response');
resultResponse.appendChild(document.createTextNode(JSON.stringify(data, null, '\t')));
if (data.status === 'approved') {
alertBox.append('payment successful');
alertBox.addClass('alert-info');
alertBox.appendChild(document.createTextNode('payment successful'));
alertBox.classList.add('alert-info');
} else {
alertBox.addClass('alert-danger');
alertBox.append('payment failed: ' + data.error_message ?? data.md_error_message);
alertBox.classList.add('alert-danger');
alertBox.appendChild(document.createTextNode('payment failed: ' + (data.error_message ?? data.md_error_message)));
}
alertBox.show();
alertBox.style.display = 'block';
}
</script>
Expand All @@ -204,28 +208,33 @@ $renderedForm = ob_get_clean();
window.addEventListener('message', function (event) {
messageReceived = true;
displayResponse(event);
$('#iframe-modal').modal('hide');
let myModal = bootstrap.Modal.getInstance(document.getElementById('iframe-modal'));
myModal.hide();
});
/**
* modal box'ta iframe ile ödeme yöntemi seçilmiş.
* modal box içinde yeni iframe oluşturuyoruz ve iframe içine $renderedForm verisini basıyoruz.
*/
let iframe = document.createElement('iframe');
document.getElementById("iframe-modal-dialog").appendChild(iframe);
$(iframe).height('500px');
$(iframe).width('410px');
document.getElementById("iframe-modal-body").appendChild(iframe);
iframe.style.height = '500px';
iframe.style.width = '410px';
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(`<?= $renderedForm; ?>`);
iframe.contentWindow.document.close();
$('#iframe-modal').modal('show');
let modalElement = document.getElementById('iframe-modal');
let myModal = new bootstrap.Modal(modalElement, {
keyboard: false
})
myModal.show();
$('#iframe-modal').on('hidden.bs.modal', function () {
modalElement.addEventListener('hidden.bs.modal', function () {
if (!messageReceived) {
let alertBox = $('#result-alert');
alertBox.addClass('alert-danger');
alertBox.append('modal box kapatildi');
alertBox.show();
let alertBox = document.getElementById('result-alert');
alertBox.classList.add('alert-danger');
alertBox.appendChild(document.createTextNode('modal box kapatildi'));
alertBox.style.display = 'block';
}
});
</script>
Expand Down
66 changes: 40 additions & 26 deletions examples/_common-codes/3d/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,28 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
</pre>

<script>
$('#result-alert').hide();
document.getElementById('result-alert').style.display = 'none';
let messageReceived = false;

/**
* Bankadan geri websitenize yönlendirme yapıldıktan sonra alınan sonuca göre başarılı/başarısız alert box'u gösterir.
*/
let displayResponse = function (event) {
let alertBox = $('#result-alert');
let alertBox = document.getElementById('result-alert');
let data = JSON.parse(atob(event.data));
$('#result-response').append(JSON.stringify(data, null, '\t'));

let resultResponse = document.getElementById('result-response');
resultResponse.appendChild(document.createTextNode(JSON.stringify(data, null, '\t')));

if (data.status === 'approved') {
alertBox.append('payment successful');
alertBox.addClass('alert-info');
alertBox.appendChild(document.createTextNode('payment successful'));
alertBox.classList.add('alert-info');
} else {
alertBox.addClass('alert-danger');
alertBox.append('payment failed: ' + data.error_message ?? data.md_error_message);
alertBox.classList.add('alert-danger');
alertBox.appendChild(document.createTextNode('payment failed: ' + (data.error_message ?? data.md_error_message)));
}
alertBox.show();

alertBox.style.display = 'block';
}
</script>
<?php endif; ?>
Expand All @@ -287,9 +291,14 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {

<?php if ('by_iframe' === $flowType) : ?>
<div class="modal fade" tabindex="-1" role="dialog" id="iframe-modal" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog" role="document" id="iframe-modal-dialog" style="width: 426px;">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"
style="color: white; opacity: 1;"><span aria-hidden="true">&times;</span></button>
<div class="modal-dialog" role="document" style="width: 426px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="iframe-modal-body">
</div>
</div>
</div>
</div>
<script>
Expand All @@ -302,28 +311,33 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
window.addEventListener('message', function (event) {
messageReceived = true;
displayResponse(event);
$('#iframe-modal').modal('hide');
let myModal = bootstrap.Modal.getInstance(document.getElementById('iframe-modal'));
myModal.hide();
});

/**
* modal box'ta iframe ile ödeme yöntemi seçilmiş.
* modal box içinde yeni iframe oluşturuyoruz ve iframe içine $renderedForm verisini basıyoruz.
*/
let iframe = document.createElement('iframe');
document.getElementById("iframe-modal-dialog").appendChild(iframe);
$(iframe).height('500px');
$(iframe).width('410px');
document.getElementById("iframe-modal-body").appendChild(iframe);
iframe.style.height = '500px';
iframe.style.width = '410px';
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(`<?= $renderedForm; ?>`);
iframe.contentWindow.document.close();
$('#iframe-modal').modal('show');
let modalElement = document.getElementById('iframe-modal');
let myModal = new bootstrap.Modal(modalElement, {
keyboard: false
})
myModal.show();

$('#iframe-modal').on('hidden.bs.modal', function () {
modalElement.addEventListener('hidden.bs.modal', function () {
if (!messageReceived) {
let alertBox = $('#result-alert');
alertBox.addClass('alert-danger');
alertBox.append('modal box kapatildi');
alertBox.show();
let alertBox = document.getElementById('result-alert');
alertBox.classList.add('alert-danger');
alertBox.appendChild(document.createTextNode('modal box kapatildi'));
alertBox.style.display = 'block';
}
});
</script>
Expand Down Expand Up @@ -368,12 +382,12 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
*/
let closeInterval = setInterval(function () {
if (popupWindow.closed && !messageReceived) {
// windows is closed without completing payment
// window is closed without completing payment
clearInterval(closeInterval);
let alertBox = $('#result-alert');
alertBox.addClass('alert-danger');
alertBox.append('popup kapatildi');
alertBox.show();
let alertBox = document.getElementById('result-alert');
alertBox.classList.add('alert-danger');
alertBox.appendChild(document.createTextNode('popup kapatildi'));
alertBox.style.display = 'block';
}
}, 1000);
</script>
Expand Down
4 changes: 3 additions & 1 deletion examples/_common-codes/3d/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// ilgili bankanin _config.php dosyasi load ediyoruz.
// ornegin /examples/finansbank-payfor/3d/_config.php
require '_config.php';

if ($transaction === null) {
$transaction = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH;
}
require '../../_templates/_header.php';

$url = $baseUrl.'form.php';
Expand Down
6 changes: 3 additions & 3 deletions examples/_common-codes/regular/cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

use Mews\Pos\PosInterface;

$templateTitle = 'Refund Order';
$templateTitle = 'Cancel Order';

// ilgili bankanin _config.php dosyasi load ediyoruz.
// ornegin /examples/finansbank-payfor/regular/_config.php
require '_config.php';
$transaction = PosInterface::TX_TYPE_CANCEL;

require '../../_templates/_header.php';

Expand Down Expand Up @@ -80,8 +82,6 @@ function createCancelOrder(string $gatewayClass, array $lastResponse, string $ip
$order = createCancelOrder(get_class($pos), $session->get('last_response'), $ip);
dump($order);

$transaction = PosInterface::TX_TYPE_CANCEL;

try {
$pos->cancel($order);
} catch (Exception $e) {
Expand Down
3 changes: 1 addition & 2 deletions examples/_common-codes/regular/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ilgili bankanin _config.php dosyasi load ediyoruz.
// ornegin /examples/finansbank-payfor/regular/_config.php
require_once '_config.php';
$transaction = \Mews\Pos\PosInterface::TX_TYPE_HISTORY;

require '../../_templates/_header.php';

Expand Down Expand Up @@ -45,8 +46,6 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array
$order = createHistoryOrder(get_class($pos), []);
dump($order);

$transaction = \Mews\Pos\PosInterface::TX_TYPE_HISTORY;

try {
$pos->history($order);
} catch (Exception $e) {
Expand Down
3 changes: 1 addition & 2 deletions examples/_common-codes/regular/order_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ilgili bankanin _config.php dosyasi load ediyoruz.
// ornegin /examples/finansbank-payfor/regular/_config.php
require_once '_config.php';
$transaction = \Mews\Pos\PosInterface::TX_TYPE_ORDER_HISTORY;

require '../../_templates/_header.php';

Expand Down Expand Up @@ -64,8 +65,6 @@ function createOrderHistoryOrder(string $gatewayClass, array $lastResponse): arr
$order = createOrderHistoryOrder(get_class($pos), $lastResponse);
dump($order);

$transaction = \Mews\Pos\PosInterface::TX_TYPE_ORDER_HISTORY;

try {
$pos->orderHistory($order);
} catch (Exception $e) {
Expand Down
3 changes: 1 addition & 2 deletions examples/_common-codes/regular/refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// ilgili bankanin _config.php dosyasi load ediyoruz.
// ornegin /examples/finansbank-payfor/regular/_config.php
require '_config.php';
$transaction = PosInterface::TX_TYPE_REFUND;

require '../../_templates/_header.php';

Expand Down Expand Up @@ -70,8 +71,6 @@ function createRefundOrder(string $gatewayClass, array $lastResponse, string $ip
);
dump($order);

$transaction = PosInterface::TX_TYPE_REFUND;

try {
$pos->refund($order);
} catch (Exception $e) {
Expand Down
4 changes: 1 addition & 3 deletions examples/_common-codes/regular/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use Mews\Pos\PosInterface;

$templateTitle = 'Order Status';

// ilgili bankanin _config.php dosyasi load ediyoruz.
// ornegin /examples/finansbank-payfor/regular/_config.php
require '_config.php';
$transaction = PosInterface::TX_TYPE_STATUS;

require '../../_templates/_header.php';

Expand Down Expand Up @@ -43,8 +43,6 @@ function createStatusOrder(string $gatewayClass, array $lastResponse, string $ip
$order = createStatusOrder(get_class($pos), $session->get('last_response'), $ip);
dump($order);

$transaction = PosInterface::TX_TYPE_STATUS;

$pos->status($order);

$response = $pos->getResponse();
Expand Down
4 changes: 4 additions & 0 deletions examples/_main_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
12 => '12 Taksit',
];

$paymentModel = null;
$posClass = null;
$transaction = null;

function doPayment(PosInterface $pos, string $paymentModel, string $transaction, array $order, ?\Mews\Pos\Entity\Card\CreditCardInterface $card)
{
if (!$pos::isSupportedTransaction($transaction, $paymentModel)) {
Expand Down
Loading

0 comments on commit fb4b775

Please sign in to comment.