![](/img/trans.png)
[英]Authorize.Net In-Person SDK: Unable to refund a credit card transaction; charges a new transaction instead
[英]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.