Mark charlton
Mark charlton

Reputation: 377

This payment form is not submitting for some reason

I am using Paymill to accept payments and for some reason when I put in my live API keys this form stops submitting. I've entered in some valid live card details and the button becomes disabled for about 5 seconds and then the button becomes active again rather than posting the information to my payment script. No errors are coming up either.

Here is the code:

<form id="payment-form" action="transaction.php" method="POST">

    <input type="hidden" name="app_id" value="<? echo $app_id; ?>">
    <input type="hidden" name="email" value="<? echo $row['email']; ?>">
    <input type="hidden" name="first_name" value="<? echo $row['first_name']; ?>">
    <input type="hidden" name="surname" value="<? echo $row['surname']; ?>">
    <input class="card-amount-int" type="hidden" value="100" id="card-amount-int" />
    <input class="card-currency" type="hidden" value="GBP" id="card-currency"/>
    <div class="form-row">
        <input class="card-holdername" type="hidden" size="4" id="card-holdername" value="<? echo $row['surname']; ?>" />
    </div>


    <p>
        <label>Card number:</label>
        <input class="card-number form-control" type="text" size="25" id="card-number"/>
    </p>



    <br>

    <p>
        <label>Expiration Date:</label>
        <select id="card-expiry-month"   class="card-expiry-month">
            <option value="01">January</option>
            <option value="02">February</option>
            <option value="03">March</option>
            <option value="04">April</option>
            <option value="05">May</option>
            <option value="06">June</option>
            <option value="07">July</option>
            <option value="08">August</option>
            <option value="09">September</option>
            <option value="10">October</option>
            <option value="11">November</option>
            <option value="12">December</option>
        </select>
        <select id="card-expiry-year"  class="card-expiry-year">
            <option value="2015" selected="selected">2015</option><option value="2016">2016</option>
            <option value="2017">2017</option><option value="2018">2018</option>
            <option value="2019">2019</option><option value="2020">2020</option>
            <option value="2021">2021</option><option value="2022">2022</option>
            <option value="2023">2023</option><option value="2024">2024</option>
            <option value="2025">2025</option><option value="2026">2026</option>
            <option value="2027">2027</option><option value="2028">2028</option>
            <option value="2029">2029</option><option value="2030">2030</option>
            <option value="2031">2031</option><option value="2032">2032</option>
            <option value="2033">2033</option><option value="2034">2034</option>                        
        </select>
    </p>

    <br>
    <p>
        <label>Security Code (CVC):</label>
        <input class="card-cvc" type="text" size="4" id="card-cvc"/>
    </p>
    <br>
    <button class="submit-button btn btn-lg btn-success" type="submit" >Submit Payment</button>

</form>
<br><br>
</div>
<script type="text/javascript" src="https://bridge.paymill.com/"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>


<script type="text/javascript">
    var PAYMILL_PUBLIC_KEY = '****';

    jQuery(function ($) {
        $('#payment-form').submit(function (event) {
            var $form = $(this);

            // Disable the submit button to prevent repeated clicks
            $form.find('button').prop('disabled', true);

            paymill.createToken({
                number: $('.card-number').val(), // required, ohne Leerzeichen und Bindestriche
                exp_month: $('.card-expiry-month').val(), // required
                exp_year: $('.card-expiry-year').val(), // required, vierstellig z.B. "2016"
                cvc: $('.card-cvc').val(), // required
                amount_int: $('.card-amount-int').val(), // required, integer, z.B. "15" für 0,15 Euro
                currency: $('.card-currency').val(), // required, ISO 4217 z.B. "EUR" od. "GBP"
                cardholder: $('.card-holdername').val() // optional
            }, PaymillResponseHandler);
// Prevent the form from submitting with the default action
            return false;
        });
    });


    function PaymillResponseHandler(error, result) {
        var $form = $('#payment-form');

        if (error) {
// Show the errors on the form
            $(".payment-errors").text(error.apierror);
            $(".submit-button").removeAttr("disabled");
        } else {
// response contains id and card, which contains additional card details
            var token = result.token;
// Insert the token into the form so it gets submitted to the server
            $form.append($('<input type="hidden" name="paymillToken" />').val(token));
// and submit
            $form.get(0).submit();
        }
    }
    ;
</script>

Upvotes: 0

Views: 125

Answers (1)

Max K.
Max K.

Reputation: 21

So with "no error coming up" I assume that you say that there is no error in the console. As far as I see the code itself is ok but I think auth for the live keys fails (as far as test keys ran successfully).

When posting to the API there is then a valid response with code 200 (from an HTTP view) but still auth fails (already for Tokenization/in Bridge). Please check the response in the network response. If you see something like {"code: "80", message: "User Authentication Error"} you know where the issue is. Then please make sure that your keys are valid (test them e.g. via cUrl).

Upvotes: 2

Related Questions