Browse Source

Updated PaymentFactory injections

pull/57/head
Galip Tolga Erdem 5 years ago
parent
commit
172fb205c9
  1. 7
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentRequests/PaymentRequestAppService.cs
  2. 2
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/DemoService.cs
  3. 3
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/IPaymentStrategy.cs
  4. 11
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/PaymentServiceFactory.cs
  5. 2
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/PaypalService.cs

7
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentRequests/PaymentRequestAppService.cs

@ -53,8 +53,9 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
public virtual async Task<PaymentRequestStartResultDto> StartAsync(PaymentRequestStartDto input)
{
PaymentRequest paymentRequest = await PaymentRequestRepository.GetAsync(input.PaymentRequestId, includeDetails: true);
PaymentRequest paymentRequest =
await PaymentRequestRepository.GetAsync(input.PaymentRequestId, includeDetails: true);
var paymentService = _paymentServiceFactory.Create(input.PaymentTypeId);
return await paymentService.StartAsync(paymentRequest, input);
}
@ -62,7 +63,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
public virtual async Task<PaymentRequestDto> CompleteAsync(PaymentRequestCompleteInputDto input)
{
var paymentService = _paymentServiceFactory.Create(input.PaymentTypeId);
var paymentRequest = await paymentService.CompleteAsync(PaymentRequestRepository, input.Token);
return ObjectMapper.Map<PaymentRequest, PaymentRequestDto>(paymentRequest);
}

2
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/DemoService.cs

@ -1,9 +1,11 @@
using System;
using System.Threading.Tasks;
using EShopOnAbp.PaymentService.PaymentRequests;
using Volo.Abp.DependencyInjection;
namespace EShopOnAbp.PaymentService.PaymentServices;
[ExposeServices(typeof(IPaymentStrategy), typeof(DemoService))]
public class DemoService : IPaymentStrategy
{
public Task<PaymentRequestStartResultDto> StartAsync(PaymentRequest paymentRequest, PaymentRequestStartDto input)

3
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/IPaymentStrategy.cs

@ -1,9 +1,10 @@
using System.Threading.Tasks;
using EShopOnAbp.PaymentService.PaymentRequests;
using Volo.Abp.DependencyInjection;
namespace EShopOnAbp.PaymentService.PaymentServices;
public interface IPaymentStrategy
public interface IPaymentStrategy : ITransientDependency
{
public Task<PaymentRequestStartResultDto> StartAsync(PaymentRequest paymentRequest, PaymentRequestStartDto input);
public Task<PaymentRequest> CompleteAsync(IPaymentRequestRepository paymentRequestRepository, string token);

11
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/PaymentServiceFactory.cs

@ -1,7 +1,5 @@
using System;
using EShopOnAbp.PaymentService.PaymentRequests;
using Microsoft.Extensions.DependencyInjection;
using PayPalCheckoutSdk.Core;
using Volo.Abp.DependencyInjection;
namespace EShopOnAbp.PaymentService.PaymentServices;
@ -19,17 +17,14 @@ public class PaymentServiceFactory : ITransientDependency
{
if (paymentTypeId == 0)
{
return new DemoService();
return _serviceProvider.GetRequiredService<DemoService>();
}
if (paymentTypeId == 1)
{
var paypalService = _serviceProvider.GetRequiredService<PayPalHttpClient>();
var requestDomainService = _serviceProvider.GetRequiredService<PaymentRequestDomainService>();
return new PaypalService(paypalService, requestDomainService);
return _serviceProvider.GetRequiredService<PaypalService>();
}
return new DemoService();
return _serviceProvider.GetRequiredService<DemoService>();
}
}

2
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServices/PaypalService.cs

@ -6,9 +6,11 @@ using System.Threading.Tasks;
using EShopOnAbp.PaymentService.PaymentRequests;
using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;
using Volo.Abp.DependencyInjection;
namespace EShopOnAbp.PaymentService.PaymentServices;
[ExposeServices(typeof(IPaymentStrategy), typeof(PaypalService))]
public class PaypalService : IPaymentStrategy
{
private readonly PayPalHttpClient _payPalHttpClient;

Loading…
Cancel
Save