1

I just had a fresh install of Charge 2 and my Craft version is Craft CMS 2.6.2989. However as long as I have {{craft.charge.setPaymentOptions()}} in my template, all my form fields disappear and show up again after I remove this line.

{% extends "_layout" %}
{% set title = "Bookings" | t %}

{% set entry = craft.entries.section('bookings').first %}

{% block content %}
    <div class="[ grid ] island">
        <div class="[ grid__item desk-seven-twelfths ]">
            {% if entry.heading | length %}
                <h1 class="brand-color">{{ entry.heading }}</h1>
            {% endif %}

            {% if entry.featureImage | length %}
                <img src="{{ entry.featureImage.first.url('halfWidth') }}" alt="{{ entry.Title }}" class="push--bottom">
            {% endif %}

            {% if entry.introText | length %}
                <div class="lede">{{ entry.introText }}</div>
            {% endif %}

            {% if entry.body | length %}
                {% include '_partials/_body' %}
            {% endif %}
        </div>

        <div class="[ grid__item desk-one-third push--desk-one-twelfth ]">
            <div class="island ui-background--light">
                <h3 class="push-half--bottom text--center ui-color--dark">{{ "Make a Payment" | t }}</h3>

                <hr class="rule rule--double">

                <form id="charge-form" method="post" data-publicKey="{{ craft.charge.publicKey }}">
                    {% set chargeOptions = {'planAmount' : 99} %}
                    {{craft.charge.setPaymentOptions(chargeOptions)}}
                    <input type="hidden" name="action" value="charge/charge"/>

                    <label for="customerEmail">Receipt Email</label>
                    <input type="text" name="customerEmail" value="{{ currentUser ? currentUser.email }}" id="customerEmail"/>

                    <label for="cardNumber">Card Number</label>
                    <input type="text" data-stripe="number" placeholder="•••• •••• •••• ••••" id="cardNumber"/>

                    <label for="cardExpiry">Card Expiry</label>
                    <input type="text" data-stripe="exp" placeholder="mm / yy" id="cardExpiry"/>

                    <label for="cardCvc">Card CVC</label>
                    <input type="text" data-stripe="cvc" placeholder="123" id="cardCvc"/>
                </form> 

            </div>
        </div>
    </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    {% includeJsResource('charge/js/jquery.charge.js') %}
    {% includeJsResource('charge/js/stripe_v2.min.js') %}
    {% includejs %}
        $(this).charge();
    {% endincludejs %}
{% endblock %}

enter image description here

I can't see what's wrong with my setup...

  • Looks like {{craft.charge.setPaymentOptions()}} returns a 500 and the page just half rendered, stopped at this line – Leon Zhang Sep 5 '17 at 4:38
  • There is something wrong with function public function encode($arr) { return base64_encode(craft()->security->encrypt(serialize($arr))); } – Leon Zhang Sep 5 '17 at 5:59
  • Never mind, I figured out. After looking into the source code of the encrypt function, it calls mcrypt_module_get_algo_key_size and because my vagrant box didn't have php5-mcrypt installed, it failed there. To fix it: apt-get install php5-mcrypt sudo php5enmod mcrypt – Leon Zhang Sep 5 '17 at 6:39
  • Thanks for the follow-up, Leon. Would you mind adding that as an official answer in case it helps someone in the future? – Brad Bell Sep 5 '17 at 18:06
1

After looking into the source code of the encrypt function, the craft.charge.setPaymentOptions() function calls mcrypt_module_get_algo_key_size and because my vagrant box (ubuntu 14.04) didn't have php5-mcrypt installed, it failed there.

To fix it: run apt-get install php5-mcrypt && sudo php5enmod mcrypt.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.