Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsStoreStoreAuthorize.net Gateway Provider - FIX 2.1.36Authorize.net Gateway Provider - FIX 2.1.36
Previous
 
Next
New Post
12/11/2010 4:17 PM
 
Here is this code-




using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using DotNetNuke.Modules.Store.Cart;
using DotNetNuke.Modules.Store.Components;
using DotNetNuke.Modules.Store.Customer;
using DotNetNuke.Modules.Store.Providers.Address;
using DotNetNuke.Services.Localization;

namespace DotNetNuke.Modules.Store.Cart
{
///
/// Summary description for AuthNetGatewayProvider.
///

public class AuthNetGatewayProvider
{
#region Constructors
public AuthNetGatewayProvider(string gatewaySettings)
{
_gatewaySettings = gatewaySettings;
}
#endregion

#region Private Declarations
private string _gatewaySettings = string.Empty;
#endregion

#region Public Methods
public TransactionResult ProcessTransaction(IAddressInfo shipping, IAddressInfo billing,
OrderInfo orderInfo, object transDetails)
{
TransactionResult result = new TransactionResult();

CultureInfo ci_enUS = new CultureInfo("en-US");

// Check data before performing transaction
AuthNetSettings settings = new AuthNetSettings(_gatewaySettings);
if ((settings == null) || (!settings.IsValid()))
{
result.Succeeded = false;
result.ResultCode = -3;

return result;
}

if (billing == null)
{
result.Succeeded = false;
result.ResultCode = -4;

return result;
}

TransactionDetails trans = new TransactionDetails(transDetails as string);
if ((trans == null) || (!trans.IsValid()))
{
result.Succeeded = false;
result.ResultCode = -5;

return result;
}

// Gather transaction information
string url = settings.GatewayURL;
string firstName = billing.FirstName;
string lastName = billing.LastName;
string address = billing.Address1 + " " + billing.Address2;
address = address.Trim();

NameValueCollection NVCol = new NameValueCollection();
// Merchant infos
NVCol.Add("x_login", settings.Username);
NVCol.Add("x_tran_key", settings.Password);
NVCol.Add("x_version", settings.Version);
NVCol.Add("x_test_request", settings.IsTest.ToString());
// Init infos
NVCol.Add("x_delim_data", "True");
NVCol.Add("x_delim_char", "~");
NVCol.Add("x_encap_char", "'");
NVCol.Add("x_relay_response", "False");
// Billing infos
NVCol.Add("x_first_name", firstName);
NVCol.Add("x_last_name", lastName);
NVCol.Add("x_company", "");
NVCol.Add("x_address", address);
NVCol.Add("x_city", billing.City);
NVCol.Add("x_state", billing.RegionCode);
NVCol.Add("x_zip", billing.PostalCode);
NVCol.Add("x_country", billing.CountryCode);
NVCol.Add("x_phone", billing.Phone1);
// Shipping infos
firstName = shipping.FirstName;
lastName = shipping.LastName;
address = shipping.Address1 + " " + shipping.Address2;
address = address.Trim();
NVCol.Add("x_ship_to_first_name", firstName);
NVCol.Add("x_ship_to_last_name", lastName);
NVCol.Add("x_ship_to_company", "");
NVCol.Add("x_ship_to_address", address);
NVCol.Add("x_ship_to_city", shipping.City);
NVCol.Add("x_ship_to_state", shipping.RegionCode);
NVCol.Add("x_ship_to_zip", shipping.PostalCode);
NVCol.Add("x_ship_to_country", shipping.CountryCode);
// Customer infos
NVCol.Add("x_cust_id", billing.UserID.ToString());
NVCol.Add("x_customer_ip", HttpContext.Current.Request.UserHostAddress);
// Order infos
NVCol.Add("x_invoice_num", orderInfo.OrderID.ToString());
NVCol.Add("x_amount", orderInfo.GrandTotal.ToString("0.00", ci_enUS));
NVCol.Add("x_tax", orderInfo.Tax.ToString("0.00", ci_enUS));
NVCol.Add("x_freight", orderInfo.ShippingCost.ToString("0.00", ci_enUS));
// Transaction infos
NVCol.Add("x_method", "CC");
NVCol.Add("x_type", settings.Capture.ToString());
NVCol.Add("x_recurring_billing", "NO");
NVCol.Add("x_card_num", trans.CardNumber);
NVCol.Add("x_card_code", trans.VerificationCode);
NVCol.Add("x_exp_date", trans.ExpirationMonth.ToString("00") + "/" + trans.ExpirationYear.ToString());


// Order details
ArrayList line_items = new ArrayList();
string fieldSep = "<|>";
OrderController orderController = new OrderController();
ArrayList orderDetails = orderController.GetOrderDetails(orderInfo.OrderID);
foreach (OrderDetailsInfo itemInfo in orderDetails)
{
line_items.Add(itemInfo.ModelNumber + fieldSep + itemInfo.ModelName + fieldSep + fieldSep + itemInfo.Quantity.ToString() + fieldSep + itemInfo.UnitCost.ToString("0.00", ci_enUS) + fieldSep + "Y");
}




// Perform transaction
try
{
Encoding enc = Encoding.GetEncoding(1252);
StreamReader loResponseStream = new StreamReader(PostEx(url, NVCol, line_items).GetResponseStream(), enc);

string lcHtml = loResponseStream.ReadToEnd();
loResponseStream.Close();

string[] resultArray = Microsoft.VisualBasic.Strings.Split(lcHtml.TrimStart("'".ToCharArray()), "'~'", -1, Microsoft.VisualBasic.CompareMethod.Binary);

result.Succeeded = (resultArray[0] == "1");
result.ResultCode = int.Parse(resultArray[0]);
result.ReasonCode = int.Parse(resultArray[2]);
result.Message = resultArray[3];
}
catch (Exception ex)
{
result.Succeeded = false;
result.ResultCode = -2;
result.Message = ex.Message;
}

return result;
}
#endregion

#region Private Methods
private WebResponse PostEx(string url, NameValueCollection values, ArrayList line_items)
{
WebRequest request = null;
StringBuilder builder = null;
string[] keys = null;
Stream stream = null;
byte[] bytes = null;
request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

if (values.Count == 0)
{
request.ContentLength = 0;
}
else
{
builder = new StringBuilder();
keys = values.AllKeys;
foreach (string key in keys)
{
if (builder.Length > 0)
{
builder.Append("&");
}
builder.Append(HttpUtility.UrlEncode(key));
builder.Append("=");
builder.Append(HttpUtility.UrlEncode(values[key]));
}

string WIPorder = builder.ToString();

foreach (string value in line_items)
{
WIPorder += ("&x_line_item=" + HttpUtility.UrlEncode(value));
}


bytes = Encoding.UTF8.GetBytes(WIPorder.ToString());
request.ContentLength = bytes.Length;
stream = request.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();
}
return request.GetResponse();
}
#endregion
}
}
 
