Converting SQPAYMENTFORM NONCE to php?

Hello,

The SqPaymentForm walkthrough explains how to implement the form through JS, and then process it using JS. The problem for me, is that I am not fluent in JS. I am fluent in PHP.

What I need to happen, is to convert the nonce response that I get in the js when I hit the pay button, to a hidden input element within the form.

There is a php payment process example found here. This gives an example of using the payment form as well, but its initialized and executed differently than the sqpaymentform walkthrough. For some reason, its trying to use a dotenv model that doesn’t want to initialize. I’m not sure why its not finding it. This example however, does do what I’d like the other one to do in the script, which is place the nonce into a hidden element.

Is there a middle ground between these two? Because I think thats where I need to go. I need to be at the place that uses the form from the first walkthrough, and the result of the php example. Anyone have experience with this?

<div id="form-container">
        <form id="nonce-form" novalidate action="test3.php" method="post">
            <div id="sq-card-number"></div>
            <div class="third" id="sq-expiration-date"></div>
            <div class="third" id="sq-cvv"></div>
            <div class="third" id="sq-postal-code"></div>            
            <input type="hidden" id="card-nonce" name="nonce">
            <button id="sq-creditcard" class="button-credit-card" onclick="onGetCardNonce(event)">Add Card</button>
            <div id="error"></div>
        </form>   
   </div>

Found out thats all you need to get it moved over to handle for php. If you know php, you’ll have to create your own file to handle the nonce.

Replace test3.php in the form action to whatever file you have for handling it.

Also have to replace the alert with this
//TODO: Replace alert with code in step 2.1
document.getElementById(‘card-nonce’).value = nonce;
document.getElementById(‘nonce-form’).submit();

1 Like