在WooCommerce支付网关插件中提交表单

时间:2013-10-31 15:13:09

标签: php wordpress woocommerce

我正在为Skipjack支付网关开发一个插件。此网关使用skipjack提供的html表单通过HTTP POST将订单信息传递到他们的自定义付款表单。我创建了process_payment()函数,它将此表单回显给浏览器并通过javascript自动提交。此表单已在Chrome和Firefox中成功提交,但未在Internet Explorer中提交。

这是process_payment()函数:

    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;
    }

目前,当我在IE中运行此插件时,在提交表单时(无论是手动还是通过javascript),结帐页面只会刷新一条消息,表明您的会话已过期,但表单未提交。当我在IE中查看源时,表单不会显示,即使它显然在页面上显示。但它在Chrome和FireFox中可以正常工作。

正如您在上面的代码中所看到的,我只是使用echo将表单输出到浏览器以作为html处理。有一个更好的方法吗?我还使用die停止执行php,因为当我使用return时,我收到了一条失败消息。我应该返回什么,因为浏览器需要重定向到位于https://payments.skipjack.com/FormBuilder/VPOS.aspx的skipjack表单(存储在变量$ url中)?

0 个答案:

没有答案