You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
8.8 KiB
C#

using POSV.Cef.FastTemplate.PayMent.Base;
using POSV.Entity;
using POSV.ShoppingCart;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static POSV.Cef.FastTemplate.PayMent.Base.PayBase;
namespace POSV.Cef.FastTemplate.PayMent
{
public class PayOperation
{
//================= construct function ==================
#region construct function
/// <summary>
/// 参数在对象内会copy
/// </summary>
public PayOperation(OrderObject orderObject, string _code)
{
var _data = ObjectUtils.Copy(orderObject);
var code = ObjectUtils.Copy(_code);
this.m_PayCode = code;
this.m_OrderObject = _data;
}
#endregion
//================== private fields =====================
#region fields
/// <summary>
/// 支付对象
/// </summary>
public OrderObject m_OrderObject;
/// <summary>
/// 支付条码
/// </summary>
public string m_PayCode = "";
/// <summary>
/// 支付参数
/// </summary>
public PayMode m_CurrentPayMode = null;
/// <summary>
/// 异步通知
/// </summary>
public PayResultAsyncCallBack AsyncPayResult;
/// <summary>
/// 支付对象
/// </summary>
private PayBase m_pay = null;
private string meseeage = "";
public string m_Message
{
get { return (this.m_pay?.m_Message == null ? meseeage : this.m_pay?.m_Message); }
set { meseeage = value; }
}
#endregion
//================== public function =======================
/// <summary>
/// 同步
/// </summary>
/// <returns></returns>
public PayItem PayStart()
{
if (this.VerifyParameter())
{
//获取支付参数
this.GetPayMode();
//初始化支付对象
this.Initialize();
if (this.m_pay == null)
{
return null;
}
else
{
this.m_pay.SaveSaomaTicket(string.Format("{0}_{1}", this.m_OrderObject.StoreNo, this.m_OrderObject.TradeNo), this.m_PayCode);
return this.m_pay.PayStart();
}
}
else
{
return null;
}
}
/// <summary>
/// 异步回掉
/// </summary>
public void AsyncPayStart()
{
if (this.AsyncPayResult != null)
{
try
{
//获取支付参数
this.GetPayMode();
//初始化支付对象
this.Initialize();
}
catch (Exception)
{
this.m_pay.m_Message = this.m_Message;
}
this.m_pay.SaveSaomaTicket(string.Format("{0}_{1}", this.m_OrderObject.StoreNo, this.m_OrderObject.TradeNo), this.m_PayCode);
this.m_pay.AsyncPayResult = this.AsyncPayResult;
this.m_pay.AsyncPayStart();
}
else
{
//强行提示调用者
throw new Exception("注意,AsyncPayResult参数没有赋值");
}
}
/// <summary>
/// 外部验证|验证调用参数
/// </summary>
public bool VerifyParameter()
{
if (this.m_OrderObject == null)
{
this.m_Message = "订单对象为空,请确认参数";
return false;
}
if (string.IsNullOrEmpty(this.m_PayCode))
{
this.m_Message = "请扫描或输入支付码...";
return false;
}
if (!string.IsNullOrEmpty(this.m_PayCode) && this.m_PayCode.Length >= 16)
{
string prefix = this.m_PayCode.Substring(0, 2);
switch (prefix)
{
case "10":
case "11":
case "12":
case "13":
case "14":
case "15":
break;
case "25":
case "26":
case "27":
case "28":
case "29":
case "30":
break;
case "70":
case "71":
case "72":
case "73":
case "74":
case "75":
break;
default:
this.m_Message = "支付码不合法";
return false;
}
}
else
{
this.m_Message = "支付码不合法...";
return false;
}
return true;
}
//================== private function =======================
private void Initialize()
{
if (this.m_CurrentPayMode == null)
{
this.m_Message = "尚未配置支付参数...";
return;
}
var parameter = this.m_CurrentPayMode.Body;
//会员不需要配置
if ((parameter == null || parameter.Count == 0) && !this.m_CurrentPayMode.No.Equals("02"))
{
this.m_Message = "尚未配置支付参数...";
return;
}
//获取支付渠道
string channel = "";
if (this.m_CurrentPayMode.No.Equals("02"))
{
channel = "Member";
}
else
{
channel = (parameter.ContainsKey("channel") ? parameter["channel"].ToString() : "").ToLower();
}
switch (channel)
{
//case "alipay":
//case "wxpay":
//case "subalipay":
//case "subwxpay":
// {
// //this._payChannel = PayChannelEnum.原生支付;
// }
// break;
case "leshua":
{
//乐刷支付
//this.m_pay = new LESHUA_Pay();
}
break;
case "saobei":
{
//this._payChannel = PayChannelEnum.扫呗支付;
this.m_pay = new SAOBEI_Pay();
}
break;
case "Member":
this.m_pay = new Member_Pay();
break;
default:
channel = "";//zhangy 2020-03-21 Add 暂不支持的支付通道
break;
}
//zhangy 2020 - 03 - 21 Add 暂不支持的支付通道
if (string.IsNullOrEmpty(channel))
{
this.m_Message = "暂不支持的支付通道...";
return;
}
this.m_pay.m_CurrentPayMode = this.m_CurrentPayMode;
this.m_pay.m_OrderObject = this.m_OrderObject;
this.m_pay.m_PayCode = this.m_PayCode;
}
/// <summary>
/// 获取支付方式
/// </summary>
private void GetPayMode()
{
string prefix = this.m_PayCode.Substring(0, 2);
switch (prefix)
{
case "10":
case "11":
case "12":
case "13":
case "14":
case "15":
{
//微信
this.m_CurrentPayMode = OrderUtils.GetPayMode("05");
}
break;
case "25":
case "26":
case "27":
case "28":
case "29":
case "30":
{
//支付宝
this.m_CurrentPayMode = OrderUtils.GetPayMode("04");
}
break;
case "70":
case "71":
case "72":
case "73":
case "74":
case "75":
{
//会员卡
this.m_CurrentPayMode = OrderUtils.GetPayMode("02");
}
break;
}
}
}
}