1

有没有人在这个主题上建立过任何东西?Authorize.Net 是使用最广泛的支付网关之一,因此我认为这种集成会有最佳实践和/或可靠资源。我无法从搜索中找到任何可靠的东西。非常感谢任何建议/资源/建议。“分享就是关怀”

4

1 回答 1

1

Paypal 和 Authorize.net 的 API 非常简单。您实际上并不需要使用 Zend 特定的方法在 Zend 应用程序中设置它们。基于 Zend 构建的 Magento 有一个 Authorize.net 连接,你可以看一下。Opencart 是另一个具有 Authorize.net 插件的开源购物车。我看过了,它写得体面,易于理解。

编辑:这是来自 Opencart 的 Authorize.net AIM 课程(他们也有 SIM 版本)。您应该可以很容易地以此为基础制作自己的作品。

class ControllerPaymentAuthorizeNetAim extends Controller {
    protected function index() {
        $this->language->load('payment/authorizenet_aim');

        $this->data['text_credit_card'] = $this->language->get('text_credit_card');
        $this->data['text_wait'] = $this->language->get('text_wait');

        $this->data['entry_cc_owner'] = $this->language->get('entry_cc_owner');
        $this->data['entry_cc_number'] = $this->language->get('entry_cc_number');
        $this->data['entry_cc_expire_date'] = $this->language->get('entry_cc_expire_date');
        $this->data['entry_cc_cvv2'] = $this->language->get('entry_cc_cvv2');

        $this->data['button_confirm'] = $this->language->get('button_confirm');

        $this->data['months'] = array();

        for ($i = 1; $i <= 12; $i++) {
            $this->data['months'][] = array(
                'text'  => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)), 
                'value' => sprintf('%02d', $i)
            );
        }

        $today = getdate();

        $this->data['year_expire'] = array();

        for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
            $this->data['year_expire'][] = array(
                'text'  => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
                'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)) 
            );
        }

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/authorizenet_aim.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/payment/authorizenet_aim.tpl';
        } else {
            $this->template = 'default/template/payment/authorizenet_aim.tpl';
        }   

        $this->render();        
    }

    public function send() {
        if ($this->config->get('authorizenet_aim_server') == 'live') {
            $url = 'https://secure.authorize.net/gateway/transact.dll';
        } elseif ($this->config->get('authorizenet_aim_server') == 'test') {
            $url = 'https://test.authorize.net/gateway/transact.dll';       
        }   

        //$url = 'https://secure.networkmerchants.com/gateway/transact.dll';    

        $this->load->model('checkout/order');

        $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

        $data = array();

        $data['x_login'] = $this->config->get('authorizenet_aim_login');
        $data['x_tran_key'] = $this->config->get('authorizenet_aim_key');
        $data['x_version'] = '3.1';
        $data['x_delim_data'] = 'true';
        $data['x_delim_char'] = ',';
        $data['x_encap_char'] = '"';
        $data['x_relay_response'] = 'false';
        $data['x_first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
        $data['x_last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
        $data['x_company'] = html_entity_decode($order_info['payment_company'], ENT_QUOTES, 'UTF-8');
        $data['x_address'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
        $data['x_city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
        $data['x_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
        $data['x_zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
        $data['x_country'] = html_entity_decode($order_info['payment_country'], ENT_QUOTES, 'UTF-8');
        $data['x_phone'] = $order_info['telephone'];
        $data['x_customer_ip'] = $this->request->server['REMOTE_ADDR'];
        $data['x_email'] = $order_info['email'];
        $data['x_description'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
        $data['x_amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], 1.00000, false);
        $data['x_currency_code'] = $this->currency->getCode();
        $data['x_method'] = 'CC';
        $data['x_type'] = ($this->config->get('authorizenet_aim_method') == 'capture') ? 'AUTH_CAPTURE' : 'AUTH_ONLY';
        $data['x_card_num'] = str_replace(' ', '', $this->request->post['cc_number']);
        $data['x_exp_date'] = $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'];
        $data['x_card_code'] = $this->request->post['cc_cvv2'];
        $data['x_invoice_num'] = $this->session->data['order_id'];

        /* Customer Shipping Address Fields */
        $data['x_ship_to_first_name'] = html_entity_decode($order_info['shipping_firstname'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_last_name'] = html_entity_decode($order_info['shipping_lastname'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_company'] = html_entity_decode($order_info['shipping_company'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_address'] = html_entity_decode($order_info['shipping_address_1'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['shipping_address_2'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_city'] = html_entity_decode($order_info['shipping_city'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_state'] = html_entity_decode($order_info['shipping_zone'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_zip'] = html_entity_decode($order_info['shipping_postcode'], ENT_QUOTES, 'UTF-8');
        $data['x_ship_to_country'] = html_entity_decode($order_info['shipping_country'], ENT_QUOTES, 'UTF-8');

        if ($this->config->get('authorizenet_aim_mode') == 'test') {
            $data['x_test_request'] = 'true';
        }   

        $curl = curl_init($url);

        curl_setopt($curl, CURLOPT_PORT, 443);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));

        $response = curl_exec($curl);

        $json = array();

        if (curl_error($curl)) {
            $json['error'] = 'CURL ERROR: ' . curl_errno($curl) . '::' . curl_error($curl);

            $this->log->write('AUTHNET AIM CURL ERROR: ' . curl_errno($curl) . '::' . curl_error($curl));   
        } elseif ($response) {
            $i = 1;

            $response_info = array();

            $results = explode(',', $response);

            foreach ($results as $result) {
                $response_info[$i] = trim($result, '"');

                $i++;
            }

            if ($response_info[1] == '1') {
                if (strtoupper($response_info[38]) == strtoupper(md5($this->config->get('authorizenet_aim_hash') . $response_info[6] . $this->currency->format($order_info['total'], $order_info['currency_code'], 1.00000, false)))) {
                    $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));

                    $message = '';

                    if (isset($response_info['5'])) {
                        $message .= 'Authorization Code: ' . $response_info['5'] . "\n";
                    }

                    if (isset($response_info['6'])) {
                        $message .= 'AVS Response: ' . $response_info['6'] . "\n";
                    }

                    if (isset($response_info['7'])) {
                        $message .= 'Transaction ID: ' . $response_info['7'] . "\n";
                    }

                    if (isset($response_info['39'])) {
                        $message .= 'Card Code Response: ' . $response_info['39'] . "\n";
                    }

                    if (isset($response_info['40'])) {
                        $message .= 'Cardholder Authentication Verification Response: ' . $response_info['40'] . "\n";
                    }               

                    $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('authorizenet_aim_order_status_id'), $message, false);             
                }

                $json['success'] = $this->url->link('checkout/success', '', 'SSL');
            } else {
                $json['error'] = $response_info[4];
            }
        } else {
            $json['error'] = 'Empty Gateway Response';

            $this->log->write('AUTHNET AIM CURL ERROR: Empty Gateway Response');
        }

        curl_close($curl);

        $this->response->setOutput(json_encode($json));
    }
}
于 2012-11-26T22:36:46.873 回答