<?php
/**
 * TNW_Stripe extension
 * NOTICE OF LICENSE
 *
 * This source file is subject to the OSL 3.0 License
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/osl-3.0.php
 *
 * @category  TNW
 * @package   TNW_Stripe
 * @copyright Copyright (c) 2017-2018
 * @license   Open Software License (OSL 3.0)
 */

/** @var TNW\Stripe\Block\Payment $block */

$code = $block->escapeHtml($block->getCode());
?>
<script>
  //<![CDATA[
  require(
    [
      'jquery',
      'TNW_Stripe/js/stripe',
      'Magento_Sales/order/create/form',
      'domReady!'
    ], function($, Stripe) {
      var config = <?php /* @noEscape */ echo $block->getPaymentConfig(); ?>,
        payment,
        form = $('#payment_form_<?php /* @noEscape */ echo $code; ?>');

      config.active = form.length > 0 && !form.is(':hidden');
      payment = new Stripe(config);
    });
  //]]>
</script>