New Post
12/11/2010 5:28 PM
 
My Original Post -

I'm not sure if this is a known bug or not, but the latest source code available on CodePlex - dnnstore-50648 (Version 2.1.36) has an error using the Authorize.net Gateway Provider. I'm not sure if this was fixed in version 2.01.4x,so I decided to just post this here. The code works fine if you try to checkout with one item in your cart, but fails with more than one item. You will get an error response from authorize.net showing an error Code of 270 and that a line item is invalid. I believe this occurs because the multiple line items in your cart consist of multiple values with the same key/name (x_line_item), and therefore cannot be added to the Name Value Collection (NVCol) and called by keyname (values.AllKeys). I rewrote part of the provider to fix this error. The provider will work for any number of items now and has been tested in live shopping carts. I will try to post the changed file below (File - AuthNetGatewayProvider.cs)

 
New Post
12/13/2010 1:59 AM
 
Hi Matt,

Thanks for report! The version 02.01.46 have the same bug.
I just released the new version 02.01.47, the bug is corrected now. It will be great if you could test the last beta.

Gilles

We (team members) are Humans offering their knowledge, their work and their spare time FOR FREE to benefit the community. It would be so particularly appreciated that your messages begin with "Hello" and end with "Thank you" or any other form of politeness. Ask yourself what your reaction would be, if you were approached by me (a total stranger) on the street to ask you something without saying "Hello" nor "Thank you"? After several years of services dedicated to the community, I begin to be tired to read requests without any form of politeness.
 
New Post
9/17/2011 6:01 PM
 
Hi Matt,

Thank you so much for creating this module I recently downloaded version 3. I've been working on my own, specifically for Authorize.net, nothing worthy of release to the public this will save me a lot of time. I'm still evaluating but I noticed that If you leave out the model number When a product is created you will also get authorize.net error 270. Putting in a model number fixes that, I just thought it was worth mentioning.
 
New Post
3/12/2012 1:44 PM
 

Hello everyone,

 I am using v3 of the Store and am still getting the Error 270 (x_line_item is the culprit ). The product name that I am submitting is 'xxxxx - my product'. I know that's not a lot of info to go on. :-)  Is there a way to see the query string that this provider is sending?

 -Sam

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsStoreStoreAuthorize.net Gateway Provider - FIX 2.1.36Authorize.net Gateway Provider - FIX 2.1.36


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out