cancel
Showing results for 
Search instead for 
Did you mean: 

Prior Authorization Capture using C# SDK

I have my test system setup using the C# SDK for AIM , and due to our company's ordering process, we need to do an Authorization first, then capture the authorization separately. I initially did this using the Capture transaction type, but that obviously isn't correct, because it creates a new transaction. I can't find anything in the SDK about doing a PriorAuthCapture transaction type.

 

Am I missing something, or is there another way to do the PriorAuthCapture using the C# SDK?

cpoirier
Member
2 ACCEPTED SOLUTIONS

Accepted Solutions

It is missing from the SDK. You can modify the source.

View solution in original post

RaynorC1emen7
Expert

Thanks for the heads-up on the source download RaynorC1emen7, I didn't notice that those were two separate links. I downloaded the source and added a PriorAuthCaptureRequest class in AuthorizeNET/AIM/Requests/ (I just copied and modified the CaptureRequest class. Here is the source:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AuthorizeNet {
    /// <summary>
    /// A request representing a PriorAuthCaptureRequest - the final transfer of funds that happens after an AuthorizationRequest.
    /// </summary>
    public class PriorAuthCaptureRequest:GatewayRequest {

        /// <summary>
        /// Initializes a new instance of the <see cref="PriorAuthCaptureRequest"/> class.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="transactionId">The transaction id.</param>
        /// <param name="authCode">The auth code.</param>
        public PriorAuthCaptureRequest(decimal amount, string transactionId, string authCode)
        {
            this.SetApiAction(RequestAction.PriorAuthCapture);
            this.Queue(ApiFields.Amount, amount.ToString());
            this.Queue(ApiFields.TransactionID, transactionId);
            this.Queue(ApiFields.AuthorizationCode, authCode);
        }

    }
}


View solution in original post

7 REPLIES 7

It is missing from the SDK. You can modify the source.

RaynorC1emen7
Expert

How would we modify the source to perform a Prior Authorization Capture?

 

The class library is pre-compiled into the AuthorizeNet.dll. Can you send a working sample? I'm having the exact same issue. Thanks!

How did you get this working? If you don't mind, can you share a C# sample?

eggsarebad
Member

I haven't done this yet, but my plan is to write a class that extends GatewayRequest and submits the raw XML request. I will post code when I have done this so that others can use it.

I found a solution using System.Reflection. I downloaded .Net Reflector and found the hidden mothod names inside the GatewayRequest class.

 

I then found a hidden method named "SetApiAction". This internal method takes the RequestAction Enum as a parameter.

 

Here's the VB.net code:

 

'Decalre your CaptureRequest class

Dim auth As CaptureRequest = New AuthorizeNet.CaptureRequest(ord.OrderTotal, ord.ResponseTransactionID, ord.ResponseAuthorizationCode)

 

'Modify the SDK using System.Reflection, so you can make a prior_auth_capture request

Dim mi As MethodInfo = GetType(CaptureRequest).GetMethod("SetApiAction", BindingFlags.NonPublic Or BindingFlags.Instance)
mi.Invoke(auth, New Object() {RequestAction.PriorAuthCapture})

 

Let me know if it works for you!

C# SDKs have two different download, dll or source. Source on the left, dll(binary) on the right.

 

Thanks for the heads-up on the source download RaynorC1emen7, I didn't notice that those were two separate links. I downloaded the source and added a PriorAuthCaptureRequest class in AuthorizeNET/AIM/Requests/ (I just copied and modified the CaptureRequest class. Here is the source:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AuthorizeNet {
    /// <summary>
    /// A request representing a PriorAuthCaptureRequest - the final transfer of funds that happens after an AuthorizationRequest.
    /// </summary>
    public class PriorAuthCaptureRequest:GatewayRequest {

        /// <summary>
        /// Initializes a new instance of the <see cref="PriorAuthCaptureRequest"/> class.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="transactionId">The transaction id.</param>
        /// <param name="authCode">The auth code.</param>
        public PriorAuthCaptureRequest(decimal amount, string transactionId, string authCode)
        {
            this.SetApiAction(RequestAction.PriorAuthCapture);
            this.Queue(ApiFields.Amount, amount.ToString());
            this.Queue(ApiFields.TransactionID, transactionId);
            this.Queue(ApiFields.AuthorizationCode, authCode);
        }

    }
}