I am working on integrating Authorize .Net in to Dash Commerce 3.02 and running into some problems. Right the settings are not saving properly. Here is a copy of the payment provider class and the configuration utility.
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Text;
using
System.Net;
using
System.IO; namespace MettleSystems.dashCommerce.Store.Services.PaymentService
{
public class AuthorizeNet : IPaymentProvider
{
public const string posturl = "https://secure.authorize.net/gateway/transact.dll";
public const string API_LOGIN = "Test User";public const string Trans_KEY = "TestKey";
public const string Auth_Type = "AUTH_CAPTURE";private Hashtable myHash = new Hashtable();
private string apilogin = string.Empty;private string transkey = string.Empty;public AuthorizeNet()
{
//Blank Constructor
}
public AuthorizeNet(string APILogin, string TransKey)
{
apilogin = APILogin;
transkey = TransKey;
//Reset Hash Table
myHash.Clear();
//Add things to the hash tablemyHash.Add("x_login", apilogin);
myHash.Add(
"x_tran_key", transkey);myHash.Add("x_delim_data", "TRUE");
myHash.Add(
"x_delim_char", '|');myHash.Add("x_relay_response", "FALSE");
myHash.Add(
"x_type", "AUTH_CAPTURE");myHash.Add("x_method", "CC");
}
#region IPaymentProvider MembersTransaction IPaymentProvider.Authorize(Order Order)
{
//Add Additional Information to the Hash TablemyHash.Add("x_card_num", Order.CreditCardNumber);
myHash.Add(
"x_card_exp", Order.CreditCardExpirationMonth + Order.CreditCardExpirationYear);if (Order.CreditCardType != CreditCardType.Amex)
{
myHash.Add("x_card_code", Order.CreditCardSecurityNumber);
}
myHash.Add("x_amount", Order.SubTotal);
myHash.Add(
"x_description", Order.OrderId);
//Add Address InformationAddress mBill = Order.BillingAddress;
myHash.Add(
"x_first_name", mBill.FirstName);myHash.Add("x_last_name", mBill.LastName);
myHash.Add(
"x_address", mBill.Address1);myHash.Add("x_city", mBill.City);
myHash.Add(
"x_state", mBill.StateOrRegion);myHash.Add("x_zip", mBill.PostalCode);
myHash.Add(
"x_phone", mBill.Phone);myHash.Add("x_customer_ip", Order.IPAddress);
String post = string.Empty;foreach (DictionaryEntry field in myHash)
{
post = field.Key + "=" + field.Value + "&";
}
post = post.TrimEnd('&');
//Create Request ObjectHttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(posturl);objRequest.Method = "POST";
objRequest.ContentLength = post.Length;
objRequest.ContentType =
"application/x-www-form-urlencoded";StreamWriter writer = null;writer = new StreamWriter(objRequest.GetRequestStream());
writer.Write(post);
writer.Close();
//Now get the response codeString response = string.Empty;
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
{
response = responseStream.ReadToEnd();
responseStream.Close();
}
Array response_values = response.Split('|');
Transaction trans = new Transaction();
//Set Trans Values
trans.OrderId = Order.OrderId;
trans.GatewayName = "Authorize.Net";
int respCode = 0;respCode = (int)response_values.GetValue(0);
//Handles the response codeswitch (respCode)
{
case 1:
trans.GatewayResponse =
"Approved";break;
case 2:trans.GatewayResponse = "Declined";
break;case 3:
trans.GatewayResponse =
"Error";break;
case 4:trans.GatewayResponse = "Held for Review";
break;default:
trans.GatewayResponse =
"Declined";break;
}
//Finishup Gateway Information
trans.GatewayTransactionId = response_values.GetValue(6).ToString();
//Now everything else
trans.PaymentMethod = Order.CreditCardType.ToString();
trans.AVSCode = response_values.GetValue(5).ToString();
trans.TransactionTypeId = (int)TransactionType.Charge;
trans.TransactionDate =
DateTime.Now;trans.GrossAmount = (int)response_values.GetValue(9);
//Store the Authorization Code
trans.CVV2Code = response_values.GetValue(4).ToString();
trans.Save("System");return trans;
}
Transaction IPaymentProvider.Charge(Order order)
{
throw new NotImplementedException();
}
Transaction IPaymentProvider.Refund(Transaction transaction, Order order)
{
throw new NotImplementedException();
}
#endregion
}
}
PaymentProvider Configuration Class
using
System;
using
System.Data;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
MettleSystems.dashCommerce.Core;
using
MettleSystems.dashCommerce.Localization;
using
MettleSystems.dashCommerce.Store;
using
MettleSystems.dashCommerce.Store.Services;
using
MettleSystems.dashCommerce.Store.Services.PaymentService;
using
MettleSystems.dashCommerce.Store.Web.Controls;namespace MettleSystems.dashCommerce.Web.admin.controls.configuration.paymentproviders
{
public partial class Authorize_Config : PaymentConfigurationControl
{
ProviderSettings provSetting = null;
PaymentServiceSettings payServ;protected void Page_Load(object sender, EventArgs e)
{
try
{
payServ = PaymentService.FetchConfiguredPaymentProviders();if (payServ != null)
{
foreach (ProviderSettings pSet in payServ.ProviderSettingsCollection)
{
if (pSet.Name == typeof(Authorize_Config).Name)
{
provSetting = pSet;
break;
}
}
if (provSetting != null)
{
txtApiLogin.Text = provSetting.Parameters[AuthorizeNet.API_LOGIN];
txtTransKey.Text = provSetting.Parameters[
AuthorizeNet.Trans_KEY];ddlAuth.SelectedValue = provSetting.Parameters[AuthorizeNet.Auth_Type];
}
else
{
provSetting = new ProviderSettings();
}
}
}
catch (Exception ex)
{
Logger.Error(typeof(Authorize_Config).Name + ".Page_Load", ex);base.MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
}
}
protected void cmdSave_Click(object sender, EventArgs e)
{
try
{
if (provSetting == null)
{
provSetting = new ProviderSettings(typeof(AuthorizeNet).Name, typeof(AuthorizeNet).AssemblyQualifiedName);if (payServ == null)
{
payServ = new PaymentServiceSettings();
}
payServ.ProviderSettingsCollection.Add(provSetting);
}
payServ.ProviderSettingsCollection.Clear();
//Following the Order they are inserted to match the constructorprovSetting.Parameters.Add(AuthorizeNet.API_LOGIN, txtApiLogin.Text.Trim());
provSetting.Parameters.Add(
AuthorizeNet.Trans_KEY, txtTransKey.Text.Trim());provSetting.Parameters.Add(AuthorizeNet.Auth_Type, ddlAuth.SelectedValue.Trim());
int id = base.Save(payServ, WebUtility.GetUserName());if (id > 0)
{
MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblPaymentConfigurationSaved"));
}
else
{
MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblPaymentConfigurationNotSaved"));
}
}
catch (Exception ex)
{
Logger.Error(typeof(Authorize_Config).Name + ".cmdSave_Click", ex);base.MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
}
}
}
}
Any thoughts are appreciated