Hi guys,
please i'm working on a custom donation page with authorize.net
i used a custom web part that accept API Credentials & Keys and many other parameters
Scenario:
make transaction
Save all Data to an custom table
The problem i have now i can't get the code from authorize,
Can you please help me to get code i need it to test
Thanks
This is my Code:
using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.PortalControls;
using CMS.Helpers;
using CMS.DataEngine;
using CMS.CustomTables;
using System.Net;
using System.IO;
using System.Collections.Generic;
using CMS.EventLog;
using System.Threading.Tasks;
using System.Collections.Generic;
using AuthorizeNet.Api.Controllers;
using AuthorizeNet.Api.Contracts.V1;
using AuthorizeNet.Api.Controllers.Bases;
using System.Diagnostics;
public partial class CMSWebParts_Iss_Donate : CMSAbstractWebPart
{
    #region "Properties"
 /// <summary>
/// Title
/// </summary>
public string Title
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("Title"), "");
    }
    set
    {
        this.SetValue("Title", value);
    }
}
/// <summary>
/// Content
/// </summary>
public string Content
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("Content"), "");
    }
    set
    {
        this.SetValue("Content", value);
    }
}
    /// <summary>
/// Organization Name
/// </summary>
public string OrganizationName
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("OrganizationName"), "");
    }
    set
    {
        this.SetValue("OrganizationName", value);
    }
}
/// <summary>
/// AuthorizeNet Login Name
/// </summary>
public string AuthorizeNetLoginName
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("AuthorizeNetLoginName"), "");
    }
    set
    {
        this.SetValue("AuthorizeNetLoginName", value);
    }
}
/// <summary>
/// AuthorizeNet Transaction Key
/// </summary>
public string AuthorizeNetTransactionKey
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("AuthorizeNetTransactionKey"), "");
    }
    set
    {
        this.SetValue("AuthorizeNetTransactionKey", value);
    }
}
/// <summary>
/// Donation Endpoints
/// </summary>
public string DonationEndpoints
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("DonationEndpoints"), "");
    }
    set
    {
        this.SetValue("DonationEndpoints", value);
    }
}
/// <summary>
/// Successful Payment Page
/// </summary>
public string SuccessfulPaymentPage
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("SuccessfulPaymentPage"), "");
    }
    set
    {
        this.SetValue("SuccessfulPaymentPage", value);
    }
}
/// <summary>
/// Preset Dollar Amouts
/// </summary>
public string PresetDollarAmouts
{
    get
    {
        return ValidationHelper.GetString(this.GetValue("PresetDollarAmouts"), "");
    }
    set
    {
        this.SetValue("PresetDollarAmouts", value);
    }
}
#endregion
#region "Methods"
/// <summary>
/// Content loaded event handler.
/// </summary>
public override void OnContentLoaded()
{       
    base.OnContentLoaded();
    SetupControl();
    string test=
    ltlTitleText.Text=Title;   
    ltlContentText.Text = Content;
}
/// <summary>
/// Initializes the control properties.
/// </summary>
protected void SetupControl()
{
    if (this.StopProcessing)
    {
        // Do not process
    }
    else
    {
    }
}
/// <summary>
/// Reloads the control data.
/// </summary>
public override void ReloadData()
{
    base.ReloadData();
    SetupControl();
}
public class AuthorizeCreditCard
{
    private static Exception ex;
    public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount, String Number, String Expiration)
    {
        Console.WriteLine("Authorize 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 = Number,
            expirationDate = Expiration
        };
        //standard api call to retrieve response
        var paymentType = new paymentType { Item = creditCard };
        var transactionRequest = new transactionRequestType
        {
            transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),    // authorize only
            amount = amount,
            payment = paymentType
        };
        var request = new createTransactionRequest { transactionRequest = transactionRequest };
        // instantiate the contoller 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
        if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        {
            if (response.transactionResponse != null)
            {
                Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
            }
        }
        else if (response != null)
        {
            Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
            if (response.transactionResponse != null)
            {
                Console.WriteLine("Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText);
            }
        }
        return response;
    }
}
protected void Donate(object sender, EventArgs e) {
    decimal decinum = Math.Round(Convert.ToDecimal(Amount.Text), 2);
    string expire = month.SelectedValue + " " + year.SelectedValue;
     AuthorizeCreditCard.Run(AuthorizeNetLoginName, AuthorizeNetTransactionKey, decinum, Card.Text, expire);
  var resp = (createTransactionResponse)AuthorizeCreditCard.Run(AuthorizeNetLoginName, AuthorizeNetTransactionKey, decinum, Card.Text, expire);
    string customTableClassName = "customtable.Donation";
    // Check if Custom table 'Sample table' exists
    DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
    if (customTable != null)
    {
        // Create new custom table item 
        CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName);
        // Set the ItemText field value
        newCustomTableItem.SetValue("Title", Title);
        newCustomTableItem.SetValue("Content", Content);
        newCustomTableItem.SetValue("OrganizationName", OrganizationName);
        newCustomTableItem.SetValue("AuthorizeNetLoginName", AuthorizeNetLoginName);
        newCustomTableItem.SetValue("AuthorizeNetTransactionKey", AuthorizeNetTransactionKey);
        newCustomTableItem.SetValue("DonationEndpoints", DonationEndpoints);
        newCustomTableItem.SetValue("SuccessfulPaymentPage", SuccessfulPaymentPage);
        newCustomTableItem.SetValue("PresetDollarAmouts", PresetDollarAmouts);
        newCustomTableItem.SetValue("DollarAmount", Amount.Text);
        newCustomTableItem.SetValue("CardType", Card.SelectedValue);
        newCustomTableItem.SetValue("CreditCardNumber", Credit.Text);
        newCustomTableItem.SetValue("Expires", expire);
        newCustomTableItem.SetValue("SecurityCode", Security.Text);
        newCustomTableItem.SetValue("FirstName", First.Text);
        newCustomTableItem.SetValue("LastName", Last.Text);
        newCustomTableItem.SetValue("Address1", Address1.Text);
        newCustomTableItem.SetValue("Address2", Address2.Text);
        newCustomTableItem.SetValue("City", City.Text);
        newCustomTableItem.SetValue("State", State.Text);
        newCustomTableItem.SetValue("PostalCode", Postal.Text);
        newCustomTableItem.SetValue("Country", Country.SelectedValue);
        newCustomTableItem.SetValue("Email", Email.Text);
        newCustomTableItem.SetValue("Phone", Phone.Text);
        newCustomTableItem.SetValue("Comment", comment.Text);
        // Insert the custom table item into database
        newCustomTableItem.Insert();
    }
    // Authorize.Net
    // Thank You Page
    Response.Redirect(SuccessfulPaymentPage);
}
#endregion
}