分享 nopCommerce2.0版本 payment插件之wedopay信用卡通道

外贸网站基于第三方的信用卡付款通道wedopay的付款插件 源码共享。如有问题多多交流:我的电子邮件cnchjf#qq.com(#换@) 

希望志同道合的到我们的大群里.net 技术交流群4 1 0 5 0 4 8 0 加群 请注明:nopcommerce

 /Files/chjf2008/Nop.Plugin.Payments.Wedopay.rar

其中 需要配置的信息 本人都放在语言资源包中了,这样方便在后台中修改,以不至于去修改web.config文件,所以在view 文件夹下的

Configure.cshtml 是多余的。

 

主要实现的代码:

WedopayPaymentProcessor.cs

此类要实现

BasePlugin, IPaymentMethod 中的方法,具体的可以见类库大打包文件。

 

 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Configuration;
using System.Web.Routing;
using System.Xml;
using System.Xml.Serialization;

using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Core.Domain.Shipping;
using Nop.Core.Plugins;
using Nop.Plugin.Payments.Wedopay.Controllers;
using Nop.Services.Catalog;
using Nop.Services.Common;
using Nop.Services.Configuration;
using Nop.Services.Customers;
using Nop.Services.Directory;
using Nop.Services.Localization;
using Nop.Services.Logging;
using Nop.Services.Orders;
using Nop.Services.Payments;
using Nop.Services.Shipping;
using Nop.Services.Tax;
using Nop.Plugin.Payments.Wedopay.Models;
using System.Net;
using System.Collections.Specialized;

namespace Nop.Plugin.Payments.Wedopay
{
     public  class WedopayPaymentProcessor : BasePlugin, IPaymentMethod
    {
         #region Fields

         private  readonly IShippingService _shippingService;
         private  readonly IWorkContext _workContext;
         private  readonly ICustomerService _customerService;
         private  readonly IOrderProcessingService _orderProcessingService;
         private  readonly IOrderService _orderService;
         private  readonly ILocalizationService _localocalizationService;


         #endregion

         #region Ctor

         public WedopayPaymentProcessor(IShippingService shippingService, IWorkContext workContext,
            ICustomerService customerService,
            IOrderProcessingService orderProcessingService,
            IOrderService orderService, ILocalizationService localizationService,
           ILocalizationService _localocalizationService)
        {
             this._shippingService = shippingService;
             this._workContext = workContext;
             this._customerService = customerService;
             this._orderProcessingService = orderProcessingService;
             this._orderService = orderService;
             this._localocalizationService = localizationService;
        }

         #endregion

         public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result =  new ProcessPaymentResult();
            result.NewPaymentStatus = PaymentStatus.Pending;
             // result.AuthorizationTransactionId = processPaymentRequest.GoogleOrderNumber;
             return result;

        }
         public  void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            var ShippingAddress = postProcessPaymentRequest.Order.ShippingAddress;
            var order = postProcessPaymentRequest.Order;
            
            var BillNo = order.OrderGuid.ToString();            
            var Amount = order.OrderTotal.ToString();
            var Language =  2;
            var Currency =  1;
            var PaymentType =  5;
             // get payment config from language resource system
            var MD5key = _localocalizationService.GetResource( " Config.Payment.Wedopay.Md5Key ").Trim();
            var MerNo = _localocalizationService.GetResource( " Config.Payment.Wedopay.MerNo ").Trim();
            var ReturnURL = _localocalizationService.GetResource( " Config.Payment.Wedopay.ReturnURL ").Trim();
            var SubmitURL = _localocalizationService.GetResource( " Config.Payment.Wedopay.SubmitURL ").Trim();
             /// end
            var md5src = MerNo + BillNo + Currency + Amount + Language + ReturnURL + MD5key;
            var MD5info = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(md5src,  " MD5 ");
            List< string> productNameList =  new List< string>();
             foreach (var pv  in order.OrderProductVariants)
            {
                productNameList.Add(pv.ProductVariant.Product.Name);
            }           
           
