Hello everyone, I am new to testing the Auth sandbox API, I made the following API call to do an authorization to the credit card, but I don't know if it is ok, the message is successful, but it is really the proper response ? can someone give me your opinion?
---------------------------------------------------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
string strApiLoginID = "XXXXXXXX";
string strApiTransactionKey = "XXXXXXXXXXXXXXX";
Run(strApiLoginID, strApiTransactionKey);
}
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
{
Console.WriteLine("Charge Tokenized Credit Card 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 creditCard = new creditCardType
{
cardNumber = "4111111111111111",
expirationDate = "1028",
// Set the token specific info
isPaymentToken = true,
cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA=" // Set this to the value of the cryptogram received from the token provide
};
//standard api call to retrieve response
var paymentType = new paymentType { Item = creditCard };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card
amount = 133.45m,
payment = paymentType
};
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the controller that will call the service
var controller = new createTransactionController(request);
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
// validate response
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if (response.transactionResponse.messages != null)
{
Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
}
else
{
Console.WriteLine("Failed Transaction.");
if (response.transactionResponse.errors != null)
{
Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
}
}
}
else
{
Console.WriteLine("Failed Transaction.");
if (response.transactionResponse != null && response.transactionResponse.errors != null)
{
Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
}
else
{
Console.WriteLine("Error Code: " + response.messages.message[0].code);
Console.WriteLine("Error message: " + response.messages.message[0].text);
}
}
}
else
{
Console.WriteLine("Null Response.");
}
return response;
}
Response
-----------
{
"transactionResponse": {
"responseCode": "1",
"authCode": "PYQMA1",
"avsResultCode": "Y",
"cvvResultCode": "p",
"cavvResultCode": "2",
"transId": "60173132287",
"refTransID": "",
"transHash": "C85B15CED28462974F1114DB07A16C39",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"networkTransId": "MELZ9F8877Q8LL15I0RU2K2"
},
"refId": null,
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
---------------------------------------------------------------------------------------------------------------------------------
Thank you for your time.
09-06-2021 09:23 AM