Alipay payment gateway problem(images are avaliable now)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 anos atrás
Hi, this is the best open source shopping cart program ever.

I really want to contribute to it. In China, 10,000,000 people use alipay payment gateway every day. I'm trying to integrate into NopCommerce1.20.

So far I'm almost there, but I got two problems, I hope stuff here can give me some hints.

I follow the steps below:

Step1: I add a new payment gateway in Administration control panel
this new payment method id is 21


Step2: configue the payment method like this:



Configuration template path: Payment\Alipay\ConfigurePaymentMethod.ascx
User template path:  ~\Templates\Payment\Alipay\PaymentModule.ascx
Class name: NopSolutions.NopCommerce.Payment.Methods.Alipay.AlipayPaymentProcessor, Nop.Payment.Alipay

Step3: Payment\Alipay\ConfigurePaymentMethod.ascx





Step4: ~\Templates\Payment\Alipay\PaymentModule.ascx





Step5: Set the AlPpayPaymentModule.Message as

English//AliPayPaymentModule.Message//You will be redirected to Alipay site to complete the order.

Step6: NopSolutions.NopCommerce.Payment.Methods.Alipay.AlipayPaymentProcessor, Nop.Payment.Alipay

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
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 NopSolutions.NopCommerce.Common;
using NopSolutions.NopCommerce.Common.Configuration.Settings;
using NopSolutions.NopCommerce.Common.CustomerManagement;
using NopSolutions.NopCommerce.Common.Directory;
using NopSolutions.NopCommerce.Common.Orders;
using NopSolutions.NopCommerce.Common.Payment;
using NopSolutions.NopCommerce.Common.Utils;

namespace NopSolutions.NopCommerce.Payment.Methods.Alipay
{
    /// <summary>
    /// Alipay payment processor
    /// </summary>
    public class AlipayPaymentProcessor : IPaymentMethod
    {
        #region Fields
        private string Key;
        private string PartnerId;
        #endregion

        #region Ctor
        /// <summary>
        /// Creates a new instance of the PayPalStandardPaymentProcessor class
        /// </summary>
        public AlipayPaymentProcessor()
        {
            Key = SettingManager.GetSettingValue("PaymentMethod.Alipay.Key");
            PartnerId = SettingManager.GetSettingValue("PaymentMethod.Alipay.PartnerID");

            if (string.IsNullOrEmpty(Key))
                throw new NopException("Alipay Key is empty");

            if (string.IsNullOrEmpty(PartnerId))
                throw new NopException("Alipay PartnerId is empty");
        }
        #endregion

        #region Utilities
        /// <summary>
        /// Gets Paypal URL
        /// </summary>
        /// <returns></returns>
        private string GetAlipayGatewayUrl()
        {
            return "https://www.alipay.com/cooperate/gateway.do?";
        }

        #endregion

        #region Methods
    
        /// <summary>
        /// Process payment
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an order processing</param>
        /// <param name="customer">Customer</param>
        /// <param name="OrderGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void ProcessPayment(PaymentInfo paymentInfo, Customer customer, Guid OrderGuid, ref ProcessPaymentResult processPaymentResult)
        {
            processPaymentResult.PaymentStatus = PaymentStatusEnum.Pending;
        }

