cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to issue Auth Only request using AIM and Capture using new API?

I have a question as we're going to upgrade our system and before upgrade I would like to know either it is possible or not.

Environment:
Currently we're using AIM Advance Integration Method in one of our web application. We're using Authorize & Capture "AUTH_CAPTURE" in web application to charge a card.

What we're thinking to accomplish:
We've another back office desktop application which is connected to live web application. Now we're thinking to use Authorize Only on web application and then bring transaction ID to our desktop application and after some internal process we issue a capture request to charge a card.

Problem:
I'm sure this is possible via simple call. But while looking on documentation of AIM it is recommended by Authorize.Net to use cohesive API for future development as you'll not be supporting AIM in future. So we're planning to shift to new API now instead of future. So my question is following

If we do Auth only on web application side using (AIM) and bring transaction details into back end office system and then issue a capture request from our back end (desktop) application using new cohesive API to charge a card. Or you can say, on one end we're using AIM to issue Auth Only request and on second end we're considering to use cohesive API to capture amount (charge a card), so is it possible?
 
I will really appreciate help in this regard.
Ammas
Member
1 ACCEPTED SOLUTION

Accepted Solutions

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>
Powered by NexWebSites.com -
Certified Authorize.net developers

View solution in original post

NexusSoftware
Trusted Contributor
3 REPLIES 3

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>
Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor

Thanks for getting back to me on it and confirmation.

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];
        }
    }
}