Skip to content

RevStackCore/AuthorizeDotNet

Repository files navigation

AuthorizeDotNet

A .NET Core Authorize.Net Sdk

Build status

A core Authorize.Net sdk for charge, authorize, refund and void transactions.

Nuget Installation

Install-Package RevStackCore.AuthorizeDotNet

Payment Processor Interface Abstraction

The sdk payment processor implements the following interface for asynchronous processing of charge, authorize, refund and void transactions. The entities correspond to the Authorize.Net API reference https://developer.authorize.net/api/reference/index.html

public interface IANetProcessor
{
    Task<ANetChargeTransactionResponse> ChargeAsync(ANetCreditCard creditCard, string refId, decimal amount);
    Task<ANetChargeTransactionResponse> ChargeAsync(ANetCreditCard creditCard, ANetBillTo billing, string refId,  decimal amount);
    Task<ANetChargeTransactionResponse> ChargeAsync(ANetChargeTransactionRequest request, string refId);
    Task<ANetAuthorizeTransactionResponse> AuthorizeAsync(ANetCreditCard creditCard, string refId, decimal amount);
    Task<ANetAuthorizeTransactionResponse> AuthorizeAsync(ANetCreditCard creditCard, ANetBillTo billing, string refId, decimal amount);
    Task<ANetAuthorizeTransactionResponse> AuthorizeAsync(ANetAuthorizeTransactionRequest request, string refId);
    Task<ANetCaptureTransactionResponse> CaptureAsync(ANetCaptureTransactionRequest request, string refId);
    Task<ANetRefundTransactionResponse> RefundAsync(ANetRefundTransactionRequest request, string refId);
    Task<ANetVoidTransactionResponse> VoidAsync(ANetVoidTransactionRequest request, string refId);
}

Payment Processor Constructor

The sdk payment processor constructor takes 3 arguments: the Authorize.Net loginId and transactionKey, and the processor api mode: Live or Sandbox.

public ANetProcessor(string loginId, string transactionKey, ANetProcessorModeType mode)

Sample Usage

using RevStackCore.AuthorizeDotNet;

var processor = new ANetProcessor(LOGIN_ID,TRANSACTION_KEY,ANetProcessorModeType.Sandbox);
var creditCard= new ANetCreditCard
{
   CardNumber="4539517044325459",
   ExpirationDate="2021-10",
   CardCode="478"
};
var response = await processor.ChargeAsync(creditCard,REFERENCE_ID, AMOUNT);
if (response.ResponseCode == ANetResponseCodeType.Approved)
{
    //authCode=response.AuthCode;
    //transId=response.TransId;
    //do something
}
else
{
    if(response.Errors !=null && response.Errors.Any())
    {
        //errorText=response.Errors.FirstOrDefault().ErrorText;
        //errorCode = response.Errors.FirstOrDefault().ErrorCode;
    }
    else
    {
        //messageDescription=response.Messages.FirstOrDefault().Description;
        //messageCode=response.Messages.FirstOrDefault().Code;
    }
    
    //do seomthing
}