Hi!
We are starting a project to convert some custom payment gateways from version 8 to version 9. I've been trying to find an example implementation of a payment gateway addin. Where could I find one?
Jani
Hi!
We are starting a project to convert some custom payment gateways from version 8 to version 9. I've been trying to find an example implementation of a payment gateway addin. Where could I find one?
Jani
We don't have any examples of full payment gateway integrations using AddIns. We do have documentation on that functionality in the manual.
Hi,
I am new to AspDotNetStorefront and AddIns, but I found it very interesting and powerful way to add functionalities.
I started by reading and testing the sample of:
Code Sample #1: Implementing a 3rd – Party Shipping Carrier
from page 63 of the "ERP Provider Sync Specification (ERPS)" document.
I can compiled the codes into my dev box without error. Do I need to do more in the contract in order to use the new functionality?
Here are the code I used:
/************************************************** ***********************************
* xxxxxxx, Inc
*
* This Add-In is a start to add a business rule for product-shipping driven criteria
* for checkout grouping and shipping calculations. This class implements the
* IShippingRates Add-In View.
*
* By: xxxxxxxxxx
* Date: Sept 08. 2010
*
************************************************** ************************************
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq.Expressions;
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
using AspDotNetStorefrontCore.ShippingCalculation;
using AspDotNetStorefront.HostView;
using AspDotNetStorefront.AddIn;
/*
* This class is used to return additional shipping rates while also using a carrier
* natively integrated into AspDotNetStorefront. This uses UPS real time shipping
* rates in AspDotNetStorefront, and integrates FedEx shipping rates.
*
* The Add-In must be decorated with the Add-In attribute from the System.AddIn namespace.
* Here, the Add-In starts with a class that implements the IShippingRates Add-In View:
*
*/
[System.AddIn.AddIn("Shipping Rates Add In",
Version = "1.0.0.0",
Description = "Add-In to retrieve and return FedEx shipping rates externally.")]
public class EH_FedExRates : IShippingRates
{
public EH_FedExRates()
{
}
/*
* The IShippingRates view exposes a single method with a return type of
* IShippingMethodCollection, GetRates(), which accepts a collection of packages being
* shipped, and a collection of shopping cart items. This method is required by the
* Add-In View, ergo we must implement it within the Add-In:
*
*/
public IShippingMethodCollection GetRates(IPackageCollection pCollection, IShoppingCart sCart)
{
var newShipMethods = new ShippingMethodCollection();
/*
* We then enumerate through each item in the package collection to build a request to be
* sent to FedEx:
*
*/
foreach (IPackage p in pCollection.Packages())
{
System.DateTime TomorrowsDate = System.DateTime.Now.AddDays(1);
XDocument FedExRequest = new XDocument(
new XDeclaration("1.0", "UTF-8", "no"),
new XElement("FDXRateAvailableServicesRequest",
new XAttribute(XNamespace.Xmlns + "api", "http://www.fedex.com/fsmapi"),
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XmlSchema-instance"),
new XAttribute(XNamespace.Xmlns + "noNamespaceSchemaLocation", "FDXRateAvailableServicesRequest.xsd"),
new XElement("RequestHeader",
new XElement("CustomerTransactionIdentifer", "RatesRequest"),
new XElement("AccountNumber", 123456789),
new XElement("MeterNumber", 0123456),
new XElement("CarrierCode", "FDXE")),
new XElement("ShipDate",
TomorrowsDate.Year.ToString() +
"-" + TomorrowsDate.Month.ToString().PadLeft(2, '0') +
"-" + TomorrowsDate.Day.ToString().PadLeft(2, '0')),
new XElement("DropoffType", "REGULARPICKUP"),
new XElement("Packaging", "YOURPACKAGING"),
new XElement("WeightUnits", "LBS"),
new XElement("ListRate", false),
new XElement("Weight", p.Weight()),
new XElement("OriginAddress",
new XElement("StateOrProvinceCode", pCollection.OriginStateProvince()),
new XElement("PostalCode", pCollection.OriginZipPostalCode()),
new XElement("CountryCode", pCollection.OriginCountryCode())),
new XElement("DestinationAddress",
new XElement("StateOrProvinceCode", pCollection.DestinationStateProvince()),
new XElement("PostalCode", pCollection.DestinationZipPostalCode()),
new XElement("CountryCode", pCollection.DestinationCountryCode())),
new XElement("Payment",
new XElement("PayorType", "SENDER")),
new XElement("DeclaredValue",
new XElement("Value", p.InsuredValue().Amount()),
new XElement("CurrencyCode", p.InsuredValue().CurrencyCode())),
new XElement("PackageCount", 1),
new XElement("SpecialServices",
new XElement("ResidentialDelivery", 1))));
//We then format the request in a way that the carriers’ API expects and send it off:
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter xtw = new XmlTextWriter(sw))
{
FedExRequest.WriteTo(xtw);
RTShipRequest = sw.ToString();
xtw.Close();
}
sw.Close();
}
String result = POSTandReceiveData(RTShipRequest, "https://gateway.fedex.com:443/GatewayDC");
/*
*
* We then take the response and parse it into an xml document so we can get the rates. We
* can also catch any errors here to provide ourselves with troubleshooting information
* should something go wrong with the Add-In
*
*/
// Load Xml into a XmlDocument object
XDocument *FedExResponse = new XDocument();
try
{
FedExResponse = XDocument.Parse(result);
}
catch
{
// do additional error logging here and return an empty set of shipping
// methods back to the host. This prevents the add-in from crashing the application
// incase anything goes wrong. However, error handling is also performed on the
// host side to prevent application failure in the event of add-in failure.
// [TO DO]
return new ShippingMethodCollection();
}
/*
* We would then enumerate through the response document and populate the shipping
* method collection with the rates and methods returned from the carrier:
*
*
*/
// Get rates
IEnumerable<XElement> nodesEntries = FedExResponse.Descendants().Where(e => e.Name == "Entry");
foreach (XElement xe in nodesEntries)
{
string origRateName = FedExGetCodeDescription(xe.Descendants().Single(e => e.Name == "Service").Value);
string rateName = "(From Shipping Rates Add-In) FedEx " + origRateName;
decimal totalCharges = decimal.Parse(xe.Descendants().Single(e => e.Name == "NetCharge").Value);
var newShipMethod = new ShippingMethod();
newShipMethod.m_carrier = "FEDEX";
newShipMethod.m_serviceName = rateName;
newShipMethod.m_serviceRate = new ShippingMoney { m_amount = totalCharges };
newShipMethod.m_vatRate = new ShippingMoney { m_amount = 0.00M };
newShipMethods.ShippingMethods().Add(newShipMethod );
}
/*
* Finally we return the shipping method collection to the Add-In View, which is converted
* to the Contract via the Add-In-Side Adapter, where the Host-Side Adapter then converts
* to the Host-Side View for consumption by the Host:
*
*
*/
return newShipMethods;
}
/*
* Because you also have a collection of shopping cart items, you can also do things like
* penny shipping or free shipping on a particular method/rate combination based on the
* subtotal of items in the cart:
*
*/
// get the subtotal of items in the shopping cart
decimal cartSubTotal = sCart.Items().Sum(ci => (ci.Price().Amount() * ci.Quantity()));
// if the order is between 50.00 and 150.00 and shipping domestically (U.S.)
// offer penny shipping for the Express Saver shipping method returned by FedEx
if (cartSubTotal > 50.00M && cartSubTotal <= 150.00M && pCollection.DestinationCountry().Equals("United States", StringComparison.OrdinalIgnoreCase))
{
if (origRateName.Equals("Express Saver", StringComparison.OrdinalIgnoreCase))
{
newShipMethod.m_serviceRate = new ShippingMoney { m_amount = 0.01M };
}
}
// if the order is greater than 150.00 and shipping domestically (U.S.)
// offer free shipping for the Express Saver shipping method returned by FedEx
if (cartSubTotal > 150.00M && pCollection.DestinationCountry().Equals("United States", StringComparison.OrdinalIgnoreCase))
{
if (origRateName.Equals("Express Saver", StringComparison.OrdinalIgnoreCase))
{
newShipMethod.m_serviceName = "FedEx Express Saver (Free Shipping)";
newShipMethod.m_serviceRate = new ShippingMoney { m_amount = 0.00M };
}
}
}
}
Any tips and suggestions would be grateful.
Thanks
-Dave
Dave, I'm working on an addin and wanted to ask if this process worked for you? I'm not sure I completely understand how to do this based on the manual.
Thanks for any advice you can give,
Jeff
Does anyone have a good link on how to implement an add-in. The classes are fairly easy to figure out, but where should these files be placed in the project?
I found a good tutorial on building a .Net add-in (http://blogs.microsoft.co.il/blogs/b...tem-AddIn.aspx), but I can't find an example that would seem to apply to the Storefont project.
First I added a Class Library project under the ASPDotNetStorefrontAddIns/AddIns directory. I then added the references for AspDotNetStorefrontAddInView and AspDotNetStorefrontCore projects (and marked them as copy local = false) and System.AddIn and System.AddInContract.
I compiled my sample class and added it using the Add-In manager in the Admin Site and it shows up there, but doesn't seem to do anything when I go to the cart. If this is not the correct way to implement this can someone give me an example?
I did have to make a change to AddInManager.aspx.cs line 92 so the add-in would copy correctly.
Code:from: addInSavePath = "{0}/{1}".FormatWith(addInDirectory, file.FileName); to: addInSavePath = "{0}/{1}".FormatWith(addInDirectory, Path.GetFileName(file.FileName));
My Class looks like this:
Code:using System.AddIn; using System.Collections.Generic; using AspDotNetStorefront.AddInView; using AspDotNetStorefrontCore; [AddIn("My Order Options", Version = "1.0.0.0", Description = "My Order Options", Publisher = "My Company")] public class MyOrderOptions : IOrderOptions { public IList<IOrderOption> GetOrderOptions() { IList<IOrderOption> Options = new List<IOrderOption>(); OrderOption o = new OrderOption(); o.Name = "Test Option"; o.Cost = 5.50M; o.Description = "This is a test option"; o.DefaultIsChecked = true; Options.Add((IOrderOption)o); return Options; } }
We are really interested in getting addins to work, perfect if there are any working examples.
=====
Version (Code/DB): AspDotNetStorefront MSx 9.1.0.1/9.1.0.0
Execution Mode: 64 Bit
Dot Net Developments - E-commerce By Experience
It is very frustrating working with some of the features, such as add-in's because the documentation does not cover the specifics of the ASPDNSF framework. There should be a reference guide that explains the purpose of each add-in contract, what each parameters purpose is and exactly when the add-in is called and how the returned data will be integrated in to the site.
Finally a basic example should be created for each add-in that shows the proper way to work with the objects in the passed parameters and returned object. The shipping example primarily covers making calls to a shipping API outside of the storefront and working with XML that is returned by that API. This is a terrible example because it hides the ASPDNSF required information in the mess of the shipping API implementation.
It is our responsibility as developers to learn how to work with API's from other entities by reading through their documentation. However, as a developer, I find it difficult to work with the ASPDNSF API's because of the poor documentation. Please give us basic examples for each add-in that returns some data that we can see on the site.
The shipping example could have easily been done by creating a new ShippingMethodCollection then a new ShippingMethod and populating each property with constants instead of working with a full blown XML example. It would have been a 8 line example that would be much easier to read through. Let me be responsible for getting data from an outside source and then looping through the results to populate the collection myself.
I would really appreciate it if I could get this information quickly. Here is a quick example of my shipping GetRates implementation (I could have looped through each package and added some random amount to build the shipping total to be more complete). It took 10 seconds to create it. Please have a developer spend an hour creating examples like this for the other add-in's, it will help a lot of us.
Code:public IShippingMethodCollection GetRates(IPackageCollection pCollection, IShoppingCart sCart) { var newShipMethods = new ShippingMethodCollection(); //Loop through the next block for each shipping method required var newShipMethod = new ShippingMethod(); newShipMethod.m_carrier = "FEDEX"; newShipMethod.m_serviceName = "2 Day; newShipMethod.m_serviceRate = new ShippingMoney { m_amount = 5.67M }; newShipMethod.m_vatRate = new ShippingMoney { m_amount = 0.00M }; newShipMethods.ShippingMethods().Add(newShipMethod ); return newShipMethods; }
Last edited by LarryW; 04-21-2011 at 08:15 AM. Reason: fixed formatting
Agreed, I would love to see more examples. I believe alot of the changes we've made could been made as addins but we didn't have a firm grasp as to how it works. This would certainly make it easier for us to upgrade to the latest version.
When will the problem LarryW spotted be addressed?
http://forums.aspdotnetstorefront.co...ht=#post107056
No matter how good documentation is or could be, it is all for nothing it add-ins are causing problems.
=====
Version (Code/DB): AspDotNetStorefront MSx 9.1.0.1/9.1.0.0
Execution Mode: 64 Bit
Dot Net Developments - E-commerce By Experience