Opencart付款需要字段处理问题

时间:2015-11-09 17:01:40

标签: opencart authorize.net

有人可以告诉我Opencart authorizenet_aim验证的位置吗?它似乎在检查cc_number和到期,但我找不到它。

我已使用payment/authorizenet_aim.php数组添加了$json['error']中的错误检查,但仍然弹出alert(),其中显示[object Object]

控制器/付款/ authorizenet_aim.php:

public function send() {
  $json = array();
  $data = array();

  $this->language->load('payment/authorizenet_aim');

  if(isset($this->request->post['cc_owner']) && '' == $this->request-post['cc_owner']) {
    $json['error']['cc_owner'] = $this->language->get('error_cc_owner');
  } else {
      $json['error']['cc_owner'] = '';
  }

  if(isset($this->request->post['cc_number']) && '' == $this->request->post['cc_number']) {
    $json['error']['cc_number'] = $this->language->get('error_cc_number');
  } else {
      $json['error']['cc_number'] = '';
  }

  if(isset($this->request->post['cc_cvv2']) && '' == $this->request->post['cc_cvv2']) {
    $json['error']['cc_cvv2'] = $this->language->get('error_cc_cvv2');
  } else {
    $json['error']['cc_cvv2'] = '';
  }

  if(!isset($json['error']['cc_owner']) && !isset($json['error']['cc_number']) && !isset($json['error']['cc_cvv2'])) {
    ...//curl
  }

  $this->response->setOutput(json_encode($json));
}

模板/支付/ authorizenet_aim.tpl

<script>
  $('#button-confirm').bind('click', function() {
    ...
    success: function() {
      if(json['error']) {
        if(json['error']['cc_owner']) {
          $('input[name=cc_owner]').after('<span class="error">' + json['error']['cc_owner']);
        ...
      }

1 个答案:

答案 0 :(得分:0)

在获得风滚草徽章之后,我想我最好赎回自己并弄清楚这一点。以下是基础知识:

目录/控制器/付款/ authorizenet_aim.php /发送:

$json = array();                                                                                                                    

$this->language->load('payment/authorizenet_aim');                                                                                  

if(!isset($this->request->post['cc_owner']) || '' == $this->request->post['cc_owner']) {                                            
  $json['error']['cc_owner'] = $this->language->get('error_cc_owner');                                                              
}                                                                                                                                   

if(!isset($this->request->post['cc_number']) || '' == $this->request->post['cc_number']) {                                          
  $json['error']['cc_number'] = $this->language->get('error_cc_number');                                                            
}                                                                                                                                   

if(!isset($this->request->post['cc_cvv2']) || '' == $this->request->post['cc_cvv2']) {                                              
  $json['error']['cc_cvv2'] = $this->language->get('error_cc_cvv2');                                                                
}
...
if(!isset($json['error']['cc_owner']) && !isset($json['error']['cc_number']) && !isset($json['error']['cc_cvv2'])) {

  $curl = curl_init($url);
  ...
  curl_close($curl);
}

$this->response->setOutput(json_encode($json));

目录/视图/主题/ mytheme的/模板/付款/ authorizenet_aim.tpl:

$('#button-confirm').bind('click', function() {

  $('span.error').remove();

  $.ajax({

    ...

    success: function() {
      if (json['error']) {

        if(json['error']['cc_owner'] || json['error']['cc_number'] || json['error']['cc_cvv2']) {

          var error_msg = "You have missed some required fields:\n";

          if (json['error']['cc_owner']) {
            $('input[name=cc_owner]').after('<span class="error" style="display:inline-table;margin-left:12px;font-size:small;">' + json['error']['cc_owner']);
            error_msg += "- " + json['error']['cc_owner'] + "\n";
          }

          if (json['error']['cc_number']) {
            $('input[name=cc_number]').after('<span class="error" style="display:inline-table;margin-left:12px;font-size:small;">' + json['error']['cc_number']);
            error_msg += "- " + json['error']['cc_number'] + "\n";
          }

          if (json['error']['cc_cvv2']) {
            $('input[name=cc_cvv2]').after('<span class="error" style="display:inline-table;margin-left:12px;font-size:small;">' + json['error']['cc_cvv2']);
            error_msg += "- " + json['error']['cc_cvv2'] + "\n";
          }

          alert(error_msg);
        } else {
            alert(json['error']);
        }
    }
    ...

我正在研究其他Luhn等,但这是一个好的开始。