【问题标题】:How can I get object values from authorize .net payment getway response如何从授权 .net 支付网关响应中获取对象值
【发布时间】:2016-12-21 13:09:08
【问题描述】:

authorize.net 示例代码以以下两种方法给出响应。

echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";

我希望所有具有类名的方法都打印完整的响应

【问题讨论】:

    标签: payment-gateway authorize.net


    【解决方案1】:

    你现在可能已经想通了。但我正在为所有看到这个问题的人发布我的解决方案。 我创建了一个数组来分解 $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"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-04
      • 2023-03-19
      • 2022-01-14
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      相关资源
      最近更新 更多