Codeigniter My_payment Authorize.net图书馆。如何发送发票号码?

时间:2013-03-22 22:00:36

标签: php codeigniter e-commerce authorize.net

我使用authorize.net my_payment.php库为codeigniter为我的一个客户的网站进行authorize.net付款。他们刚刚来找我,要求通过authorize.net付款发送他们的发票号码。我试图将'invoice_number' => $orderNumber添加到它发送的参数中,但它不起作用。

有关如何使用付款在authorize.net中记录发票号的任何想法?

以下是my_payment库:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    /*
    |--------------------------------------------------------------------------
    | Authorize.net Payment Module
    |--------------------------------------------------------------------------
    |
    | Just add the following config to your application/config/config.php file
    |
    | $config['at_login']   = "xxxxxxxxxx"; //your login
    | $config['at_password']    = "xxxxxxxxxxxx"; //your transaction key
    | $config['at_test']    = 1; //Set to 0 for live transactions
    | $config['at_debug']   = 1; //Set to 0 for live transactions
    | $config['at_site'] = 'https://test.authorize.net/gateway/transact.dll'; //comment for live trans
    | //$config['at_site'] = 'https://secure.authorize.net/gateway/transact.dll'; //uncomment for live trans
    |
    |   Call it by doing this:
    |
    |       $this->load->library('my_payment');
    |       $params->cc = '1293081309812039812039' ;//etc... you get the idea
    |       
    |       $result = $this->my_payment->authorize($params);
    |       print_r($result); //response codes from authorize.net
    |
    |
    |
    */

    class My_payment {

        public function Authorize($params)
        {
            $CI =& get_instance();

            $x_Login = $CI->config->item('at_login');     
            $x_Password = $CI->config->item('at_password');

            $DEBUGGING                  = $CI->config->item('at_debug');
            $TESTING                    = $CI->config->item('at_test'); 
            $ERROR_RETRIES              = 2;

            $auth_net_url               = $CI->config->item('at_site');

            $authnet_values             = array
            (
                "x_login"               => $x_Login,
                "x_version"             => "3.1",
                "x_delim_char"          => "|",
                "x_delim_data"          => "TRUE",
                "x_type"                => "AUTH_CAPTURE",
                "x_method"              => "CC",
                "x_tran_key"            => $x_Password,
                "x_relay_response"      => "FALSE",
                "x_card_num"            => $params->cc,
                "x_exp_date"            => $params->exp,
                "x_description"         => $params->desc,
                "x_amount"              => $params->amount,
                "x_first_name"          => $params->firstName,
                "x_last_name"           => $params->lastName,
                "x_address"             => $params->address,
                "x_city"                => $params->city,
                "x_state"               => $params->state,
                "x_zip"                 => $params->zip,
                "SpecialCode"           => $params->specialCode,
            );

            $fields = "";
            foreach( $authnet_values as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";

            $ch = curl_init($auth_net_url);

            curl_setopt($ch, CURLOPT_HEADER, 0); 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " ));

            $result = curl_exec($ch);

            curl_close ($ch);

            return $result;

        }
    }
    /* End of file My_payment.php */
    /* Location: ./system/application/libraries/My_payment.php */

以下是我发送付款的代码:

    //Process via Authorize.net
            //Load the authorize.net payment library
            $this->load->library('my_payment');
            $params = new stdClass();
            //Process the transaction
            $params->cc = $_POST['finalCardNumber'];
            $params->exp = $_POST['finalExpMonth'].'/'.$_POST['finalExpYear'];
            $params->desc = 'Stoles.com Order';
            $params->amount = $_POST['finalGrandTotal'];
            $params->firstName = $_POST['finalBillingFirstName'];
            $params->lastName = $_POST['finalBillingLastName'];
            $params->address = $_POST['finalBillingAddress'];
            $params->city = $_POST['finalBillingCity'];
            $params->state = $_POST['finalBillingState'];
            $params->zip = $_POST['finalBillingZipcode'];
            $params->specialCode = $_POST['finalCardCode'];
            $params->invoice_number = $orderNumber;

            $result = $this->my_payment->authorize($params);

            $authres = str_split($result);

1 个答案:

答案 0 :(得分:1)

只是向params添加一个额外的值不会使请求实际发送该值,因为该类显然只发送$authnet_values中指定的参数。

在这种情况下,您需要修改$authnet_values以在授权请求中传递其他参数x_invoice_num