<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

/**
 * @var \Adyen\Payment\Block\Checkout\Success $block
 */
?>
<?php if ($block->renderAction()): ?>
    <script type="text/javascript">
        require([
            'jquery',
            'adyenCheckout3101'
        ], function ($, AdyenCheckout) {
            var action = JSON.parse('<?= /* @noEscape */ $block->getAction(); ?>');
            var checkoutComponent = new AdyenCheckout({
                locale: '<?= $block->escapeHtml($block->getLocale()); ?>',
                environment: '<?= $block->escapeHtml($block->getEnvironment()); ?>',
                originKey: '<?= $block->escapeHtml($block->getOriginKey()); ?>'
            });
            try {
                checkoutComponent.createFromAction(action).mount('#ActionContainer');
            } catch(err) {
                // Action component cannot be created
            }
        });
    </script>
    <div id="ActionContainer"></div>
<?php else: ?>
    <?php if ($block->isBoletoPayment()): ?>
    <?php
    $boletoData = $block->getBoletoData();
    ?>
    <p>
        <?= $block->escapeHtml(__('Boleto PDF: ')); ?>
        <a href="<?= $block->escapeUrl($boletoData['downloadUrl']); ?>">
            <?= $block->escapeHtml(__('Click here to download the Boleto PDF')); ?>
        </a>
    </p>
<?php endif; ?>

    <?php if (!empty($block->getBankTransferData())): ?>
    <?php
    $banktranferData = $block->getBankTransferData();
    $order = $block->getOrder();
    ?>
    <h2><?= $block->escapeHtml(__('Pay using Bank transfer')); ?></h2>
    <p><?= $block->escapeHtml(
            __('Please transfer the amount using the reference below to the following bank account')
        ); ?></p>
    <table>
        <tbody>
        <?php if (!empty($order->getGrandTotal())): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Amount')); ?></th>
                <td><?= /* @noEscape */
                    $order->formatPrice($order->getGrandTotal()); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($banktranferData['bankTransfer.reference'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('With reference')); ?></th>
                <td><?= $block->escapeHtml($banktranferData['bankTransfer.reference']); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($banktranferData['bankTransfer.owner'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Beneficiary Name')); ?></th>
                <td><?= $block->escapeHtml($banktranferData['bankTransfer.owner']); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($banktranferData['bankTransfer.bankName'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Bank')); ?></th>
                <td><?= $block->escapeHtml($banktranferData['bankTransfer.bankName']); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($banktranferData['bankTransfer.iban'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('IBAN')); ?></th>
                <td><?= $block->escapeHtml($banktranferData['bankTransfer.iban']); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($banktranferData['bankTransfer.accountCode'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Bankaccount')); ?></th>
                <td><?= $block->escapeHtml($banktranferData['bankTransfer.accountCode']); ?></td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>
<?php elseif (!empty($block->getMultibancoData())): ?>
    <?php
    $multibancoData = $block->getMultibancoData();
    ?>
    <h2><?= $block->escapeHtml(__('Pay using Multibanco')); ?></h2>
    <p><?= $block->escapeHtml(
            __(
                'Please pay with the provided Multibanco reference and entity before payment deadline in order to ' .
                'complete our payment'
            )
        ); ?></p>
    <table>
        <tbody>

        <?php if (strcmp($multibancoData['paymentMethodType'], 'multibanco') === 0): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Entity')); ?></th>
                <td><?= $block->escapeHtml($multibancoData['entity']); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($multibancoData['reference'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Reference')); ?></th>
                <td><?= $block->escapeHtml($multibancoData['reference']); ?></td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($multibancoData['totalAmount'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Amount')); ?></th>
                <td><?= /* @noEscape */
                    $block->priceHelper->currency($multibancoData['totalAmount']['value']); ?>
                </td>
            </tr>
        <?php endif; ?>

        <?php if (!empty($multibancoData['expiresAt'])): ?>
            <tr>
                <th scope="row"><?= $block->escapeHtml(__('Payment deadline')); ?></th>
                <td><?= $block->escapeHtml($multibancoData['expiresAt']); ?></td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>
    <?php endif; ?>
<?php endif; ?>
