【发布时间】:2019-05-25 16:24:32
【问题描述】:
我正在尝试在 Laravel 项目中实现 Authorize.net webhook。从商家界面,我添加了一个 webhook 端点。但是当我尝试检索事件时,它会抛出无效的 JSON 错误。我在下面的代码中做错了什么?
namespace App\Http\Controllers\Api\Anet;
use Illuminate\Http\Request;
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
use App\Http\Controllers\Controller;
use JohnConde\Authnet\AuthnetWebhook;
class xxxController extends Controller
{
public function webhook(){
$headers = getallheaders();
$payload = file_get_contents("php://input");
$webhook = new AuthnetWebhook(hex2bin('XXXXXD4FF0A6060E23DBCD9AE507E20XXXXX'), $payload, $headers);
if ($webhook->isValid()) {
// Get the transaction ID
$transactionId = $webhook->payload->id;
// Here you can get more information about the transaction
$request = AuthnetApiFactory::getJsonApiHandler('services.authorize.login', 'services.authorize.key');
$response = $request->getTransactionDetailsRequest(array(
'transId' => $transactionId
));
/* You can put these response values in the database or whatever your business logic dictates.
$response->transaction->transactionType
$response->transaction->transactionStatus
$response->transaction->authCode
$response->transaction->AVSResponse
*/
}
}
}
错误:
"message": "Invalid JSON sent in the Webhook notification",
"exception": "JohnConde\\Authnet\\AuthnetInvalidJsonException",
"file": "/var/www/html/staging/vendor/stymiee/authnetjson/src/authnet/AuthnetWebhook.php",
"line": 67,
【问题讨论】:
-
$payload的值是多少? -
您能否发布第 67 行或突出显示这是哪一行?似乎不完整,没有它就很难给出建议。猜测这些让我感到紧张。我会尝试输出请求的响应,而不是调用任何期望有效 JSON 的东西来查看我得到的输出,然后从那里找出原因。
-
如果你能做一个
var_dump($payload);来向我们展示 JSON 的样子,这会很有帮助。 -
@JohnConde file_get_contents("php://input");返回空值。
-
@weaver 那么这显然是问题所在。构造函数期望该参数包含有效的 JSON,而不是空值。你需要弄清楚为什么触发 webhook 的东西没有发送 json
标签: php laravel payment-gateway authorize.net authorize.net-webhooks