authorize.net hello world Charge Credit Card ERROR : Invalid response

authorize.net hello world Charge Credit Card ERROR : Invalid response

正在尝试让 Authorize.net 的 Hello World 示例正常工作

这里安装的 Composer 是 json。几乎与他们的示例相同。

{
"require": {
    "symfony/console": "^3.3",
    "php": ">=5.6",
    "ext-curl": "*",
    "authorizenet/authorizenet": ">=1.9.3"    
}
}

以下是从 ssh 中剪切和粘贴的

>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files

我在 Hello World PHP 示例中唯一更改的是我的沙箱登录 ID 和事务密钥以及 vendor/autoload.php 的路径。

我在这里遗漏了什么才能将这个例子变成 return 除了

以外的东西

信用卡收费错误:响应无效

这个问题的解决方法很简单。在此处发布解决方案以进行支付。首先,这是基本工作所需的一切 composer.json

{
"require": {
    "symfony/console": "^3.3",
    "authorizenet/authorizenet": ">=1.9.3"    
}
}

您可能甚至不需要交响乐。顺便说一句,我是运行 php 5.6和TLS 1.2,这是必需的。

其次,示例代码中存在范围问题。这是信用卡收费示例代码的前几行,它在 authorize.net 浏览器沙箱中运行良好。

function chargeCreditCard($amount)
{

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

这是我在 php 脚本中将其更改为无效的内容。

    function chargeCreditCard(){

    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName($AuthorizeLoginID);
    $merchantAuthentication->setTransactionKey($AuthorizeTransKey); 

这是我将其更改为有效的内容。

    function chargeCreditCard(){

    global $AuthorizeLoginID, $AuthorizeTransKey;

    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName($AuthorizeLoginID);
    $merchantAuthentication->setTransactionKey($AuthorizeTransKey); 

我有点生自己的气,因为我没有早点看到凭据的范围问题,但我最终通过消除过程解决了这个问题。