opencart 2.0升级后Opencart支付网关报错
Opencart Payment gateway error after opencart 2.0 upgrade
我们的 opencart 商店有一个名为 atom 的支付网关。最近我们将 Opencart 从 1.5.6.4 升级到 2.0.1.0 版本。由于这种付款方式停止工作。我经历了this post了解opencart 2.0的变化
下面是我更新的代码
//catalog/controller/payment/atompay.php
<?php
class ControllerPaymentAtompay extends Controller {
protected function index() {
$this->language->load('payment/atompay');
$data['button_confirm'] = $this->language->get('button_confirm');
$data['url2'] = $this->url->link('payment/atompay/dopayment');
$this->session->data['order_id'];
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/atompay.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/payment/atompay.tpl', $data);
} else {
return $this->load->view('default/template/payment/atompay.tpl', $data);
}
//$this->render();
}
public function dopayment() {
$vendor = $this->config->get('atompay_vendor');
$password = $this->config->get('atompay_password');
$data['action'] = $this->config->get('atompay_url');
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$datenow = date("d/m/Y");
$data['BillingCity'] = $order_info['payment_city'];
$data['BillingPostCode'] = $order_info['payment_postcode'];
$data['BillingCountry'] = $order_info['payment_iso_code_2'];
$data['login'] = $this->config->get('atompay_vendor');
$data['pass'] = $this->config->get('atompay_password');
$data['ttype'] = 'NBFundTransfer';
$data['action'] = $this->config->get('atompay_url');
$data['prodid'] = $this->config->get('atompay_prodid');
$data['amt'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
$data['txnid'] = $this->session->data['order_id'];
$data['txndate'] = $datenow;
$data['CustomerName'] = html_entity_decode($order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['CustomerEMail'] = $order_info['email'];
$data['BillingPhone'] = $order_info['telephone'];
$data['BillingAddress1'] = $order_info['payment_address_1']."|".$data['BillingCity']."|".$data['BillingCountry'];
$data['ru'] = $this->url->link('payment/atompay/success');
$postFields = "";
$postFields .= "&login=".$data['login'];
$postFields .= "&pass=".$data['pass'];
$postFields .= "&ttype=".$data['ttype'];
$postFields .= "&prodid=".$data['prodid'];
$postFields .= "&amt=".$data['amt'];
$postFields .= "&txncurr=INR";
$postFields .= "&txnscamt=0";
$postFields .= "&clientcode=".urlencode(base64_encode('123'));
$postFields .= "&txnid=".$data['txnid'];
$postFields .= "&date=".$datenow;
$postFields .= "&custacc=123456789012";
$postFields .= "&udf1=".$data['CustomerName'];
$postFields .= "&udf2=".$data['CustomerEMail'];
$postFields .= "&udf3=".$data['BillingPhone'];
$postFields .= "&udf4=".$data['BillingAddress1'];
$postFields .= "&ru=".$data['ru'];
$sendUrl = $data['action']."?".substr($postFields,1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$data['action']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT , 80);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$returnData = curl_exec($ch);
$parser = xml_parser_create('');
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($returnData), $xml_values);
xml_parser_free($parser);
if(isset($xml_values[3]['value'])=='' || isset($xml_values[4]['value'])=='' || isset($xml_values[5]['value'])=='')
{
$this->redirect($this->url->link('checkout/atomfailure&msg=1'));
}
$returnArray['url'] = $xml_values[3]['value'];
$returnArray['ttype'] = $xml_values[4]['value'];
$returnArray['tempTxnId'] = $xml_values[5]['value'];
$returnArray['token'] = $xml_values[6]['value'];
$url =$returnArray['url'] ;
$postFields = "";
$postFields .= "&ttype=".$returnArray['ttype'] ;
$postFields .= "&tempTxnId=".$returnArray['tempTxnId'];
$postFields .= "&token=".$returnArray['token'] ;
$postFields .= "&txnStage=1";
$url = $url."?".$postFields;
if($returnArray['tempTxnId']=='')
{
$this->redirect($this->url->link('checkout/atomfailure&msg=1'));
}
else
{
header("Location: ".$url);
}
}
public function success() {
if ($this->request->post['f_code'] =='Ok') {
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->request->post['mer_txn'], $this->config->get('config_order_status_id'),"Payment Pending");
$this->model_checkout_order->update($this->request->post['mer_txn'], $this->config->get('atompay_order_status_id'), "Payment Received", false);
$this->redirect($this->url->link('checkout/success'));
}
else
{
$message = "Payment failed";
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->request->post['mer_txn'], $this->config->get('config_order_status_id'),"Payment Pending");
$this->model_checkout_order->update($this->request->post['mer_txn'], $this->config->get('config_order_status_id'), $message, false);
//$this->error['warning'] = "Transaction Denied. Payment failed.";
$this->redirect($this->url->link('checkout/atomfailure'));
}
}
}
?>
和
//catalog/model/payment/atompay.php
<?php
class ModelPaymentAtomPay extends Model {
public function getMethod($address, $total) {
$this->load->language('payment/atompay');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('atompay_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if ($this->config->get('atompay_total') > $total) {
$status = false;
} elseif (!$this->config->get('atompay_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'atompay',
'title' => $this->language->get('text_title'),
'terms' => '',
'sort_order' => $this->config->get('atompay_sort_order')
);
}
return $method_data;
}
}
?>
当我尝试下订单时确认订单被禁用并且没有找到错误日志。我错过了什么吗?
您的 index()
方法定义了 protected
访问权限。所以你不能从它的范围之外调用它。所以你应该把它改成 public function index()
.
我们的 opencart 商店有一个名为 atom 的支付网关。最近我们将 Opencart 从 1.5.6.4 升级到 2.0.1.0 版本。由于这种付款方式停止工作。我经历了this post了解opencart 2.0的变化
下面是我更新的代码
//catalog/controller/payment/atompay.php
<?php
class ControllerPaymentAtompay extends Controller {
protected function index() {
$this->language->load('payment/atompay');
$data['button_confirm'] = $this->language->get('button_confirm');
$data['url2'] = $this->url->link('payment/atompay/dopayment');
$this->session->data['order_id'];
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/atompay.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/payment/atompay.tpl', $data);
} else {
return $this->load->view('default/template/payment/atompay.tpl', $data);
}
//$this->render();
}
public function dopayment() {
$vendor = $this->config->get('atompay_vendor');
$password = $this->config->get('atompay_password');
$data['action'] = $this->config->get('atompay_url');
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$datenow = date("d/m/Y");
$data['BillingCity'] = $order_info['payment_city'];
$data['BillingPostCode'] = $order_info['payment_postcode'];
$data['BillingCountry'] = $order_info['payment_iso_code_2'];
$data['login'] = $this->config->get('atompay_vendor');
$data['pass'] = $this->config->get('atompay_password');
$data['ttype'] = 'NBFundTransfer';
$data['action'] = $this->config->get('atompay_url');
$data['prodid'] = $this->config->get('atompay_prodid');
$data['amt'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
$data['txnid'] = $this->session->data['order_id'];
$data['txndate'] = $datenow;
$data['CustomerName'] = html_entity_decode($order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['CustomerEMail'] = $order_info['email'];
$data['BillingPhone'] = $order_info['telephone'];
$data['BillingAddress1'] = $order_info['payment_address_1']."|".$data['BillingCity']."|".$data['BillingCountry'];
$data['ru'] = $this->url->link('payment/atompay/success');
$postFields = "";
$postFields .= "&login=".$data['login'];
$postFields .= "&pass=".$data['pass'];
$postFields .= "&ttype=".$data['ttype'];
$postFields .= "&prodid=".$data['prodid'];
$postFields .= "&amt=".$data['amt'];
$postFields .= "&txncurr=INR";
$postFields .= "&txnscamt=0";
$postFields .= "&clientcode=".urlencode(base64_encode('123'));
$postFields .= "&txnid=".$data['txnid'];
$postFields .= "&date=".$datenow;
$postFields .= "&custacc=123456789012";
$postFields .= "&udf1=".$data['CustomerName'];
$postFields .= "&udf2=".$data['CustomerEMail'];
$postFields .= "&udf3=".$data['BillingPhone'];
$postFields .= "&udf4=".$data['BillingAddress1'];
$postFields .= "&ru=".$data['ru'];
$sendUrl = $data['action']."?".substr($postFields,1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$data['action']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT , 80);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$returnData = curl_exec($ch);
$parser = xml_parser_create('');
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($returnData), $xml_values);
xml_parser_free($parser);
if(isset($xml_values[3]['value'])=='' || isset($xml_values[4]['value'])=='' || isset($xml_values[5]['value'])=='')
{
$this->redirect($this->url->link('checkout/atomfailure&msg=1'));
}
$returnArray['url'] = $xml_values[3]['value'];
$returnArray['ttype'] = $xml_values[4]['value'];
$returnArray['tempTxnId'] = $xml_values[5]['value'];
$returnArray['token'] = $xml_values[6]['value'];
$url =$returnArray['url'] ;
$postFields = "";
$postFields .= "&ttype=".$returnArray['ttype'] ;
$postFields .= "&tempTxnId=".$returnArray['tempTxnId'];
$postFields .= "&token=".$returnArray['token'] ;
$postFields .= "&txnStage=1";
$url = $url."?".$postFields;
if($returnArray['tempTxnId']=='')
{
$this->redirect($this->url->link('checkout/atomfailure&msg=1'));
}
else
{
header("Location: ".$url);
}
}
public function success() {
if ($this->request->post['f_code'] =='Ok') {
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->request->post['mer_txn'], $this->config->get('config_order_status_id'),"Payment Pending");
$this->model_checkout_order->update($this->request->post['mer_txn'], $this->config->get('atompay_order_status_id'), "Payment Received", false);
$this->redirect($this->url->link('checkout/success'));
}
else
{
$message = "Payment failed";
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->request->post['mer_txn'], $this->config->get('config_order_status_id'),"Payment Pending");
$this->model_checkout_order->update($this->request->post['mer_txn'], $this->config->get('config_order_status_id'), $message, false);
//$this->error['warning'] = "Transaction Denied. Payment failed.";
$this->redirect($this->url->link('checkout/atomfailure'));
}
}
}
?>
和
//catalog/model/payment/atompay.php
<?php
class ModelPaymentAtomPay extends Model {
public function getMethod($address, $total) {
$this->load->language('payment/atompay');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('atompay_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if ($this->config->get('atompay_total') > $total) {
$status = false;
} elseif (!$this->config->get('atompay_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'atompay',
'title' => $this->language->get('text_title'),
'terms' => '',
'sort_order' => $this->config->get('atompay_sort_order')
);
}
return $method_data;
}
}
?>
当我尝试下订单时确认订单被禁用并且没有找到错误日志。我错过了什么吗?
您的 index()
方法定义了 protected
访问权限。所以你不能从它的范围之外调用它。所以你应该把它改成 public function index()
.