Skip to content

Commit

Permalink
Merge pull request #51 from EasyAbp/abp-wechat-2.1.0
Browse files Browse the repository at this point in the history
Upgrade to Abp.WeChat 2.1.0 and remove the local WeChatPay settings
  • Loading branch information
gdlcf88 authored Jan 8, 2023
2 parents b2dba3a + 39931d9 commit b023ba6
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 200 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>

<AbpVersion>6.0.1</AbpVersion>
<EasyAbpAbpWeChatModuleVersion>1.10.2</EasyAbpAbpWeChatModuleVersion>
<EasyAbpAbpWeChatModuleVersion>2.1.0</EasyAbpAbpWeChatModuleVersion>

</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
46 changes: 23 additions & 23 deletions docs/Prepayment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,23 @@ We have launched an online demo for this module: [https://pay.samples.easyabp.io
```
> please refer to the `ConfigurePaymentServicePrepayment` method in the [Web module](https://github.com/EasyAbp/PaymentService/blob/master/samples/PaymentServiceSample/aspnet-core/src/PaymentServiceSample.Web/PaymentServiceSampleWebModule.cs) of the sample app.
3. Access the API `/api/paymentService/prepayment/account` (with the request param `UserId`), then the account will be created automatically.
3. Use the API `/api/payment-service/prepayment/account` (with the request param `UserId`), then the account will be created automatically.

4. Top up your account:

1. Use the API `/api/paymentService/prepayment/account/topUp` to start top-up.
1. Use the API `/api/payment-service/prepayment/account/top-up` to start top-up.

2. Use the API `/api/paymentService/prepayment/account/{id}` to get the `ExtraProperties.PendingTopUpPaymentId`.
2. Use the API `/api/payment-service/prepayment/account/{id}` to get the `ExtraProperties.PendingTopUpPaymentId`.

3. Use the API `/api/paymentService/payment/{id}/pay` to finish the payment. (for example you can use WeChatPay to top up your prepayment account, please refer to the document of the payment method you want)
3. Use the API `/api/payment-service/payment/{id}/pay` to finish the payment. (for example you can use WeChatPay to top up your prepayment account, please refer to the document of the payment method you want)

4. If you want to cancel an ongoing payment, please use the API `/api/paymentService/payment/{id}/cancel`.
4. If you want to cancel an ongoing payment, please use the API `/api/payment-service/payment/{id}/cancel`.

> Or just change the balance directly with the management pages if you have the account management permission.

5. Pay with prepayment account.
1. Users can use the API `/api/paymentService/payment/{id}/pay` to finish the payment, please put the necessary params in the `ExtraProperties`:

```
{
"extraProperties": {
"AccountId": "82D49C17-9282-4822-9EE9-A0685529D707" // Id of the prepayment account that you use to pay
}
}
```

> Skip the following steps if you are using the [EasyAbp.EShop](https://github.com/EasyAbp/EShop).
<details>
<summary>See more steps</summary>

2. Create a payment with the payment method `Prepayment`.
> Other modules or apps that depend on PaymentService module should create payments via distributed events.
1. Create a payment with the payment method `Prepayment`.
> Other modules or apps should create payments via distributed events. Skip this step if you are using the [EasyAbp.EShop](https://github.com/EasyAbp/EShop).
<details>
<summary>See sample code</summary>
Expand All @@ -107,9 +92,24 @@ We have launched an online demo for this module: [https://pay.samples.easyabp.io
}).ToList()
});
```
> please refer to the [usage in EShop](https://github.com/EasyAbp/EShop/blob/dev/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs)
> please refer to the [usage in EShop](https://github.com/EasyAbp/EShop/blob/dev/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs)
</details>

2. Use the API `/api/payment-service/payment/{id}/pay` to finish the payment, please put the necessary params in the `ExtraProperties`:

```
{
"extraProperties": {
"AccountId": "82D49C17-9282-4822-9EE9-A0685529D707" // Id of the prepayment account that you use to pay
}
}
```

> Skip the following steps if you are using the [EasyAbp.EShop](https://github.com/EasyAbp/EShop).
<details>
<summary>See more steps</summary>

3. Handle the payment created distributed event to get and remember the `PaymentId`.
<details>
<summary>See sample code</summary>
Expand Down
39 changes: 20 additions & 19 deletions docs/WeChatPay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,8 @@ We have launched an online demo for this module: [https://pay.samples.easyabp.io
> See the [demo](https://github.com/EasyAbp/PaymentService/blob/master/samples/PaymentServiceSample/aspnet-core/src/PaymentServiceSample.Web/appsettings.json), it is also according to the [document](https://github.com/EasyAbp/Abp.WeChat/blob/master/doc/WeChatPay.md) of the EasyAbp.Abp.WeChat module.
3. Pay with WeChatPay.
1. Users can use the API `/api/paymentService/payment/{id}/pay` to finish the payment, please put the necessary params in the `ExtraProperties`:

```
{
"extraProperties": {
"trade_type": "JSAPI",
"appid": "wx81a2956875268fk8" // You can specify an appid or get it from the input from the client.
}
}
```

> Skip the following steps if you are using the [EasyAbp.EShop](https://github.com/EasyAbp/EShop).
<details>
<summary>See more steps</summary>

2. Create a payment with the payment method `WeChatPay`.
> Other modules or apps that depend on PaymentService module should create payments via distributed events.
1. Create a payment with the payment method `WeChatPay`.
> Other modules or apps should create payments via distributed events. Skip this step if you are using the [EasyAbp.EShop](https://github.com/EasyAbp/EShop).
<details>
<summary>See sample code</summary>
Expand All @@ -85,9 +69,26 @@ We have launched an online demo for this module: [https://pay.samples.easyabp.io
}).ToList()
});
```
> please refer to the [usage in EShop](https://github.com/EasyAbp/EShop/blob/dev/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs)
> please refer to the [usage in EShop](https://github.com/EasyAbp/EShop/blob/dev/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs)
</details>

2. Users can use the API `/api/payment-service/payment/{id}/pay` (POST) to finish the payment, please put the necessary params in the `ExtraProperties`:

```
{
"extraProperties": {
"trade_type": "JSAPI",
"appid": "wx81a2956875268fk8" // You can specify an appid or get it from the input from the client.
"mch_id": "10000100" // If it's null, use the default settings/options value you configured in the Abp.WeChat.Pay module.
}
}
```

> Skip the following steps if you are using the [EasyAbp.EShop](https://github.com/EasyAbp/EShop).
<details>
<summary>See more steps</summary>

3. Handle the payment created distributed event to get and remember the `PaymentId`.
<details>
<summary>See sample code</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Pay.Services;
using EasyAbp.Abp.WeChat.Pay.Services.Pay;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
Expand All @@ -11,28 +12,31 @@ namespace EasyAbp.PaymentService.WeChatPay.Background;
public class CloseWeChatPayOrderJob : IAsyncBackgroundJob<CloseWeChatPayOrderJobArgs>, ITransientDependency
{
private readonly ICurrentTenant _currentTenant;
private readonly ServiceProviderPayService _serviceProviderPayService;
private readonly IAbpWeChatPayServiceFactory _abpWeChatPayServiceFactory;

public CloseWeChatPayOrderJob(
ICurrentTenant currentTenant,
ServiceProviderPayService serviceProviderPayService)
IAbpWeChatPayServiceFactory abpWeChatPayServiceFactory)
{
_currentTenant = currentTenant;
_serviceProviderPayService = serviceProviderPayService;
_abpWeChatPayServiceFactory = abpWeChatPayServiceFactory;
}

public virtual async Task ExecuteAsync(CloseWeChatPayOrderJobArgs args)
{
using var change = _currentTenant.Change(args.TenantId);

var orderQueryResult = await _serviceProviderPayService.CloseOrderAsync(
var serviceProviderPayService =
await _abpWeChatPayServiceFactory.CreateAsync<ServiceProviderPayWeService>(args.MchId);

var orderQueryResult = await serviceProviderPayService.CloseOrderAsync(
appId: args.AppId,
mchId: args.MchId,
subAppId: null,
subMchId: null,
outTradeNo: args.OutTradeNo
);

var dict = orderQueryResult.SelectSingleNode("xml").ToDictionary() ?? throw new NullReferenceException();
var resultCode = dict.GetOrDefault("result_code");
var errCode = dict.GetOrDefault("err_code");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Pay.Services;
using EasyAbp.Abp.WeChat.Pay.Services.Pay;
using EasyAbp.PaymentService.Payments;
using EasyAbp.PaymentService.Refunds;
Expand Down Expand Up @@ -28,7 +29,7 @@ public class WeChatPayRefundJob : IAsyncBackgroundJob<WeChatPayRefundJobArgs>, I
private readonly IPaymentRecordRepository _paymentRecordRepository;
private readonly IRefundRecordRepository _refundRecordRepository;
private readonly IWeChatPayFeeConverter _weChatPayFeeConverter;
private readonly ServiceProviderPayService _serviceProviderPayService;
private readonly IAbpWeChatPayServiceFactory _abpWeChatPayServiceFactory;

public WeChatPayRefundJob(
IGuidGenerator guidGenerator,
Expand All @@ -40,7 +41,7 @@ public WeChatPayRefundJob(
IPaymentRecordRepository paymentRecordRepository,
IRefundRecordRepository refundRecordRepository,
IWeChatPayFeeConverter weChatPayFeeConverter,
ServiceProviderPayService serviceProviderPayService)
IAbpWeChatPayServiceFactory abpWeChatPayServiceFactory)
{
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
Expand All @@ -51,7 +52,7 @@ public WeChatPayRefundJob(
_paymentRecordRepository = paymentRecordRepository;
_refundRecordRepository = refundRecordRepository;
_weChatPayFeeConverter = weChatPayFeeConverter;
_serviceProviderPayService = serviceProviderPayService;
_abpWeChatPayServiceFactory = abpWeChatPayServiceFactory;
}

[UnitOfWork(true)]
Expand Down Expand Up @@ -167,9 +168,14 @@ private async Task<Dictionary<string, string>> RequestWeChatPayRefundAsync(Payme
PaymentRecord paymentRecord, decimal refundAmount, [NotNull] string outRefundNo,
[CanBeNull] string displayReason)
{
var result = await _serviceProviderPayService.RefundAsync(
var mchId = payment.PayeeAccount;

var serviceProviderPayService =
await _abpWeChatPayServiceFactory.CreateAsync<ServiceProviderPayWeService>(mchId);

var result = await serviceProviderPayService.RefundAsync(
appId: payment.GetProperty<string>("appid"),
mchId: payment.PayeeAccount,
mchId: mchId,
subAppId: null,
subMchId: null,
transactionId: paymentRecord.TransactionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Pay.Infrastructure;
using EasyAbp.Abp.WeChat.Pay.Infrastructure.OptionResolve;
using EasyAbp.Abp.WeChat.Common.RequestHandling;
using EasyAbp.Abp.WeChat.Pay.RequestHandling;
using EasyAbp.PaymentService.Payments;
using EasyAbp.PaymentService.WeChatPay.Background;
using EasyAbp.PaymentService.WeChatPay.PaymentRecords;
Expand All @@ -15,9 +15,9 @@

namespace EasyAbp.PaymentService.WeChatPay
{
public class PaymentServiceWeChatPayHandler : IWeChatPayHandler, ITransientDependency
public class PaidWeChatPayEventHandler : IWeChatPayEventHandler, ITransientDependency
{
public WeChatHandlerType Type { get; } = WeChatHandlerType.Normal;
public WeChatHandlerType Type => WeChatHandlerType.Paid;

private readonly IDataFilter _dataFilter;
private readonly IServiceProvider _serviceProvider;
Expand All @@ -27,7 +27,7 @@ public class PaymentServiceWeChatPayHandler : IWeChatPayHandler, ITransientDepen
private readonly IPaymentRecordRepository _paymentRecordRepository;
private readonly IPaymentRepository _paymentRepository;

public PaymentServiceWeChatPayHandler(
public PaidWeChatPayEventHandler(
IDataFilter dataFilter,
IServiceProvider serviceProvider,
IUnitOfWorkManager unitOfWorkManager,
Expand All @@ -46,17 +46,23 @@ public PaymentServiceWeChatPayHandler(
}

[UnitOfWork(true)]
public virtual async Task HandleAsync(WeChatPayHandlerContext context)
public virtual async Task<WeChatRequestHandlingResult> HandleAsync(WeChatPayEventModel model)
{
var dict = context.WeChatRequestXmlData.SelectSingleNode("xml").ToDictionary() ??
var dict = model.WeChatRequestXmlData.SelectSingleNode("xml").ToDictionary() ??
throw new NullReferenceException();

if (dict.GetOrDefault("return_code") != "SUCCESS" ||
dict.GetOrDefault("device_info") != PaymentServiceWeChatPayConsts.DeviceInfo)
var returnCode = dict.GetOrDefault("return_code");
var deviceInfo = dict.GetOrDefault("device_info");

if (returnCode != "SUCCESS")
{
context.IsSuccess = false;
return new WeChatRequestHandlingResult(false, $"Unexpected return_code:{returnCode}");
}

return;
if (deviceInfo != PaymentServiceWeChatPayConsts.DeviceInfo)
{
// skip handling
return new WeChatRequestHandlingResult(true);
}

using var disabledDataFilter = _dataFilter.Disable<IMultiTenant>();
Expand Down Expand Up @@ -96,7 +102,10 @@ public virtual async Task HandleAsync(WeChatPayHandlerContext context)
// Enqueue an empty job to ensure the background job worker is alive.
await _backgroundJobManager.EnqueueAsync(new EmptyJobArgs(payment.TenantId));

_unitOfWorkManager.Current.OnCompleted(async () => { await _backgroundJobManager.EnqueueAsync(args); });
_unitOfWorkManager.Current.OnCompleted(async () =>
{
await _backgroundJobManager.EnqueueAsync(args);
});
}
else
{
Expand All @@ -108,8 +117,8 @@ public virtual async Task HandleAsync(WeChatPayHandlerContext context)
});
}
}
context.IsSuccess = true;

return new WeChatRequestHandlingResult(true);
}

protected virtual async Task<PaymentRecord> RecordPaymentResultAsync(Dictionary<string, string> dict,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using EasyAbp.Abp.WeChat.Pay;
using EasyAbp.Abp.WeChat.Pay.Infrastructure.OptionResolve;
using EasyAbp.Abp.WeChat.Pay;
using EasyAbp.PaymentService.WeChatPay.ObjectExtending;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Modularity;
Expand All @@ -19,13 +17,5 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
{
PaymentServiceWeChatPayDomainObjectExtensions.Configure();
}

public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpWeChatPayResolveOptions>(options =>
{
options.Contributors.AddFirst(new SettingOptionsResolveContributor());
});
}
}
}
}
Loading

0 comments on commit b023ba6

Please sign in to comment.