Payment gateways for US and Canada

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
KenPalmer
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Fri Sep 21, 2012 9:50 am

Payment gateways for US and Canada

Post by KenPalmer » Thu Oct 25, 2012 10:33 am

We have different gateway accounts for Skipjack US and Skipjack Canada. I saw this post about distinguishing payment gateways for an older version of AbleCommerce.
viewtopic.php?f=42&t=13826&p=59374&hilit=canada#p59374

And I saw this related to Skipjack.
http://help.ablecommerce.com/mergedProj ... ipjack.htm

With AbleCommerce Gold R2, how can I set up the gateway to use Skipjack Canada for Canadian transactions, and Skipjack US for United States transactions? Thanks.

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: Payment gateways for US and Canada

Post by Logan Rhodehamel » Thu Oct 25, 2012 11:25 am

It can be done. There are two parts you need to do. The first part is that because of the way our gateways work, you cannot configure two of the exact same provider. There is a very easy way around this though - it's a simple task for a developer. The idea is that you must create your own new provider class using some other name. To implement it you just inherit from the existing provider that you want to duplicate. That's enough to make AC treat it as a unique provider in the system.

Here are examples for both SkipJack and SagePay (Protx). The source zip gives the full source for building the alternate provider. The dll is the binary. If you don't care how it is made, you can just download the dll and for WAP installs you need to reference it. For WSP installs just put it into your bin folder. This will let you configure a second instance of the gateway. It will be visible from the Add Gateway screen.
CommerceBuilder.SkipJack2.dll.zip
CommerceBuilder.SkipJack2.src.zip
CommerceBuilder.SagePay2.dll.zip
CommerceBuilder.SagePay2.src.zip
The second part you will have to do on your end relates to payment methods. We do not currently support multiple gateways for a single payment method. When you configure a payment method in the admin you can link it to a single gateway. If that payment method is used at checkout, the associated gateway is activated.

So if you want to support multiple gateways using a single payment method (e.g. Visa) you will have to define two different payment methods each having the same name. One of these methods will link to the gateway configured for US. The other will link to the gateway configured for CA. You will have to customize the payment code so that it checks the billing address of the customer and filters the payment list. Only show the right payment method(s) depending on the country of the customer.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

KenPalmer
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Fri Sep 21, 2012 9:50 am

Re: Payment gateways for US and Canada

Post by KenPalmer » Thu Oct 25, 2012 3:31 pm

Thanks Logan. I've applied the SkipJack2.dll file, and the new gateway showed up as you indicated. And I've added the alternate payment methods. Now there is a Visa for SkipJack and a Visa for SkipJack (Alternate).

Now I need to customize the payment code to check the billing address. The CreditCardPaymentForm.ascx controls for mobile and regular checkout have this code, where I'll need to apply the filter.

Code: Select all

// LOAD AVAILABLE PAYMENT METHODS
IList<PaymentMethod> methods = AbleCommerce.Code.StoreDataHelper.GetPaymentMethods(AbleContext.Current.UserId);
List<string> creditCards = new List<string>();
List<string> intlDebitCards = new List<string>();
foreach (PaymentMethod method in methods)
{
    if (method.IsCreditOrDebitCard())
    {
        CardType.Items.Add(new ListItem(method.Name, method.Id.ToString()));
        if (method.IsIntlDebitCard()) intlDebitCards.Add(method.Name);
        else creditCards.Add(method.Name);
    }
}

Here are the namespaces where I see I'll need to make the changes you suggested:
1. AbleCommerce.Mobile.UserControls.Checkout.PaymentForms.CreditCardPaymentForm
2. AbleCommerce.ConLib.Checkout.PaymentForms.CreditCardPaymentForm

Is there anywhere else on the site, which I may be overlooking, where I'll need to apply that type of filtering? Thanks!

KenPalmer
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Fri Sep 21, 2012 9:50 am

Re: Payment gateways for US and Canada

Post by KenPalmer » Thu Oct 25, 2012 4:03 pm

Maybe I can create an extended GetPaymentMethods method in StoreDataHelper.cs that accepts the country, and edit calling code accordingly.

KenPalmer
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Fri Sep 21, 2012 9:50 am

Re: Payment gateways for US and Canada

Post by KenPalmer » Mon Oct 29, 2012 8:26 am

What I did to address this need is below, in case it may help someone else. I followed Logan's directions dated 10/25/2012. Then I altered code in the Code.StoreDataHelper.cs file as indicated.

This using statement was added to provide the User object to GetPaymentMethods().

Code: Select all

using CommerceBuilder.Users;
This enum was added to the StoreDataHelper class. The enumerator values align with entries in dbo.ac_PaymentGateways.PaymentGatewayId.

Code: Select all

      public enum skipjackGatewayCountry
      {
         // Digits map to related dbo.ac_PaymentGateways.PaymentGatewayId values.
         US = 2, // SkipJack
         CA = 3  // SkipJack (Alternate)
      }
This method was extended in the StoreDataHelper class.

Code: Select all

      public static IList<PaymentMethod> GetPaymentMethods(int userId)
      {
         string cacheKey = "PaymentMethods_" + userId.ToString();
         HttpContext context = HttpContext.Current;
         if ((context != null) && (context.Items.Contains(cacheKey))) return (IList<PaymentMethod>)context.Items[cacheKey];
         IList<PaymentMethod> methods = CommerceBuilder.Payments.PaymentMethodDataSource.LoadForUser(userId);
         if (context != null) context.Items[cacheKey] = methods;

         // Filter payment methods by this user's country code.
         User user = AbleContext.Current.User;
         if (user != null)
         {
            string userCountryCode = user.PrimaryAddress.CountryCode;
            int paymentGatewayId = (int)skipjackGatewayCountry.US;
            if (userCountryCode == "CA") paymentGatewayId = (int)skipjackGatewayCountry.CA;
            IList<PaymentMethod> methodsForCountry = new List<PaymentMethod>();
            foreach (PaymentMethod method in methods)
            {
               if (method.PaymentGatewayId == paymentGatewayId) methodsForCountry.Add(method);
            }
            methods = methodsForCountry;
         }

         return methods;
      }
The result is that when a customer accesses the payment screen, the GetPaymentMethods() method evaluates the country for that user's Billing Address, and returns Skipjack payment methods (Visa, Master Card, etc) associated with that country. Those credit cards populate the payment method drop-down list.

Logan, thanks for your help on this forum. I appreciate your thoroughness and response time.

June
Ensign (ENS)
Ensign (ENS)
Posts: 11
Joined: Wed Oct 24, 2012 11:24 am

Re: Payment gateways for US and Canada

Post by June » Mon Nov 05, 2012 2:05 pm

New question, but same topic...

Does Able Commerce Gold's CyberSource payment gateway handle tokenization?

If not, who do I talk to about contracting with someone to do this?

Post Reply