获取4位数的信用卡号Authorize.net

时间:2018-05-08 17:17:28

标签: c# asp.net payment-gateway 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";

我正在检索如下图像的数据但是能够获得信用卡详细信息

enter image description here

我只想检索授权的信用卡明细。任何帮助

在我的代码中,我还添加了如下代码,但我收到错误

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”。

1 个答案:

答案 0 :(得分:2)

信用卡的最后四位数字位于回复的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."
         }
      ]
   }
}