<?php
/**
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the GNU General Public License (GPL 3)
 * that is bundled with this package in the file LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
 * versions in the future. If you wish to customize Payone_Core for your
 * needs please refer to http://www.payone.de for more information.
 *
 * @category        Payone
 * @package         design_frontend_base_default
 * @subpackage      template
 * @copyright       Copyright (c) 2021 <kontakt@fatchip.de> - www.fatchip.de
 * @author          Fatchip GmbH <kontakt@fatchip.de>
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
 * @link            https://www.fatchip.de
 */
?>

<?php /** @var Payone_Core_Block_Checkout_Onepage_Review_ApplePayHandling $this */ ?>
<script type="text/javascript">
    var button = $$('#review-buttons-container button')[0];

    if ('undefined' !== typeof button) {
        <?php if ($this->isApplePayPayment()) { ?>
        var supportedNetworks = JSON.parse('<?= json_encode($this->getSupportedNetworks()) ?>');
        button.onclick = button.onclick.wrap(
            function() {
                if (supportedNetworks.length === 0) {
                    alert('<?= $this->__('APPLEPAY_CREATE_SESSION_ERROR_CARDS') ?>');
                    return
                }

                payWithApplePay(
                    '<?= $this->getAmount() ?>',
                    '<?= $this->getCountryCode() ?>',
                    '<?= $this->getCurrencyCode() ?>',
                    supportedNetworks,
                    '<?= $this->getCreateSessionUrl() ?>',
                    '<?= $this->getCreatePaymentUrl() ?>',
                );
            }
        );
        <?php } ?>
    }
</script>