        /// <summary>
        /// Post process payment (payment gateways that require redirecting)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>The error status, or String.Empty if no errors</returns>
        public string PostProcessPayment(Order order)
        {
            string gateway = this.GetAlipayGatewayUrl();                        //支付接口
            string service = "create_direct_pay_by_user";                       //服务名称,这个是识别是何接口实现何功能的标识,请勿修改
            string seller_email = "[email protected]";                               //商家签约时的支付宝帐号,即收款的支付宝帐号
            string sign_type = "MD5";                                           //加密类型,签名方式“不用改”
            //string key                                                        //安全校验码,与partner是一组,获取方式是:用签约时支付宝帐号登陆支付宝网站www.alipay.com,在商家服务我的商家里即可查到。
            //string partner                                                    //商户ID,合作身份者ID,合作伙伴ID
            string _input_charset = "gb2312";                                   //编码类型,完全根据客户自身的项目的编码格式而定,千万不要填错。否则极其容易造成MD5加密错误。

            string show_url = "http;//www.alipay.com";                          //展示地址,即在支付页面时,商品名称的链接地址。

            string out_trade_no = order.OrderID.ToString();                     //客户自己的订单号,(现取系统时间,可改成网站自己的变量),订单号必须在自身订单系统中保持唯一性
            string subject = order.OrderID.ToString();                          //商品名称,也可称为订单名称,该接口并不是单一的只能买一样东西,可把一次支付当作一次下订单
            string body = "description";                                        //商品描述,即备注
            string total_fee = order.OrderTotal.ToString();                     //商品价格,也可称为订单的总金额

            //server notify url(Alipay_Notify.asp文件所在路经),必须是完整的路径地址
            string notify_url = "http://localhost::11624/jsnet05gb2312/Alipay_Notify.aspx";
            //server return url(return_Alipay_Notify.asp文件所在路经),必须是完整的路径地址
            string return_url = "http://localhost::11624/jsnet05gb2312/Alipay_Return.aspx";

            //支付URL生成
            string alipay_url = AliPay.CreatUrl(
                gateway,
                service,
                PartnerId,
                sign_type,
                out_trade_no,
                subject,
                body,
                total_fee,
                show_url,
                seller_email,
                Key,
                return_url,
                _input_charset,
                notify_url
                );

            //跳转到支付宝支付页
            //Response.Redirect(aliay_url);
            HttpContext.Current.Response.Redirect(alipay_url);
            //StringBuilder builder = new StringBuilder();
            //string returnURL = CommonHelper.GetStoreLocation(false) + "PaypalPDTHandler.aspx";
            //string cancel_returnURL = CommonHelper.GetStoreLocation(false) + "PaypalCancel.aspx";
            //builder.Append(GetPaypalUrl());
            //builder.AppendFormat("?cmd=_xclick&business={0}", HttpUtility.UrlEncode(businessEmail));
            //builder.AppendFormat("&item_name=Order Number {0}", order.OrderID);
            //builder.AppendFormat("&custom={0}", order.OrderID);
            //builder.AppendFormat("&amount={0}", order.OrderTotal.ToString("N", new CultureInfo("en-us")));
            ////TODO check PrimaryStoreCurrency.CurrencyCode
            //builder.Append(string.Format("&no_note=1&currency_code={0}", HttpUtility.UrlEncode(CurrencyManager.PrimaryStoreCurrency.CurrencyCode)));
            //builder.AppendFormat("&invoice={0}", order.OrderID);
            //builder.AppendFormat("&rm=2", new object[0]);
            //builder.AppendFormat("&no_shipping=1", new object[0]);
            //builder.AppendFormat("&return={0}&cancel_return={1}", HttpUtility.UrlEncode(returnURL), HttpUtility.UrlEncode(cancel_returnURL));
            //builder.AppendFormat("&first_name={0}", HttpUtility.UrlEncode(order.BillingFirstName));
            //builder.AppendFormat("&last_name={0}", HttpUtility.UrlEncode(order.BillingLastName));
            //builder.AppendFormat("&address1={0}", HttpUtility.UrlEncode(order.BillingAddress1));
            //builder.AppendFormat("&address2={0}", HttpUtility.UrlEncode(order.BillingAddress2));
            //builder.AppendFormat("&city={0}", HttpUtility.UrlEncode(order.BillingCity));
            //StateProvince billingStateProvince = StateProvinceManager.GetStateProvinceByID(order.BillingStateProvinceID);
            //if (billingStateProvince != null)
            //    builder.AppendFormat("&state={0}", HttpUtility.UrlEncode(billingStateProvince.Abbreviation));
            //else
            //    builder.AppendFormat("&state={0}", HttpUtility.UrlEncode(order.BillingStateProvince));
            //Country billingCountry = CountryManager.GetCountryByID(order.BillingCountryID);
            //if (billingCountry != null)
            //    builder.AppendFormat("&country={0}", HttpUtility.UrlEncode(billingCountry.TwoLetterISOCode));
            //else
            //    builder.AppendFormat("&country={0}", HttpUtility.UrlEncode(order.BillingCountry));
            //builder.AppendFormat("&Email={0}", HttpUtility.UrlEncode(order.BillingEmail));
            //HttpContext.Current.Response.Redirect(builder.ToString());
            return string.Empty;
        }

