<?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->isBoletoPayment()) : ?>
    <?php
    $boletoData = $block->getBoletoData();
    ?>
    <p>
        <?php echo $block->escapeHtml(__('Boleto PDF: ')); ?>
        <a href="<?php echo $block->escapeUrl($boletoData['downloadUrl']); ?>">
            <?php echo $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><?php echo $block->escapeHtml(__('Pay using Bank transfer')); ?></h2>
    <p><?php echo $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><?php echo $block->escapeHtml(__('Amount')); ?></th>
                <td><?php echo $order->formatPrice($order->getGrandTotal()); ?></td>
            </tr>
        <?php endif; ?>

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

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

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

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

        <?php if (!empty($banktranferData['bankTransfer.accountCode'])) : ?>
            <tr>
                <th><?php echo $block->escapeHtml(__('Bankaccount')); ?></th>
                <td><?php echo $banktranferData['bankTransfer.accountCode'] ?></td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>


<?php elseif (!empty($block->getMultibancoData())) : ?>
    <?php
    $multibancoData = $block->getMultibancoData();
    ?>
    <h2><?php echo $block->escapeHtml(__('Pay using Multibanco')); ?></h2>
    <p><?php echo $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><?php echo $block->escapeHtml(__('Entity')); ?></th>
                <td><?php echo $multibancoData['entity'] ?></td>
            </tr>
        <?php endif; ?>

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

        <?php if (!empty($multibancoData['totalAmount'])) : ?>
            <tr>
                <th><?php echo $block->escapeHtml(__('Amount')); ?></th>
                <td><?php echo $block->priceHelper->currency($multibancoData['totalAmount']['value']) //TODO: This value is showing as it comes from the API call and based on the currency the decimal point could be wrong until the Checkout Component is implemented ?></td>
            </tr>
        <?php endif; ?>

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


<?php endif; ?>
