php - 授权 PHP API Charge Credit Card Example 返回空响应

标签 php xml credit-card authorize.net

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

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

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

更新 Composer 后不再记录错误。

我的 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)
更新 Composer 后的响应:
Charge Credit Card ERROR : Invalid response

非常感谢!

最佳答案

您的消息有点旧,我确定已经解决了。但是,问题几乎肯定是您的输入数据。这个答案非常模糊,不一定会提供解决方案,但它会帮助您找出原因。

print_r($response)

您将看到以下对象表示:

[messages:net\authorize\api\contract\v1\ANetApiResponseType:private] => net\authorize\api\contract\v1\MessagesType 对象 ( [resultCode:net\authorize\api\contract\v1\MessagesType:private] => 错误 [message:net\authorize\api\contract\v1\MessagesType:private] => 数组 ( [0] => net\authorize\api\contract\v1\MessagesType\MessageAType 对象 ( [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)

关于php - 授权 PHP API Charge Credit Card Example 返回空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37042174/

相关文章:

php - 我们可以在 controller laravel 中使用 helper 吗?

PHP 搜索显示多个结果

phpMyAdmin - 错误 |缺少 mbstring 扩展名。请检查您在 Ubuntu 14.04 LTS 中的 PHP 配置

php - 如何在表中插入文件名、标题以及将文件上传到服务器

php - XML 不间断空格

python - 使用 txt 文件中的多个根元素创建 xml

javascript - 使用javascript获取完整的信用卡数据

java - 如何将 json 响应与 XML 值进行比较?

html - html5 localStorage 中的信用卡号

android 信用卡扫描库或任何 API(Card.io 除外)