        /// <summary>
        /// Captures payment (from admin panel)
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void Capture(Order order, ref ProcessPaymentResult processPaymentResult)
        {
            throw new NopException("Capture method not supported");
        }

        #endregion

        #region Properies

        /// <summary>
        /// Gets a value indicating whether capture is allowed from admin panel
        /// </summary>
        public bool CanCapture
        {
            get
            {
                return false;
            }
        }
        #endregion
    }
}



document structure:


after this preparation, I tried to debug and I was very confident that I almost done this. but- -

choose payment gateway-->alipay


click next


click next


click confirm to enter debug mode, i set up break point here.

Begin to debug


first problem:


payment info: all fields: Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized.

and I continue to debug, when the process reached
IPaymentMethod iPaymentMethod = Activator.CreateInstance(Type.GetType(paymentMethod.ClassName)) as IPaymentMethod;
another problem occured and at this time, paymentMethod.ClassName = "NopSolutions.NopCommerce.Payment.Methods.Alipay.AlipayPaymentProcessor, Nop.Payment.Alipay".

program breaks and the error message is: Value cannot be null. Parameter name: type, which means Activator can not create an instance of class(NopSolutions.NopCommerce.Payment.Methods.Alipay.AlipayPaymentProcessor, Nop.Payment.Alipay), why???


I'm wondering why this happened.
Anyone got a clue?

Many thanks in advance.

As soon as I finish this payment gateway, I will put it on the extension section of this website.
14 anos atrás
need help:)
14 anos atrás
[quote]Hi Ian ,

Im in Shanghai and i cant see your images and im new to nopcommerce ( using DashCommerce comerrcially for 3 years and considering something else).

Anyway I cant see your pictures ( Great Firewall) but Activator.GetInstance ( or Type.GetType) is always a pain . For external assemblies you need to add a reference to the assembly and you need the FULL assembly name . eg paymentMethod.ClassName should be something like


TopNamespace.SubNameSpace.ContainingClass+NestedClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089


http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx



I have Alipay code working for DashCOmmerce if you need a copy of some code.

Regards, [/quote]

Hi, I sent a message to u, my msn: [email protected]
                           my qq: 75172352

Please add me, then we can have a discussion of my problem.

Many thanks.

Larry with love:)
14 anos atrás
for the missing images, coz I shut down the server:(
14 anos atrás
Value cannot be null. Parameter name: type

after doing some research on Msdn, I found "Value cannot be null. Parameter name: type"

is ArgumentNullException typeName is a null reference (Nothing in Visual Basic).

http://msdn.microsoft.com/en-gb/library/d133hta4(VS.80).aspx

I also saw the topic:
http://forums.asp.net/p/980185/1255041.aspx

which is almost exactly what i'm suffering at the moment.

but i'm still confusing anyway.

any help pls?

many thanks
14 anos atrás
class view is here, please copy and paste the link to the browser.

http://www.missfantacy.com/AlipayCodeImage/8.1.jpg
14 anos atrás
Hello,

is there any alipay gateway available?
Unfortunately the link http://www.missfantacy.com/AlipayCodeImage/8.1.jpg does not work since www.missfantacy.com is down.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.