Welcome to Mediachase Community Sign in | Join | Help    
in Search   

Get cart contents in custom payment gateway

Last post Wed, Oct 15 2008, 12:08 AM by truthbrother. 7 replies.
Sort Posts: Previous Next
  •  Wed, Oct 01 2008, 2:00 AM 10386

    Get cart contents in custom payment gateway

    Hello,

    Starting from the GenericGateway i made my own gateway, but i can't seem to get the current cart contents. This is the code i have in the Charge() procedure :

                Cart cart = ClientCart.GetCart();

                if (cart != null && cart.CartItems != null)
                {
                    int cartItems = 0;
                    foreach (CartItem item in cart.CartItems.CartItem)
                    {
                        //Gateway.AddProduct(item.ProductTitle, item.CartItemId.ToString(), "", item.Price.ToString(), item.Quantity.ToString(), "19", "");
                        Gateway.AddProduct(item.ProductTitle, "", "", "", "", "19", "");
                        cartItems++;
                    }
                }

    All the item properties are null.
  •  Wed, Oct 01 2008, 4:01 AM 10389 in reply to 10386

    Re: Get cart contents in custom payment gateway

    Nevermind, i've fixed it. The AddProduct procedure was faulty.

    However, i have a different problem now. When the user clicks "Confirm order" i have to redirect it to the payment gateway page. But in the event log, i get

    WebServices.OrderCreate:Complete ---> System.Threading.ThreadAbortException: Thread was being aborted.
  •  Fri, Oct 03 2008, 10:04 AM 10396 in reply to 10389

    Re: Get cart contents in custom payment gateway

    It might be hard for us to help you since you created your own custom gateway.  Can you provide any more details with the steps you took, a screenshot, etc.?

    Mediachase Software
  •  Fri, Oct 03 2008, 2:21 PM 10399 in reply to 10396

    Re: Get cart contents in custom payment gateway

    I started from the GenericGateway class. It has only the Charge() method :

    public class ePaymentGateway : IPaymentGateway
        {
            public bool Charge(IPaymentInfo info, ref string message)
            {
                ePayGateway Gateway = new ePayGateway();
                Cart cart = ClientCart.GetCart();

                if (cart != null && cart.CartItems != null)
                {
                    Gateway.MerchantID = ClientConfig.GetParamValue("ePayment","MerchantID");
                    Gateway.Key = ClientConfig.GetParamValue("ePayment","MerchantKey");
                    Gateway.Url = ClientConfig.GetParamValue("ePayment","ProcessURL");
                    Gateway.OrderID = info.TransactionId;

                    Gateway.Shipping = "45";
                    Gateway.Discount = cart.CartItems.DiscountPrice.Amount.ToString();
                    Gateway.TotalProducts = cart.CartItems.CartItem.Length;
                   
                    String itemPrice = String.Empty;
                    foreach (CartItem item in cart.CartItems.CartItem)
                    {
                        itemPrice = item.Price.Amount.ToString();
                        Gateway.AddProduct(item.ProductTitle, item.CartItemId.ToString(), "", itemPrice.Remove(itemPrice.IndexOf(',')), item.Quantity.ToString(), "19", "");
                    }

                    CustomerInfo UserInfo = ClientCustomer.GetCustomerInfo();
                    Address address = info.BillingAddress;

                    Gateway.AddBillingInfo(
                        new string[]
                        {
                            "BILL_FNAME",
                            "BILL_LNAME",
                            "BILL_EMAIL",
                            "BILL_PHONE",
                            "BILL_FAX",
                            "BILL_ADDRESS",
                            "BILL_ADDRESS2",
                            "BILL_ZIPCODE",
                            "BILL_CITY",
                            "BILL_STATE",
                            "BILL_COUNTRYCODE"
                        },
                        new string[]
                        {
                            address.FirstName,
                            address.LastName,
                            UserInfo.Email,
                            address.PhoneNumber,
                            address.FaxNumber,
                            address.Address1,
                            address.Address2,
                            address.ZipPostalCode,
                            address.City,
                            address.StateProvince,
                            address.Country.Code
                        }
                    );

                    Gateway.AddShippingInfo(
                        new string[]
                        {
                            "DELIVERY_FNAME",
                            "DELIVERY_LNAME",
                            "DELIVERY_PHONE",
                            "DELIVERY_COMPANY",
                            "DELIVERY_ADDRESS",
                            "DELIVERY_ADDRESS2",
                            "DELIVERY_ZIPCODE",
                            "DELIVERY_CITY",
                            "DELIVERY_STATE",
                            "DELIVERY_COUNTRYCODE"
                        },
                            new string[]
                        {
                            address.FirstName,
                            address.LastName,
                            address.PhoneNumber,
                            address.Company,
                            address.Address1,
                            address.Address2,
                            address.ZipPostalCode,
                            address.City,
                            address.StateProvince,
                            address.Country.Code
                        }
                    );

                    Gateway.PostData();
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

    The ePayGateway is the class that helps building the request for the gateway. And the final method, PostData() builds a form with all the parameters and submits to the gateway URL with redirect. This is where the thread gets interrupted.

    Maybe if i add info.Complete() before PostData() this will not happen ?
  •  Wed, Oct 08 2008, 3:04 PM 10410 in reply to 10399

    Re: Get cart contents in custom payment gateway

    Anyone ?
  •  Thu, Oct 09 2008, 10:25 AM 10412 in reply to 10410

    Re: Get cart contents in custom payment gateway

    Were you successful? Since I have not coded a gateway in the way that you are trying to implement it, the best I can ask you to do is to try it and give us error messages and screenshots when things fail. Sorry I couldn't be more helpful.

    Mediachase Software
  •  Tue, Oct 14 2008, 4:04 AM 10426 in reply to 10412

    Re: Get cart contents in custom payment gateway

    Well, no. I still have the exception in the log : Thread aborted.

    Maybe you can explain how the payment process works (in steps and methods) and maybe i can figure out where i can fit in.
  •  Wed, Oct 15 2008, 12:08 AM 10438 in reply to 10426

    Re: Get cart contents in custom payment gateway

    Here are a couple of articles that should help you with your custom gateway --

    http://docs.mediachase.com/doku.php?id=ecf:41:tutorials:payment

    (example - working with PayPal)
    http://docs.mediachase.com/doku.php?id=ecf:41:tutorials:paypal
View as RSS news feed in XML
Site Terms | Privacy Policy | About Us | Contact Us
Running on Mediachase eCommerce Framework 4.0.
  Copyright © Mediachase, LTD. 1997-2006. All Rights Reserved

E-commerce, HelpDesk, Service Desk & Project Management Software, alternatives to Microsoft Project Server & Sharepoint Collaboration Server
project management software | microsoft project server | sharepoint collaboration server | issues management, helpdesk & service desk
Powered by Community Server, by Telligent Systems