authorize.net示例代码给出了以下两种方法的响应。
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
我希望所有带有类名的方法都能打印完整的响应
答案 0 :(得分:0)
你可能现在已经弄明白了。但我会为所有看到这个问题的人发布我的解决方案。 我创建了一个数组,以便分解$ tresponse对象。
if ($response != null){
$tresponse = $response->getTransactionResponse();
$result = array(
'response' => ($response != null)? true: false,
'getResultCode' => $response->getMessages()->getResultCode(),
'getMessages' => ($response->getTransactionResponse()->getMessages() != null)? array(
'msjCode' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
'msjDesc' => $response->getTransactionResponse()->getMessages()[0]->getDescription()
): null,
'getResponseCode' => ($tresponse->getResponseCode() != null)? $tresponse->getResponseCode(): null,
'getAuthCode' => ($tresponse->getAuthCode() != null)? $tresponse->getAuthCode(): null,
'getTransId' => ($tresponse->getTransId() != null)? $tresponse->getTransId(): null,
'messageCode' => ($tresponse->getMessages() != null)? $tresponse->getMessages()[0]->getCode(): null,
'msgDescription' => ($tresponse->getMessages() != null)? $tresponse->getMessages()[0]->getDescription(): null,
'transactionResponseErrors' => ($tresponse->getErrors() != null)? array(
'errorText' => $tresponse->getErrors()[0]->getErrorText(),
'errorCode' => $tresponse->getErrors()[0]->getErrorCode()
): null,
'getErrorCode' => ($tresponse->getErrors() != null)? $tresponse->getErrors()[0]->getErrorCode(): null,
'getErrorText' => ($tresponse->getErrors() != null)? $tresponse->getErrors()[0]->getErrorText(): null,
'userCardNumber' => $userCardNumber,
'userCardExpMonth' => $userCardExpMonth,
'userCardExpYear' => $userCardExpYear
);
}else{
$tresponse = $response->getTransactionResponse();
$result = array(
'response' => ($response != null)? true: false,
'transactionResponseErrors' => ($tresponse->getErrors() != null)? array(
'errorText' => $tresponse->getErrors()[0]->getErrorText(),
'errorCode' => $tresponse->getErrors()[0]->getErrorCode()
): null,
'getErrorCode' => ($tresponse->getErrors() != null)? $tresponse->getErrors()[0]->getErrorCode(): null,
'getErrorText' => ($tresponse->getErrors() != null)? $tresponse->getErrors()[0]->getErrorText(): null,
'messageCode' => ($response->getMessages()->getMessage() != null)? $response->getMessages()->getMessage()[0]->getCode(): null,
'messageText' => ($response->getMessages()->getMessage() != null)? $response->getMessages()->getMessage()[0]->getText(): null
);
}
echo json_encode($result);
生成的json对象如下所示:
{
"response": true,
"getResultCode": "Error",
"getMessages": null,
"getResponseCode": "3",
"getAuthCode": null,
"getTransId": "0",
"messageCode": null,
"msgDescription": null,
"transactionResponseErrors": {
"errorText": "The credit card number is invalid.",
"errorCode": "6"
},
"getErrorCode": "6",
"getErrorText": "The credit card number is invalid.",
"userCardNumber": "\t44444",
"userCardExpMonth": "12",
"userCardExpYear": "2018"
}