-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f3abdf
commit c8dd5b8
Showing
11 changed files
with
570 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using ICanPay.Alipay; | ||
using ICanPay.Core; | ||
|
||
namespace Zxw.Framework.Pay.AliPay | ||
{ | ||
/// <summary> | ||
/// 支付宝支付 | ||
/// </summary> | ||
public class AliPay:PayBase<AlipayGateway> | ||
{ | ||
public AliPay(IGateways getGateways) : base(getGateways) | ||
{ | ||
} | ||
|
||
public void BillDownload(string billType, string billDate) | ||
{ | ||
base.BillDownload(new Auxiliary() {BillDate = billDate, BillType = billType}); | ||
} | ||
|
||
public string CreateOrder(Order order, GatewayTradeType tradeType, | ||
Action<object, PaymentSucceedEventArgs> succeed = null, | ||
Action<object, PaymentFailedEventArgs> failed = null) | ||
{ | ||
return base.CreateOrder(order, tradeType, succeed, failed); | ||
} | ||
|
||
public Notify Cancel(string orderNo) | ||
{ | ||
return (Notify)base.Cancel(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo | ||
}); | ||
} | ||
|
||
public Notify Close(string orderNo) | ||
{ | ||
return (Notify)base.Close(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo | ||
}); | ||
} | ||
|
||
public Notify Query(string orderNo) | ||
{ | ||
return (Notify)base.Query(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo | ||
}); | ||
} | ||
|
||
public Notify Refund(string orderNo) | ||
{ | ||
return (Notify)base.Refund(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo | ||
}); | ||
} | ||
|
||
public Notify RefundQuery(string orderNo, string refundNo) | ||
{ | ||
return (Notify)base.RefundQuery(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo, | ||
OutRefundNo = refundNo | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using ICanPay.Core; | ||
|
||
namespace Zxw.Framework.Pay | ||
{ | ||
public interface IPay | ||
{ | ||
void BillDownload(IAuxiliary auxiliary); | ||
|
||
string CreateOrder(IOrder order, GatewayTradeType tradeType, | ||
Action<object, PaymentSucceedEventArgs> succeed = null, | ||
Action<object, PaymentFailedEventArgs> failed = null); | ||
|
||
INotify Cancel(IAuxiliary auxiliary); | ||
|
||
INotify Close(IAuxiliary auxiliary); | ||
|
||
INotify Query(IAuxiliary auxiliary); | ||
|
||
INotify Refund(IAuxiliary auxiliary); | ||
|
||
INotify RefundQuery(IAuxiliary auxiliary); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using ICanPay.Core; | ||
|
||
namespace Zxw.Framework.Pay | ||
{ | ||
public abstract class PayBase<TGateWay> :IPay | ||
where TGateWay : GatewayBase | ||
{ | ||
private IGateways _gateways; | ||
|
||
public virtual GatewayBase Gateway => _gateways.Get<TGateWay>(); | ||
|
||
protected PayBase(IGateways getGateways) | ||
{ | ||
_gateways = getGateways; | ||
} | ||
public virtual void BillDownload(IAuxiliary auxiliary) | ||
{ | ||
Gateway.BillDownload(auxiliary); | ||
} | ||
|
||
public virtual string CreateOrder(IOrder order, GatewayTradeType tradeType, Action<object, PaymentSucceedEventArgs> succeed = null, Action<object, PaymentFailedEventArgs> failed = null) | ||
{ | ||
if (tradeType == GatewayTradeType.Barcode) | ||
{ | ||
if (succeed == null) | ||
{ | ||
throw new ArgumentNullException(nameof(succeed)); | ||
} | ||
if (failed == null) | ||
{ | ||
throw new ArgumentNullException(nameof(failed)); | ||
} | ||
Gateway.PaymentSucceed += succeed; | ||
Gateway.PaymentFailed += failed; | ||
} | ||
return Gateway.Payment(order); | ||
} | ||
|
||
public virtual INotify Cancel(IAuxiliary auxiliary) | ||
{ | ||
return Gateway.Cancel(auxiliary); | ||
} | ||
|
||
public virtual INotify Close(IAuxiliary auxiliary) | ||
{ | ||
return Gateway.Close(auxiliary); | ||
} | ||
|
||
public virtual INotify Query(IAuxiliary auxiliary) | ||
{ | ||
return Gateway.Query(auxiliary); | ||
} | ||
|
||
public virtual INotify Refund(IAuxiliary auxiliary) | ||
{ | ||
return Gateway.Refund(auxiliary); | ||
} | ||
|
||
public virtual INotify RefundQuery(IAuxiliary auxiliary) | ||
{ | ||
return Gateway.RefundQuery(auxiliary); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using ICanPay.Core; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Zxw.Framework.NetCore.IoC; | ||
|
||
namespace Zxw.Framework.Pay | ||
{ | ||
public static class PayExtensions | ||
{ | ||
public static IServiceCollection RegisterPayMerchant<TGateway, TMerchant>(this IServiceCollection services, | ||
TMerchant merchant) | ||
where TGateway : GatewayBase, new() | ||
where TMerchant : class, IMerchant | ||
{ | ||
if (services == null) | ||
throw new ArgumentNullException(nameof(services)); | ||
if (merchant == null) | ||
throw new ArgumentNullException(nameof(merchant)); | ||
services.AddICanPay(m => | ||
{ | ||
var gateways = AspectCoreContainer.Resolve<IGateways>() ?? new Gateways(); | ||
var gateway = (TGateway) Activator.CreateInstance(typeof(TGateway), (object) merchant); | ||
gateways.Add(gateway); | ||
|
||
return gateways; | ||
}); | ||
return services; | ||
} | ||
|
||
public static IApplicationBuilder UsePay(this IApplicationBuilder app) | ||
{ | ||
if (app == null) | ||
throw new ArgumentNullException(nameof(app)); | ||
return app.UseICanPay(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using ICanPay.Core; | ||
using ICanPay.Unionpay; | ||
|
||
namespace Zxw.Framework.Pay.UnionPay | ||
{ | ||
/// <summary> | ||
/// 银联支付 | ||
/// </summary> | ||
public class UnionPay:PayBase<UnionpayGateway> | ||
{ | ||
public UnionPay(IGateways getGateways) : base(getGateways) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// 银联对账单下载 | ||
/// </summary> | ||
/// <param name="billType"></param> | ||
/// <param name="billDate"></param> | ||
public void BillDownload(string billType, string billDate) | ||
{ | ||
base.BillDownload(new Auxiliary() { BillDate = billDate, TxnTime = billType }); | ||
} | ||
|
||
/// <summary> | ||
/// 下单 | ||
/// </summary> | ||
/// <param name="order"></param> | ||
/// <param name="tradeType"></param> | ||
/// <param name="succeed"></param> | ||
/// <param name="failed"></param> | ||
/// <returns></returns> | ||
public string CreateOrder(Order order, GatewayTradeType tradeType, | ||
Action<object, PaymentSucceedEventArgs> succeed = null, | ||
Action<object, PaymentFailedEventArgs> failed = null) | ||
{ | ||
return base.CreateOrder(order, tradeType, succeed, failed); | ||
} | ||
|
||
/// <summary> | ||
/// 取消订单 | ||
/// </summary> | ||
/// <param name="tradeNo"></param> | ||
/// <param name="outRefundNo"></param> | ||
/// <param name="refundAmount"></param> | ||
/// <returns></returns> | ||
public Notify Cancel(string tradeNo, string outRefundNo, double? refundAmount) | ||
{ | ||
return (Notify)base.Cancel(new Auxiliary() | ||
{ | ||
TradeNo = tradeNo, | ||
OutRefundNo = outRefundNo, | ||
TxnTime = DateTime.Now.ToString("yyyyMMddHHmmss"), | ||
RefundAmount = refundAmount | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// 查询订单 | ||
/// </summary> | ||
/// <param name="orderNo"></param> | ||
/// <returns></returns> | ||
public Notify Query(string orderNo) | ||
{ | ||
return (Notify)base.Query(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo | ||
}); | ||
} | ||
/// <summary> | ||
/// 订单退款 | ||
/// </summary> | ||
/// <param name="orderNo"></param> | ||
/// <returns></returns> | ||
public Notify Refund(string orderNo) | ||
{ | ||
return (Notify)base.Refund(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo | ||
}); | ||
} | ||
/// <summary> | ||
/// 订单退款查询 | ||
/// </summary> | ||
/// <param name="orderNo"></param> | ||
/// <param name="refundNo"></param> | ||
/// <returns></returns> | ||
public Notify RefundQuery(string orderNo, string refundNo) | ||
{ | ||
return (Notify)base.RefundQuery(new Auxiliary() | ||
{ | ||
OutTradeNo = orderNo, | ||
OutRefundNo = refundNo | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.