C# 获取4位数的信用卡号Authorize.net
您好,我发现了一个示例代码,其中要求传递ApiLoginID、ApiTransactionKey和transactionId 我可以获取ApiLoginID和ApiTransactionKey,但如何获取测试模式下的测试transactionID authorize.net始终将transactionID设置为0 下面是我需要检索信用卡号的代码。请建议这是真实代码还是不检索信用卡详细信息C# 获取4位数的信用卡号Authorize.net,c#,asp.net,payment-gateway,authorize.net,C#,Asp.net,Payment Gateway,Authorize.net,您好,我发现了一个示例代码,其中要求传递ApiLoginID、ApiTransactionKey和transactionId 我可以获取ApiLoginID和ApiTransactionKey,但如何获取测试模式下的测试transactionID authorize.net始终将transactionID设置为0 下面是我需要检索信用卡号的代码。请建议这是真实代码还是不检索信用卡详细信息 public class GetTransactionDetails { public static
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;
}
}
}
我正在检索下图中的数据,但无法获取信用卡详细信息
我只想检索信用卡详细信息以进行授权。有什么帮助吗
在我的代码中,我也添加了如下代码,但我收到了错误
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”。信用卡的最后四位数字位于响应的
交易>支付>信用卡>卡号部分。您应该能够通过响应、交易、支付、信用卡、卡号访问
以下是来自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."
}
]
}
}
您是否无法获取值“0”@请查看已更新的玩家question@theMayer知道吗?不,我不知道你想做什么。您试图获取的内容似乎与您发布的代码完全不一致。您能否至少链接到您正在查看的示例api文档的一部分?这里您已经编写了响应,但请求应该是什么?请求可能与我在问题中所写的相同,也可能不同?您的请求已经正确,否则您将无法得到响应。我的交易状态为“已拒绝”,因此可能是因为交易id不正确。正当我需要通过livemode凭证来检查实际细节。对的因为当我在测试模式下进行测试时,我总是收到事务id,因为0您使用的是沙箱帐户吗?还是处于测试模式的生产帐户?两者之间有区别。在沙盒中,您将在进行测试事务时获得事务ID。我已在沙盒中创建了事务ID,但始终能够将事务ID检索为0
{
"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."
}
]
}
}