{% load static %}
{% load djangorave_tags %}
<!--
    User email is required by Rave, therefore user must be signed in before
    button will be displayed.
-->
<script>
    function createPaymentParams() {
        //
        // Create payment params which will be sent to Rave upon payment
        //
        {% autoescape off %}
        let pay_button_params = JSON.parse('{% if user.is_authenticated %}{% pay_button_params user=user payment_type=payment_type %}{% endif %}');
        {% endautoescape %}
        paymentParams['{{ payment_type.description }}'] = {
            PBFPubKey: pay_button_params.pub_key,
            amount: '{{ payment_type.amount }}',
            currency: '{{ payment_type.currency }}',
            custom_logo: '{{ payment_type.custom_logo }}',
            custom_title: '{{ payment_type.custom_title }}',
            customer_email: '{{ user.email }}',
            customer_firstname: '{{ user.first_name }}',
            customer_lastname: '{{ user.last_name }}',
            pay_button_text: '{{ payment_type.pay_button_text }}',
            payment_options: '{{ payment_type.payment_options }}',
            payment_plan: '{{ payment_type.payment_plan }}',
            txref: pay_button_params.txref,
            integrity_hash: pay_button_params.integrity_hash,
            redirect_url: pay_button_params.redirect_url
        }
    }
    if ('{{ user.is_authenticated }}' === 'True') {
        createPaymentParams();
    }
</script>
<script type="text/javascript" src="{% rave_inline_js %}"></script>
{% if user.is_authenticated %}
<button
    class="rave-pay-btn {% if payment_type.payment_plan %}rave-subscription-btn{% else %}rave-onceoff-btn{% endif %}"
    type="button"
    onClick="payWithRave(paymentParams['{{ payment_type.description }}'])">
    {{ payment_type.pay_button_text }}
</button>
{% else %}
<p>User must be signed in</p>
{% endif %}