授权PHP API Charge信用卡示例返回空响应

时间:2016-05-05 04:07:46

标签: php xml credit-card authorize.net

我正在使用authorize.net网站上的php示例,但无法使其工作。我已经下载了所有供应商软件和更新的作曲家。

在phplog中我不断收到同样的错误:

<code>E00045</code>
<text>The root node does not reference a valid XML namespace.</text>
</message></messages></ErrorResponse>

更新作曲家后,不再记录错误。

我的php:

require("anetsdkphp/autoload.php");
$logName = "MYAUTHKEY";
$transKey = "MYTRANSKEY";
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function chargeCreditCard($amount){
      // Common setup for API credentials
      $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
      $merchantAuthentication->setName($logName);
      $merchantAuthentication->setTransactionKey($transKey);
      $refId = 'ref' . time();
      // Create the payment data for a credit card
      $creditCard = new AnetAPI\CreditCardType();
      $creditCard->setCardNumber(4111111111111111);
      $creditCard->setExpirationDate(1238);
      $paymentOne = new AnetAPI\PaymentType();
      $paymentOne->setCreditCard($creditCard);
      //create a transaction
      $transactionRequestType = new AnetAPI\TransactionRequestType();
      $transactionRequestType->setTransactionType( "authCaptureTransaction"); 
      $transactionRequestType->setAmount($amount);
      $transactionRequestType->setPayment($paymentOne);
      $request = new AnetAPI\CreateTransactionRequest();
      $request->setMerchantAuthentication($merchantAuthentication);
      $request->setRefId($refId);
      $request->setTransactionRequest($transactionRequestType);
      $controller = new AnetController\CreateTransactionController($request);
      $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

      #$result = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"',
 '', $result);

      if ($response != null)
      {
        $tresponse = $response->getTransactionResponse();
        if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )   
        {
          echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
          echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
          echo $tresponse->getResponseCode();
        }
        else
        {
            echo  "Charge Credit Card ERROR :  Invalid response\n";
            var_dump("$tresponse");
        }

      }
      else
      {
        echo  "Charge Credit card Null response returned";
      }
  }
chargeCreditCard(55.00);

回复:

Charge Credit Card ERROR : Invalid response(0)
更新作曲家后的响应:
Charge Credit Card ERROR : Invalid response

非常感谢!

1 个答案:

答案 0 :(得分:1)

您的留言有点旧,我相信已经解决了。但是,问题几乎肯定是您的输入数据。这个答案非常含糊,不一定能提供解决方案,但它可以帮助您确定原因。

print_r($response)

您将看到以下对象表示:

[messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => net\authorize\api\contract\v1\MessagesType Object ( [resultCode:net\authorize\api\contract\v1\MessagesType:private] => Error [message:net\authorize\api\contract\v1\MessagesType:private] => Array ( [0] => net\authorize\api\contract\v1\MessagesType\MessageAType Object ( [code:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => ERROR_CODE_IS_HERE [text:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => ERROR_MESSAGE_IS_HERE)