            System.Text.StringBuilder formBuild =  new StringBuilder();
            formBuild.Append( " <html><head> ");
            formBuild.Append( " <script> function submit(){document.getElementById('frmWedopay').submit();}</script> ");
            formBuild.Append( " </head><body> ");
            formBuild.Append( " <form id=\"frmWedopay\" name=\"pay\" action=\" "+SubmitURL+ " \" method=\"post\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + Currency +  " \" name=\"Currency\" id=\"Currency\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\"\"  name=\"OrderDesc\" id=\"OrderDesc\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\"\" name=\"Remark\" id=\"Remark\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\"\" name=\"OrderURL\" id=\"OrderURL\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ReturnURL +  " \" name=\"ReturnURL\" id=\"ReturnURL\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + Language +  " \" name=\"Language\" id=\"Language\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + order.OrderGuid.ToString() +  " \" name=\"BillNo\" id=\"BillNo\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + MerNo +  " \" name=\"MerNo\" id=\"MerNo\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + MD5info +  " \" name=\"MD5info\" id=\"MD5info\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.FirstName +  " \" name=\"shippingFirstName\" id=\"shippingFirstName\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.LastName +  " \" name=\"shippingLastName\" id=\"shippingLastName\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.Email +  " \" name=\"shippingEmail\" id=\"shippingEmail\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.PhoneNumber +  " \" name=\"shippingPhone\" id=\"shippingPhone\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.ZipPostalCode +  " \" name=\"shippingZipcode\" id=\"shippingZipcode\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.Address1 + " \" name=\"shippingAddress\" id=\"shippingAddress\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.City +  " \" name=\"shippingCity\" id=\"shippingCity\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + ShippingAddress.StateProvince.Name +  " \" name=\"shippingSstate\" id=\"shippingSstate\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " +  string.Join( " , ", productNameList.ToArray()) +  " \" name=\"products\" id=\"products\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\"\" name=\"MerWebsite\" id=\"MerWebsite\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + order.OrderTotal.ToString() +  " \" name=\"Amount\" id=\"Amount\"> ");
            formBuild.Append( " <input type=\"hidden\" value=\" " + PaymentType +  " \" name=\"paymenttype\" id=\"paymenttype\"> ");
            formBuild.Append( " </form> ");
            formBuild.Append( " <script language='javascript'>submit();</script> ");
            formBuild.Append( " </body></html> ");
             string outputString = formBuild.ToString();
            HttpContext.Current.Response.Write(outputString);
            HttpContext.Current.Response.End();
        }

         public  decimal GetAdditionalHandlingFee()
        {
             return  decimal.Zero;
        }

         public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result =  new CapturePaymentResult();
             return result;
        }

         public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result =  new RefundPaymentResult();
            result.AddError( " Refund method not supported ");
             return result;
        }

         public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result =  new VoidPaymentResult();
            result.AddError( " Void method not supported ");
             return result;
        }

         public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result =  new ProcessPaymentResult();
            result.AddError( " Recurring payment not supported ");
             return result;
        }

         public CancelRecurringPaymentResult CancelRecurringPayment(CancelRecurringPaymentRequest cancelPaymentRequest)
        {
            var result =  new CancelRecurringPaymentResult();
            result.AddError( " Recurring payment not supported ");
             return result;
        }

         public  void GetConfigurationRoute( out  string actionName,  out  string controllerName,  out RouteValueDictionary routeValues)
        {
            actionName =  " Configure ";
            controllerName =  " PaymentWedopay ";
            routeValues =  new RouteValueDictionary() { {  " Namespaces "" Nop.Plugin.Payments.Wedopay.Controllers " }, {  " area "null } };
        }


         ///   <summary>
        
///  Gets a route for payment info
        
///   </summary>
        
///   <param name="actionName"> Action name </param>
        
///   <param name="controllerName"> Controller name </param>
        
///   <param name="routeValues"> Route values </param>
         public  void GetPaymentInfoRoute( out  string actionName,  out  string controllerName,  out RouteValueDictionary routeValues)
        {
            actionName =  " PaymentInfo ";
            controllerName =  " PaymentWedopay ";
            routeValues =  new RouteValueDictionary() { {  " Namespaces "" Nop.Plugin.Payments.Wedopay.Controllers " }, {  " area "null } };
        }        

         public Type GetControllerType()
        {
             return  typeof(PaymentWedopayController);
        }

         #region Properies

         ///   <summary>
        
///  Gets a value indicating whether capture is supported
        
///   </summary>
         public  bool SupportCapture
        {
             get
            {
                 return  true;
            }
        }

         ///   <summary>
        
///  Gets a value indicating whether partial refund is supported
        
///   </summary>
         public  bool SupportPartiallyRefund
        {
             get
            {
                 return  false;
            }
        }

         ///   <summary>
        
///  Gets a value indicating whether refund is supported
        
///   </summary>
         public  bool SupportRefund
        {
             get
            {
                 return  true;
            }
        }

         ///   <summary>
        
///  Gets a value indicating whether void is supported
        
///   </summary>
         public  bool SupportVoid
        {
             get
            {
                 return  true;
            }
        }

         ///   <summary>
        
///  Gets a recurring payment type of payment method
        
///   </summary>
         public RecurringPaymentType RecurringPaymentType
        {
             get
            {
                 return RecurringPaymentType.Automatic;
            }
        }

         ///   <summary>
        
///  Gets a payment method type
        
///   </summary>
         public PaymentMethodType PaymentMethodType
        {
             get
            {
                 return PaymentMethodType.Standard;
            }
        }

         #endregion
    }
}

 

 

 

你可能感兴趣的:(com)