OutTradeNo = "订单号"

时间:2022-06-16 08:14:44

跟着微软的开源,越来越多的项目撑持跨平台,但是各类付出平台供给的类库,又老又不撑持跨平台,吐槽下,尤其是微信,还有好多坑,于是ICanPay诞生了,今天就来讲ICanPay是什么,,怎么使用?

ICanPay是一个撑持多商户多种付出方法的跨平台网关措置惩罚惩罚类库,使用ICanPay可以简化订单的创建、盘问、退款和接收网关返回的付出通知等操纵。

目前撑持的付出网关有:付出宝(Alipay)、微信付出(Wechatpay)、银联付出(Unionpay)

下面以付出宝为例,其余两种付出,请参考Wiki

1. 配置商户数据 1.在Startup中添加商户数据 services.AddICanPay(a => { var gateways = new Gateways(); var merchant = new Merchant { AppId = "", NotifyUrl = "", ReturnUrl = "", AlipayPublicKey = "", Privatekey = "" }; gateways.Add(new AlipayGateway(merchant)); return gateways; }); 2.在Startup中使用ICanPay app.UseICanPay();

以上就简单的完成了对ICanPay的配置操纵

2.付出

ICanPay撑持多种付出方法,下面就来讲解如何使用

1.获取付出网关 private readonly IGateways gateways; public YourController(IGateways gateways) { this.gateways = gateways; } 2.创建订单 var order = new Order() { Amount = 0.01, OutTradeNo = "订单号", Subject = "测试", }; 3.设置付出方法 var gateway = gateways.Get<AlipayGateway>(GatewayTradeType.Web); 4.付出 gateway.Payment(order);

特殊说明:GatewayTradeType.Barcode付出方法,需要再实现PaymentSucceed和PaymentFailed事件

3.异步通知 1.获取付出网关 private readonly IGateways gateways; public NotifyController(IGateways gateways) { this.gateways = gateways; } 2.实现付出通知事件 PaymentNotify notify = new PaymentNotify(gateways); notify.PaymentSucceed += Notify_PaymentSucceed; notify.PaymentFailed += Notify_PaymentFailed; notify.UnknownGateway += Notify_UnknownGateway; private void Notify_PaymentSucceed(object sender, PaymentSucceedEventArgs e) { // 付出告成不时的措置惩罚惩罚代码 /* 建议添加以下校验。 * 1、需要验证该通知数据中的OutTradeNo是否为商户系统中创建的订单号, * 2、判断Amount是否确实为该订单的实际金额(即商户订单创建时的金额), */ if (e.GatewayType == typeof(AlipayGateway)) { var notify = (Notify)e.Notify; } } private void Notify_PaymentFailed(object sender, PaymentFailedEventArgs e) { // 付出掉败时的措置惩罚惩罚代码 } private void Notify_UnknownGateway(object sender, UnknownGatewayEventArgs e) { // 无法识别付出网关时的措置惩罚惩罚代码 } 3.接出入付通知 await notify.ReceivedAsync(); 4.帮助接口 1.盘问 var notify = (Notify)gateway.Query(new Auxiliary { OutTradeNo = "订单号" }); 2.勾销 var notify = (Notify)gateway.Cancel(new Auxiliary { OutTradeNo = "订单号" }); 3.* var notify = (Notify)gateway.Close(new Auxiliary { OutTradeNo = "订单号" }); 4.退款 var notify = (Notify)gateway.Refund(new Auxiliary { OutTradeNo = "订单号", RefundAmount = 123, OutRefundNo = "退款单号" }); 5.退款盘问 var notify = (Notify)gateway.RefundQuery(new Auxiliary { OutTradeNo = "订单号", OutRefundNo = "退款单号" }); 6.对账单下载 gateway.BillDownload(new Auxiliary { BillType = "trade", BillDate = "2017-10-31" });

以上就简单的讲解了如何使用ICanPay,如果有什么问题,也可以在Github上提问。
项目地点:ICanPay

标签: