如何从authoriz.net获取未结算的交易清单?

时间:2019-02-11 06:14:58

标签: node.js authorize.net

enter image description here

上图显示了authorize.net UI中未结算交易的列表。当我通过getUnsettledTransactionList API调用请求时,收到的结果集为空,为什么?

 "response": {
        "messages": {
            "resultCode": "Ok",
            "message": [
                {
                    "code": "I00004",
                    "text": "No records found."
                }
            ]
        },
        "totalNumInResultSet": 0
    }

我正在使用Authorize.net和NodeJs中的沙箱帐户基于以下代码进行开发

https://developer.authorize.net/api/reference/index.html#transaction-reporting-get-unsettled-transaction-list

这是我的代码

function getUnsettledTransactionList() {

    var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();
    merchantAuthenticationType.setName( process.env.SERVICE_CREDITCARD_API_APILOGINKEY );
    merchantAuthenticationType.setTransactionKey( process.env.SERVICE_CREDITCARD_API_TRANSACTIONKEY );

    var getRequest = new ApiContracts.GetUnsettledTransactionListRequest();

    getRequest.setMerchantAuthentication(merchantAuthenticationType);
    getRequest.setStatus(ApiContracts.TransactionGroupStatusEnum.PENDINGAPPROVAL);

    //keeping promise resolve and reject funcs outside the promise scope
    var promiseResolve, promiseReject;

    var promise = new Promise( (_resolve, _reject)=>{
        promiseResolve = _resolve;
        promiseReject = _reject;
    });

    var ctrl = new ApiControllers.GetUnsettledTransactionListController(getRequest.getJSON());

    ctrl.execute(function(){

        var apiResponse = ctrl.getResponse();
        var response = new ApiContracts.GetUnsettledTransactionListResponse(apiResponse);

        if(response != null){
            if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){

                var result = { 
                    message: response.getMessages().getMessage()[0].getText(),
                    messageCode: response.getMessages().getMessage()[0].getCode(),
                    transactions: [],
                    status: true,
                    response: response
                }

                if(response.getTransactions() != null)
                    result.transactions = response.getTransactions().getTransaction();                

                promiseResolve( result );
            }
            else{
                promiseReject({
                    resultCode: response.getMessages().getResultCode(),
                    errorCode: response.getMessages().getMessage()[0].getCode(),
                    errorMessage: response.getMessages().getMessage()[0].getText(),
                    status: false,
                    response: response
                });
            }
        }
        else{
            promiseReject( { message: 'Null Response.', status: false } );
        }

    });

    return promise;
}

1 个答案:

答案 0 :(得分:1)

您不应该为交易设置状态,请删除此行代码。

    getRequest.setStatus(ApiContracts.TransactionGroupStatusEnum.PENDINGAPPROVAL);

如果您在请求中添加此字段,则只会得到待批准的交易,并且可能没有待批准的交易,因此您将得到一个空列表。