关于javascript:paymentsense / woocommerce结帐时卡住了

paymentsense / woocommerce stuck on checkout

本问题已经有最佳答案,请猛点这里访问。

结帐后,我在开发人员控制台中收到此错误,页面只是停留在正在加载的动画上,

1
2
3
4
5
6
Uncaught TypeError: Cannot read property 'reload' of null
    at Object.success (checkout.min.js?ver=3.2.0:1)
    at i (jquery.js:2)
    at Object.fireWith [as resolveWith] (jquery.js:2)
    at y (jquery.js:4)
    at XMLHttpRequest.c (jquery.js:4)

这是PHP错误

1
2
3
4
5
6
7
8
9
[12-Oct-2017 09:02:12 UTC] order_total was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_address_1 was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_address_2 was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_city was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_state was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_postcode was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_country was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_email was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
[12-Oct-2017 09:02:12 UTC] billing_phone was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_Paymentsense_Direct->process_payment, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.

如何将其转换为WC 3.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
function process_payment($order_id)
        {

            global $woocommerce;
            $order = new WC_Order( $order_id );
            $suppcurr = array(
                    'USD' => '840',
                    'EUR' => '978',
                    'GBP' => '826'
            );

            if(!empty($suppcurr[get_option('woocommerce_currency')]))
            {
                $currency = $suppcurr[get_option('woocommerce_currency')];
            }
            else
            {
                $currency = '826';
            }

            try
            {
                $headers = array(
                    'SOAPAction:https://www.thepaymentgateway.net/CardDetailsTransaction',
                    'Content-Type: text/xml; charset = utf-8',
                    'Connection: close'
                );


                $MerchantID = $this->merchant_id;
                $Password = $this->password;
                $Amount = $order->order_total * 100; //Amount must be passed as an integer in pence
                $CurrencyCode = $currency; //826 = GBP

                $OrderID = $order_id;
                $OrderDescription = $this->order_prefix ."" . (string)$order_id; //Order Description for this new transaction

                $CardName = $this->stripGWInvalidChars($this->get_request('psense_ccname'));
                //die($Amount);
                $CardNumber = $this->get_request('psense_ccnum');
                $ExpMonth = $this->get_request('psense_expmonth');
                $ExpYear = $this->get_request('psense_expyear');
                $CV2 = $this->get_request('psense_cv2');
                $IssueNumber = $this->get_request('psense_issueno');

                $Address1 = $this->stripGWInvalidChars($order->billing_address_1);
                $Address2 = $this->stripGWInvalidChars($order->billing_address_2);
                $Address3 = '';
                $Address4 = '';
                $City = $this->stripGWInvalidChars($order->billing_city);
                $State = $this->stripGWInvalidChars($order->billing_state);
                $Postcode = $this->stripGWInvalidChars($order->billing_postcode);
                $Country = $this->stripGWInvalidChars($order->billing_country);
                $EmailAddress = $this->stripGWInvalidChars($order->billing_email);
                $PhoneNumber = $this->stripGWInvalidChars($order->billing_phone);
                $CountryCode = 826;
                $IPAddress = $_SERVER['REMOTE_ADDR'];


                $xml = '<?xml version="1.0" encoding="utf-8"?>
                        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                            <soap:Body>
                                <CardDetailsTransaction xmlns="https://www.thepaymentgateway.net/">
                                    <PaymentMessage>
                                        <MerchantAuthentication MerchantID="'
. $MerchantID .'" Password="'. $Password .'" />
                                        <TransactionDetails Amount="'
. $Amount .'" CurrencyCode="'. $CurrencyCode .'">
                                            <MessageDetails TransactionType="SALE" />
                                            <OrderID>'
.$OrderID .'</OrderID>
                                            <OrderDescription>'
. $OrderDescription . '</OrderDescription>
                                            <TransactionControl>
                                                <EchoCardType>TRUE</EchoCardType>
                                                <EchoAVSCheckResult>TRUE</EchoAVSCheckResult>
                                                <EchoCV2CheckResult>TRUE</EchoCV2CheckResult>
                                                <EchoAmountReceived>TRUE</EchoAmountReceived>
                                                <DuplicateDelay>20</DuplicateDelay>
                                                <CustomVariables>
                                                    <GenericVariable Name="MyInputVariable" Value="Ping" />
                                                </CustomVariables>
                                            </TransactionControl>
                                        </TransactionDetails>
                                        <CardDetails>
                                            <CardName>'
. $CardName .'</CardName>
                                            <CardNumber>'
. $CardNumber .'</CardNumber>
                                            <StartDate Month="" Year="" />
                                            <ExpiryDate Month="'
. $ExpMonth .'" Year="'. $ExpYear .'" />
                                            <CV2>'
. $CV2 .'</CV2>
                                            <IssueNumber>'
. $IssueNumber .'</IssueNumber>
                                        </CardDetails>
                                        <CustomerDetails>
                                            <BillingAddress>
                                                <Address1>'
. $Address1 .'</Address1>
                                                <Address2>'
. $Address2 .'</Address2>
                                                <Address3>'
. $Address3 .'</Address3>
                                                <Address4>'
. $Address4 .'</Address4>
                                                <City>'
. $City .'</City>
                                                <State>'
. $State .'</State>
                                                <PostCode>'
. $Postcode .'</PostCode>
                                                <CountryCode>'
. $CountryCode .'</CountryCode>
                                            </BillingAddress>
                                            <EmailAddress>'
. $EmailAddress .'</EmailAddress>
                                            <PhoneNumber>'
. $PhoneNumber .'</PhoneNumber>
                                            <CustomerIPAddress>'
. $IPAddress .'</CustomerIPAddress>
                                        </CustomerDetails>
                                        <PassOutData>Some data to be passed out</PassOutData>
                                    </PaymentMessage>
                                </CardDetailsTransaction>
                            </soap:Body>
                        </soap:Envelope>'
;

                $gwId = 1;
                $domain ="paymentsensegateway.com";
                $port ="4430";
                $transattempt = 1;
                $soapSuccess = false;

                while(!$soapSuccess && $gwId <= 3 && $transattempt <= 3)
                {
                    $url = 'https://gw'.$gwId.'.'.$domain.':'.$port.'/';

                    //initialise cURL
                    $curl = curl_init();

                    //set the options
                    curl_setopt($curl, CURLOPT_HEADER, false);
                    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
                    curl_setopt($curl, CURLOPT_POST, true);
                    curl_setopt($curl, CURLOPT_URL, $url);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($curl, CURLOPT_ENCODING, 'UTF-8');
                    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

                    //Execute cURL request
                    //$ret = returned XML
                    $ret = curl_exec($curl);
                    //$err = returned error number
                    $err = curl_errno($curl);
                    //retHead = returned XML header
                    $retHead = curl_getinfo($curl);
                    //die($ret);
                    //close cURL connection
                    curl_close($curl);
                    $curl = null;
                    //die($ret);
                    if($err == 0)
                    {
                        $StatusCode = $this->GetXMLValue("StatusCode", $ret,"[0-9]+");

                        if(is_numeric($StatusCode)) {
                            //request was processed correctly

                            if( $StatusCode != 30 ) {
                                //set success flag so it will not run the request again.
                                $soapSuccess = true;

                                //grab some of the most commonly used information from the response
                                $szMessage = $this->GetXMLValue("Message", $ret,".+");
                                $szAuthCode = $this->GetXMLValue("AuthCode", $ret,".+");
                                $szCrossReference = $this->GetCrossReference($ret);
                                $szAddressNumericCheckResult = $this->GetXMLValue("AddressNumericCheckResult", $ret,".+");
                                $szPostCodeCheckResult = $this->GetXMLValue("PostCodeCheckResult", $ret,".+");
                                $szCV2CheckResult = $this->GetXMLValue("CV2CheckResult", $ret,".+");
                                $szThreeDSecureAuthenticationCheckResult = $this->GetXMLValue("ThreeDSecureAuthenticationCheckResult", $ret,".+");

                                switch ($StatusCode) {
                                    case 0:
                                        // transaction authorised
                                        $transaction_status = 'success';
                                        break;
                                    case 3:
                                        //3D Secure Auth required
                                        //Gather required variables
                                        if ('yes'==$this->debug)
                                        {
                                            $this->log->add( 'paymentsense_direct', '3D Secure authentication required');
                                        }

                                        $pareq = $this->GetXMLValue("PaREQ", $ret,".+");
                                        $crossref   = $szCrossReference;
                                        $url = $this->GetXMLValue("ACSURL", $ret,".+");
                                        $woocommerce->session->paymentsense = array('pareq' => $pareq, 'crossref' => $crossref, 'url' => $url);
                                        return array(
                                            'result'    => 'success',
                                            'redirect'  => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('pay'))))
                                        );
                                        break;
                                    case 4:
                                        //Card Referred - treat as a decline
                                        $transaction_status = 'failed';
                                        break;
                                    case 5:
                                        //Card declined

                                        $transaction_status = 'failed';
                                        break;
                                    case 20:
                                        if (preg_match('#<PreviousTransactionResult>(.+)</PreviousTransactionResult>#iU', $ret, $soapPreviousTransactionResult)) {
                                            $PreviousTransactionResult = $soapPreviousTransactionResult[1];

                                            $PreviousMessage = $this->GetXMLValue("Message", $PreviousTransactionResult,".+");
                                            $PreviousStatusCode = $this->GetXMLValue("StatusCode", $PreviousTransactionResult,".+");
                                        }

                                        // need to look at the previous status code to see if the transaction was successful
                                        if ($PreviousStatusCode == 0)
                                        {
                                            $transaction_status = 'success';
                                        }
                                        else
                                        {
                                            $transaction_status = 'failed';
                                        }
                                        break;
                                    default:
                                        $transaction_status = 'failed';
                                        break;
                                }
                            }
                            else
                            {
                                // status code is 30 - error occured
                                // get the reason from the xml
                                $szMessageDetail = $this->GetXMLValue("Detail", $ret,".+");

                                //run the function to get the cause of the error
                                $Response ="Error occurred:";
                                $Response .= $szMessageDetail;
                            }
                        }
                    }
                    if($transattempt <=2)
                    {
                        $transattempt++;
                    }
                    else
                    {
                        //reset transaction attempt to 1 & incremend $gwID (to use next numeric gateway number (eg. use gw2 rather than gw1 now))
                        $transattempt = 1;
                        $gwId++;
                    }
                }

                if($transaction_status == 'success')
                {
                    $order->payment_complete();
                    $order->add_order_note('Payment Successful: '.$szMessage.'<br />',0);
                    return array(
                        'result' => 'success',
                        'redirect' => $this->get_return_url( $order )
                    );
                }
                elseif ($transaction_status == 'failed')
                {
                    //die("123456");
                    $order->get_checkout_payment_url(false);
                    $order->update_status('failed', sprintf( __( 'Payment Failed due to: %s .<br />', 'woocommerce' ), strtolower( $szMessage ) ));
                    wc_add_notice(__('Payment Failed due to: ', 'woothemes') . $szMessage. '<br /> Please check your card details and try again.', 'error');


                    return;
                }
            }
            catch(Exception $ex)
            {
                if ($this->debug=='yes')
                {
                    $this->log->add( 'paymentsense_direct',"Error:" . $szMessage);
                }
                echo ''. $szMessage . '';
                exit;
            }
            exit;
            }


除了我对您的问题的评论外,以下是确切的操作方法:

您必须更改直接访问$ order对象的所有行。
这是您显示的大多数代码。

1
2
3
4
5
6
7
8
9
10
$Address1 = $this->stripGWInvalidChars($order->billing_address_1);
$Address2 = $this->stripGWInvalidChars($order->billing_address_2);
$Address3 = '';
$Address4 = '';
$City = $this->stripGWInvalidChars($order->billing_city);
$State = $this->stripGWInvalidChars($order->billing_state);
$Postcode = $this->stripGWInvalidChars($order->billing_postcode);
$Country = $this->stripGWInvalidChars($order->billing_country);
$EmailAddress = $this->stripGWInvalidChars($order->billing_email);
$PhoneNumber = $this->stripGWInvalidChars($order->billing_phone);

您需要将$order->billing_address_1更改为$order->get_billing_address_1()

所以您最终得到这样的东西:

1
$Address1 = $this->stripGWInvalidChars($order->get_billing_address_1());

我不会全部完成,但是您会理解:)

您可以在这里找到WooCommerce圣经,您将在这里找到所有需要的:)