簡體   English   中英

獲取4位數字的信用卡號Authorize.net

[英]Get 4 digit credit card number Authorize.net

嗨,我發現一個示例代碼要求傳遞ApiLoginID,ApiTransactionKey和transactionId。

我能夠獲取ApiLoginID和ApiTransactionKey,但如何獲取測試transactionID,如在測試模式下authorize.net始終將transactionid設置為0

以下是我需要通過其檢索信用卡號的代碼。 請建議這是真實代碼還是不檢索信用卡詳細信息?

public class GetTransactionDetails
{
    public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string transactionId)
  {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        Console.WriteLine("Get transaction details sample");

      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
      // define the merchant information (authentication / transaction id)
      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
      {
          name = ApiLoginID,
          ItemElementName = ItemChoiceType.transactionKey,
          Item = ApiTransactionKey,
      };

      var request = new getTransactionDetailsRequest();
      request.transId = transactionId;

      // instantiate the controller that will call the service
      var controller = new getTransactionDetailsController(request);
      controller.Execute();

      // get the response from the service (errors contained if any)
      var response = controller.GetApiResponse();

      if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
      {
          if (response.transaction == null)
              return response;

          Console.WriteLine("Transaction Id: {0}", response.transaction.transId);
          Console.WriteLine("Transaction type: {0}", response.transaction.transactionType);
          Console.WriteLine("Transaction status: {0}", response.transaction.transactionStatus);
          Console.WriteLine("Transaction auth amount: {0}", response.transaction.authAmount);
          Console.WriteLine("Transaction settle amount: {0}", response.transaction.settleAmount);
      }
      else if (response != null)
      {
          Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                            response.messages.message[0].text);
      }

      return response;
   }
 }
}

在示例代碼中,我正在通過憑證以下

const string apiLoginId = "5KP3u95bQpv";
const string transactionKey = "346HZ32z3fP4hTG2";
const string transactionId = "2249735976";

我在哪里檢索數據如下圖,但尼特能夠獲得信用卡詳細信息

在此處輸入圖片說明

我只想檢索信用卡詳細信息以進行授權。 任何幫助

在我的代碼中,我還添加了以下代碼,但收到錯誤

var obj = (creditCardMaskedType)response.transaction.payment.Item;
Console.WriteLine("Creditcard settle cardnumber: {0}", obj.cardNumber);

錯誤

附加信息:無法將類型為“ AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType”的對象轉換為類型為“ AuthorizeNet.Api.Contracts.V1.creditCardMaskedType”的對象。

信用卡的后四位位於響應的transaction > payment > creditcard > cardnumber部分。 您應該可以使用response.transaction.payment.creditCard.cardNumber進行訪問。

供您參考,這是來自getTransactionDetails API調用的示例響應。 這應該向您顯示結構,並更好地了解如何獲取所需的數據。

{  
   "transaction":{  
      "transId":"2162566217",
      "submitTimeUTC":"2011-09-01T16:30:49.39Z",
      "submitTimeLocal":"2011-09-01T10:30:49.39",
      "transactionType":"authCaptureTransaction",
      "transactionStatus":"settledSuccessfully",
      "responseCode":1,
      "responseReasonCode":1,
      "responseReasonDescription":"Approval",
      "authCode":"JPG9DJ",
      "AVSResponse":"Y",
      "batch":{  
         "batchId":"1221577",
         "settlementTimeUTC":"2011-09-01T16:38:54.52Z",
         "settlementTimeUTCSpecified":true,
         "settlementTimeLocal":"2011-09-01T10:38:54.52",
         "settlementTimeLocalSpecified":true,
         "settlementState":"settledSuccessfully"
      },
      "order":{  
         "invoiceNumber":"60",
         "description":"Auto-charge for Invoice #60"
      },
      "requestedAmountSpecified":false,
      "authAmount":1018.88,
      "settleAmount":1018.88,
      "prepaidBalanceRemainingSpecified":false,
      "taxExempt":false,
      "taxExemptSpecified":true,
      "payment":{  
         "creditCard":{  
            "cardNumber":"XXXX4444",
            "expirationDate":"XXXX",
            "cardType":"MasterCard"
         }
      },
      "customer":{  
         "typeSpecified":false,
         "id":"4"
      },
      "billTo":{  
         "phoneNumber":"(619) 274-0494",
         "firstName":"Matteo",
         "lastName":"Bignotti",
         "address":"625 Broadway\nSuite 1025",
         "city":"San Diego",
         "state":"CA",
         "zip":"92101",
         "country":"United States"
      },
      "recurringBilling":false,
      "recurringBillingSpecified":true,
      "product":"Card Not Present",
      "marketType":"eCommerce"
   },
   "messages":{  
      "resultCode":"Ok",
      "message":[  
         {  
            "code":"I00001",
            "text":"Successful."
         }
      ]
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM