Submitting form in WooCommerce payment gateway plugin

I am working on developing a plugin for the Skipjack payment gateway. This gateway uses an html form provided by skipjack to pass the order information via HTTP POST to their custom payment form. I have created the process_payment() function which echoes this form to the browser and auto-submits via javascript. This form submits successfully in Chrome and Firefox but not in Internet Explorer.

Here is the process_payment() function:

Read More
    function process_payment( $order_id ) {
        global $woocommerce;

        $order = new WC_Order( $order_id );

                // Reduce stock levels
                $order->reduce_order_stock();

                // Clear cart
                $woocommerce->cart->empty_cart();

                //Convert countries to codes provided by Skipjack
                $BillingCountryCode = '';
                $ShippingCountryCode = '';
                if ($order->billing_country === 'US') {
                    $BillingCountryCode = '840';
                } else if ($order->billing_country === 'Canada') {
                    $BillingCountryCode = '124';
                }
                if ($order->shipping_country === 'US') {
                    $ShippingCountryCode = '840';
                } else if ($order->shipping_country === 'Canada') {
                    $ShippingCountryCode = '124';
                }

                $url = 'https://payments.skipjack.com/FormBuilder/VPOS.aspx';

                //build form to pass data to Skipjack
                echo'<BR><form name="Generator" method="post" action="' . $url . '">';
                echo'<input type="hidden" name="url" value="' . $url . '">';
                echo'<input type="hidden" name="VposContent" value="' . $this->settings['skipjack_vpos_code'] . '">';
                echo'<input type="submit" name="DonateButton" class="button alt" style="font-size:25px;" align="center" value="Click Here to Process Payment and Complete Order" >';
                echo'<input type="hidden" name="sjname" value="' . $order->billing_first_name . ' ' . $order->billing_last_name . '">';
                echo'<input type="hidden" name="streetaddress" value="' . $order->billing_address_1 . '">';
                echo'<input type="hidden" name="streetaddress2" value="' . $order->billing_address_2 . '">';
                echo'<input type="hidden" name="city" value="' . $order->billing_city . '">';
                echo'<input type="hidden" name="state" value="' . $order->billing_state . '">';
                echo'<input type="hidden" name="zipcode" value="' . $order->billing_postcode . '">';
                echo'<input type="hidden" name="country" value="' . $BillingCountryCode . '">';                     
                echo'<input type="hidden" name="email" value="' . $order->billing_email . '">';
                echo'<input type="hidden" name="shiptostreetaddress" value="' . $order->shipping_address_1 . '">';
                echo'<input type="hidden" name="shiptostreetaddress2" value="' . $order->shipping_address_2 . '">';
                echo'<input type="hidden" name="shiptocity" value="' . $order->shipping_city . '">';
                echo'<input type="hidden" name="shiptostate" value="' . $order->shipping_state . '">';
                echo'<input type="hidden" name="shiptozipcode" value="' . $order->shipping_postcode . '">';
                echo'<input type="hidden" name="shiptocountry" value="' . $ShippingCountryCode . '">';                     
                echo'<input type="hidden" name="shiptophone" value="' . $order->billing_phone . '">';
                echo'<input type="hidden" name="ordernumber" value="' . $order->id . '">';
                echo'<input type="hidden" name="transactionamount" value="' . $order->order_total . '">';
                echo'</form>'; 

//                //auto-submit above form
//                echo'<script>';
//                echo'document.Generator.submit();';
//                echo'return true;';
//                echo'</script>';

                die;
//               return;
    }

Currently when I run this plugin in IE, when the form is submitted (whether manually or by javascript) the checkout page just refeshes with a message that your session has expired but the form is not submitted. When I view source in IE the form does not show up, even though it obviously shows on the page. However it works correctly in Chrome and FireFox.

As you can see in my code above, I just use echo to output the form to the browser to be processed as html. Is there a better way to do this? Also I used die to stop executing the php because when I used return I got a failure message. What should I be returning since the browser needs to redirect to the skipjack form located at https://payments.skipjack.com/FormBuilder/VPOS.aspx (which is stored in the variable $url)?

Related posts

Leave a Reply