1

authorize.net CIM を使用してアプリケーションを作成しました。テストモードでアプリを使用すると、すべて正常に動作します。テスト モードからライブ モードに切り替えて、正しいユーザー ID とトランザクション キーを貼り付けると、次のように表示されます: API ユーザー名が無効であるか存在しません。

意味がない。API ユーザー名とトランザクション キーが正しいことは 100% です。

CIM codeigniter ライブラリを使用しています。CIMのセットアップと初期化を扱うコードは次のとおりです...

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
By: Spicer Matthews <spicer@cloudmanic.com>
Company: Cloudmanic Labs, LLC
Website: http://www.cloudmanic.com

Based On Work From: 
- John Conde <johnny@johnconde.net>
- http://www.communitymx.com/content/article.cfm?page=4&cid=FDB14
*/

class AuthorizeCimLib
{
    private $_CI; 
    private $_loginname;
    private $_loginkey;
    private $_response;
    private $_resultCode;
    private $_responseCode;
    private $_responseText;
    private $_success;
    private $_error;
    private $_url;
    private $_parsedresponse;
    private $_xml;
    private $_call;
    private $_responsecall;
    private $_directresponse;
    private $_items = array();
    private $_params = array();
    private $_validationmode = 'liveMode';
    private $_errormsg = '';
    private $_loginhost = 'api.authorize.net';
    private $_testhost = 'apitest.authorize.net';
    private $_loginpath = '/xml/v1/request.api';

    //
    // Construct..... 
    //
    function __construct()
    {
        $this->_CI =& get_instance();
        $this->_set_url();
        $this->_set_default_params();

        // If the config is setup properly use that to initialize
        $this->_CI->config->load('authorizenet');

        if($this->_CI->config->item('authorizenetname') && 
                $this->_CI->config->item('authorizenetkey') &&
                $this->_CI->config->item('authorizenettestmode'))
        {
            $this->initialize($this->_CI->config->item('authorizenetname'), $this->_CI->config->item('authorizenetkey'), $this->_CI->config->item('authorizenettestmode'));
        }

        log_message('debug', "AuthorizeCimLib Class Initialized");
    }

    //
    // Call this function to setup the library variables. Such as API keys.
    //
    public function initialize($name, $key, $testmode = FALSE)
    {
        // Are we in test mode??
        if($testmode)
        {
            $this->_set_testmode();
        }

        // Setup login names and keys.
        $this->_loginname = $name;
        $this->_loginkey = $key;
    }

    //
    // Set validation mode.
    //
    public function set_validationmode($mode)
    {
        $types = array('none', 'testMode', 'liveMode', 'oldLiveMode');

        if(in_array($mode, $types))
        {
            $this->_validationmode = $mode;
            return 1;
        } 
        else
        {
            log_message('debug', "AuthorizeCimLib Not A Valid Test Mode");
            return 0;
        }
    }

    //
    // Get validation mode.
    //
    public function get_validationmode()
    {
        return $this->_validationmode;
    }

    //
    // Set Parameters to send to Authorize.net
    //
    public function set_data($field, $value)
    {
        $this->_params[$field] = $value;
    }

    //
    // C;ear Parameters data
    //
    public function clear_data()
    {
        $this->_params = array();
        $this->_set_default_params();
    }
4

1 に答える 1

0

何時間も髪を抜いた後、ついにこれを理解しました!

__constructライブラリ クラスの if ステートメント ロジックにいくつかのエラーがあります。何が起こるかというと、構成オプションをチェックするときに、テストモードがに設定されてFALSEいる場合、初期化されません... FALSEif ステートメントに値を渡すためです (これは私のファイルの 49 行目あたりで発生します)。それを修正するためにできることは、その「テスト モード」チェックを if ステートメントから削除することです。

これは次のようになります。

if($this->_CI->config->item('authorizenetname') && $this->_CI->config->item('authorizenetkey'))
{
    $this->initialize($this->_CI->config->item('authorizenetname'), $this->_CI->config->item('authorizenetkey'), $this->_CI->config->item('authorizenettestmode'));
}

この答えがゲームの後半にあることは知っていますが、役に立てば幸いです。

于 2013-09-24T19:52:24.583 に答える