<input type="hidden" id="paystack_transaction_id" name="paystack_plugincustomfields[paystack_transaction_id]" value="">

<script src="https://js.paystack.co/v1/inline.js"></script>
<?php if ($this->from == 'signup') { ?>
<a style="margin-left:0px;cursor:pointer;" class="center-on-mobile app-btns primary customButton paystackButton" id="customButton"></a>
<?php } else if ($this->from == 'invoice') { ?>
<button class="app-btns primary customButton paystackButton"><?php echo $this->user->lang('Pay Invoice'); ?></button>
<?php } ?>

<script>
    function paystackOpenHandler(){
        <?php if ($this->from == 'signup') { ?>
            var email = '';

            <?php if (!$this->loggedIn) { ?>
                var CT_4 = document.getElementById('CT_4');

                if(typeof CT_4 !== null && CT_4 !== 'undefined' ) {
                    email = CT_4.value;
                }
            <?php } ?>
        <?php } ?>

        var handler = PaystackPop.setup({
            key: '<?php echo $this->publicKey; ?>',

            <?php if ($this->from == 'invoice') { ?>
                email: '<?php echo $this->user->getEmail(); ?>',
                amount: '<?php echo $this->amount; ?>',
                currency: '<?php echo $this->currency;?>',
            <?php } else if ($this->from == 'signup')  { ?>
                email: email+'<?php echo @$this->user->getEmail(); ?>',
                amount: Math.round(document.getElementById("totalPay_raw").value * 100),
                currency: '<?php echo $this->Currency;?>',
            <?php } ?>

            callback: function(response) {
                document.getElementById('paystack_transaction_id').value = response.trxref;

                <?php if ($this->from == 'invoice' || $this->from == 'signup') { ?>
                    $('#submitButton').click();
                <?php } ?>
            }
        });
        handler.openIframe();
    }

    $('.paystackButton').on('click', function(e) {
        e.preventDefault();

        <?php if ($this->from == 'signup') { ?>
            if ($('.paystackButton').hasClass('disabled')) {
                return;
            }
        <?php } ?>
        paystackOpenHandler();
    });
</script>