2

I keep getting an error response for my test field for Charge. I've pretty closely followed the example just for testing and can't seem to get a successful charge.

I've tried setting a hidden field for amount and planAmount to no success.

Error:

array(1) {
  ["errors"]=>
  array(2) {
    [0]=>
    string(37) "planAmount : Amount must be a number."
    [1]=>
    string(74) "There was a problem with your details, please check the form and try again"
  }
}

Form:

<form method="post" id="charge-form" class="charge-form">
    <input type="hidden" name="action" value="charge/charge">
    {% set options = {
        'planAmount': 79,
        'planInterval': 'year',
        'planIntervalCount': 1,
        'planCurrency': 'aus',
        'actions': {
            'onSuccess': {
                'subscription': 'gold-membership'
            }
        }
    } %}
    {{ craft.charge.setPaymentOptions(options) }}

    <div id="payment-errors"></div>

    <div>
        <label for="customerEmail">Receipt Email</label>
        <input type="text" name="customerEmail" value="{{ charge is defined ? charge.customerEmail : currentUser ? currentUser.email }}" id="customerEmail">
        {% if charge is defined %}{% for error in charge.getErrors('customerEmail') %}{{ error }}{% endfor %}{% endif %}
    </div>

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

    <div>
        <label>
            <span>Expiration (MM/YY)</span>
            <input type="text" size="2" data-stripe="exp_month">
        </label>
        <span> / </span>
        <input type="text" size="2" data-stripe="exp_year">
    </div>

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

    <button type="submit">Upgrade</button>
</form>

JS:

Stripe.setPublishableKey(this.s.publicKey.test);
$(window).charge(this.s.form);

1 Answer 1

4

Developer of Charge here.

This error is because you're passing an invalid currency code.

You're passing aus as the planCurrency, but need to be passing aud for Australian Dollars.

Under the hood, Charge is seeing that currency code as invalid, and unsetting the amount from the request, which is why that error is showing up on the planAmount.

(Charge unsets the amount as a safety mechanism to prevent the request falling back and processing in the default currency)

I'll update the language of the error to make it clearer the currency code is the invalid value in an upcoming release.

1
  • Yeah I was confused by the 3-letter country code refernce in the docs, assumed it was 'aus', not a currency code :-)
    – Jarryd
    Commented Jun 21, 2016 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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