Solved! Go to Solution.
โ12-12-2017 07:49 AM
Hello @Ammas,
Yes, you should be able to issue separate Auth and Capture calls, one via the old AIM API and the other with the new API endpoint. Just be sure to reference the appropriate TransId in your priorAuthCaptureTransaction call.
<transactionType>priorAuthCaptureTransaction</transactionType> <amount>5</amount> <refTransId>{TransactionID}</refTransId>
โ12-12-2017 10:02 AM
Hello @Ammas,
Yes, you should be able to issue separate Auth and Capture calls, one via the old AIM API and the other with the new API endpoint. Just be sure to reference the appropriate TransId in your priorAuthCaptureTransaction call.
<transactionType>priorAuthCaptureTransaction</transactionType> <amount>5</amount> <refTransId>{TransactionID}</refTransId>
โ12-12-2017 10:02 AM
Thanks for getting back to me on it and confirmation.
โ12-13-2017 03:26 AM
Here is the sample code which works for me. Sharing may be someone else required it.
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using AuthorizeNet.Api.Contracts.V1;
using AuthorizeNet.Api.Controllers;
using AuthorizeNet.Api.Controllers.Bases;
using AuthorizeNet.Util;
namespace Poc.Authorize.Net
{
class Program
{
static void Main(string[] args)
{
AuthorizeNetPoc.ExecuteTest();
}
}
public class AuthorizeNetPoc
{
public static void ExecuteTest()
{
Console.WriteLine("Authorize Credit Card Sample");
Console.WriteLine("Authorizing Credit Card Amount Using Advance Integration Method AIM");
var referenceTransactionId = AuthorizeCardUsingAim();
Console.WriteLine($"Amount Authorized successfully and Reference Transactions Id= {referenceTransactionId}");
Console.WriteLine("Capturing Amount Using Cohesive API");
ChargeCardUsingNewApi(referenceTransactionId);
Console.ReadKey();
}
private static void ChargeCardUsingNewApi(string referenceTransactionId)
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = "##########", // Put login name here.
ItemElementName = ItemChoiceType.transactionKey,
Item = "#########", // Put Transaction Key here
};
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),
refTransId = referenceTransactionId
};
var request = new createTransactionRequest
{
transactionRequest = transactionRequest
};
var controller = new createTransactionController(request);
controller.Execute();
var response = controller.GetApiResponse();
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?.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.");
}
}
private static string AuthorizeCardUsingAim()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
const string postUrl = "https://test.authorize.net/gateway/transact.dll";
var postValues = new Dictionary<string, string>
{
{"x_login", "########"}, //Put login name here.
{"x_tran_key", "#########"}, // put transaction name here.
{"x_delim_data", "TRUE"},
{"x_delim_char", "|"},
{"x_relay_response", "FALSE"},
{"x_type", "AUTH_ONLY"},
{"x_method", "CC"},
{"x_card_num", "4111111111111111"},
{"x_card_code", "123"},
{"x_exp_date", "02/18"},
{"x_amount", "100"},
{"x_description", "PO-123"},
{"x_first_name", "Ammas"},
{"x_last_name", "Sumair"},
{"x_address", "Garden Town Lahore"},
{"x_state", "Punjab"},
{"x_zip", "54000"}
};
var postString = postValues.Aggregate("", (current, postValue) => current + (postValue.Key + "=" + postValue.Value + "&"));
postString = postString.TrimEnd('&');
var sb = new StringBuilder();
for (var i = 1; i < 3; i++)
{
sb.Append($"item{i}<|>");
sb.Append($"product{i}<|>");
sb.Append($"Dummy{i}<|>");
sb.Append($"{i}<|>");
sb.Append($"{(i * 10)}<|>Y,");
}
postString = sb.ToString().Split(',').Aggregate(postString, (current, lineItem) => current + ("&x_line_item=" + lineItem));
var httpWebRequest = (HttpWebRequest)WebRequest.Create(postUrl);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = postString.Length;
httpWebRequest.ContentType = postUrl;
var myWriter = new StreamWriter(httpWebRequest.GetRequestStream());
myWriter.Write(postString);
myWriter.Close();
string postResponse;
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var responseStream = new StreamReader(httpWebResponse.GetResponseStream()))
{
postResponse = responseStream.ReadToEnd();
responseStream.Close();
}
//Transaction Id located on index 6
return postResponse.Split('|')[6];
}
}
}
โ12-13-2017 04:38 AM