Browse Source

Merge pull request #51 from abpframework/enisn/payment-bypassing-flag

Add Payment Provider bypassing
pull/52/head
Galip Tolga Erdem 5 years ago
committed by GitHub
parent
commit
c94e6c39fa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentServiceConsts.cs
  2. 12
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentRequests/PaymentRequestAppService.cs
  3. 34
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentRequests/PaymentRequestByPassAppService.cs
  4. 13
      services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServiceApplicationModule.cs
  5. 4
      services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs

7
services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentServiceConsts.cs

@ -0,0 +1,7 @@
namespace EShopOnAbp.PaymentService
{
public static class PaymentServiceConsts
{
public static bool ByPassPaymentProvider { get; set; }
}
}

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

@ -7,9 +7,11 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace EShopOnAbp.PaymentService.PaymentRequests namespace EShopOnAbp.PaymentService.PaymentRequests
{ {
[ExposeServices(typeof(PaymentRequestAppService))]
public class PaymentRequestAppService : PaymentServiceAppService, IPaymentRequestAppService public class PaymentRequestAppService : PaymentServiceAppService, IPaymentRequestAppService
{ {
protected IPaymentRequestRepository PaymentRequestRepository { get; } protected IPaymentRequestRepository PaymentRequestRepository { get; }
@ -23,7 +25,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
PayPalHttpClient = payPalHttpClient; PayPalHttpClient = payPalHttpClient;
} }
public async Task<PaymentRequestDto> CreateAsync(PaymentRequestCreationDto input) public virtual async Task<PaymentRequestDto> CreateAsync(PaymentRequestCreationDto input)
{ {
var paymentRequest = new PaymentRequest(GuidGenerator.Create(), input.Currency, input.BuyerId); var paymentRequest = new PaymentRequest(GuidGenerator.Create(), input.Currency, input.BuyerId);
@ -45,7 +47,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
return ObjectMapper.Map<PaymentRequest, PaymentRequestDto>(paymentRequest); return ObjectMapper.Map<PaymentRequest, PaymentRequestDto>(paymentRequest);
} }
public async Task<PaymentRequestStartResultDto> StartAsync(PaymentRequestStartDto input) public virtual async Task<PaymentRequestStartResultDto> StartAsync(PaymentRequestStartDto input)
{ {
var paymentRequest = await PaymentRequestRepository.GetAsync(input.PaymentRequestId, includeDetails: true); var paymentRequest = await PaymentRequestRepository.GetAsync(input.PaymentRequestId, includeDetails: true);
@ -103,7 +105,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
}; };
} }
public async Task<PaymentRequestDto> CompleteAsync(string token) public virtual async Task<PaymentRequestDto> CompleteAsync(string token)
{ {
var request = new OrdersCaptureRequest(token); var request = new OrdersCaptureRequest(token);
request.RequestBody(new OrderActionRequest()); request.RequestBody(new OrderActionRequest());
@ -115,7 +117,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
return ObjectMapper.Map<PaymentRequest, PaymentRequestDto>(paymentRequest); return ObjectMapper.Map<PaymentRequest, PaymentRequestDto>(paymentRequest);
} }
public async Task<bool> HandleWebhookAsync(string payload) public virtual async Task<bool> HandleWebhookAsync(string payload)
{ {
var jObject = JObject.Parse(payload); var jObject = JObject.Parse(payload);
@ -134,7 +136,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests
return true; return true;
} }
private async Task<PaymentRequest> UpdatePaymentRequestStateAsync(Order order) protected async Task<PaymentRequest> UpdatePaymentRequestStateAsync(Order order)
{ {
var paymentRequestId = Guid.Parse(order.PurchaseUnits.First().ReferenceId); var paymentRequestId = Guid.Parse(order.PurchaseUnits.First().ReferenceId);

34
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentRequests/PaymentRequestByPassAppService.cs

@ -0,0 +1,34 @@
using PayPalCheckoutSdk.Core;
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace EShopOnAbp.PaymentService.PaymentRequests
{
[ExposeServices(typeof(PaymentRequestByPassAppService))]
public class PaymentRequestByPassAppService : PaymentRequestAppService
{
public PaymentRequestByPassAppService(IPaymentRequestRepository paymentRequestRepository, PayPalHttpClient payPalHttpClient) : base(paymentRequestRepository, payPalHttpClient)
{
}
public override Task<PaymentRequestStartResultDto> StartAsync(PaymentRequestStartDto input)
{
return Task.FromResult(new PaymentRequestStartResultDto
{
CheckoutLink = input.ReturnUrl + "?token=" + input.PaymentRequestId
});
}
public override async Task<PaymentRequestDto> CompleteAsync(string token)
{
var paymentRequest = await PaymentRequestRepository.GetAsync(Guid.Parse(token));
paymentRequest.SetAsCompleted();
await PaymentRequestRepository.UpdateAsync(paymentRequest);
return ObjectMapper.Map<PaymentRequest, PaymentRequestDto>(paymentRequest);
}
}
}

13
services/payment/src/EShopOnAbp.PaymentService.Application/PaymentServiceApplicationModule.cs

@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
using EShopOnAbp.PaymentService.PayPal; using EShopOnAbp.PaymentService.PayPal;
using PayPalCheckoutSdk.Core; using PayPalCheckoutSdk.Core;
using System; using System;
using EShopOnAbp.PaymentService.PaymentRequests;
namespace EShopOnAbp.PaymentService namespace EShopOnAbp.PaymentService
{ {
@ -38,6 +39,18 @@ namespace EShopOnAbp.PaymentService
return new PayPalHttpClient(new LiveEnvironment(options.ClientId, options.Secret)); return new PayPalHttpClient(new LiveEnvironment(options.ClientId, options.Secret));
}); });
context.Services.AddTransient<IPaymentRequestAppService>(provider =>
{
if (PaymentServiceConsts.ByPassPaymentProvider)
{
return provider.GetRequiredService<PaymentRequestByPassAppService>();
}
else
{
return provider.GetRequiredService<PaymentRequestAppService>();
}
});
} }
} }
} }

4
services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs

@ -31,6 +31,10 @@ namespace EShopOnAbp.PaymentService
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
/// Enable bypassing payment provider via uncommenting code line below.
/// If bypassing is enabled, all payments will be completed immediately.
// PaymentServiceConsts.ByPassPaymentProvider = true;
JwtBearerConfigurationHelper.Configure(context, "PaymentService"); JwtBearerConfigurationHelper.Configure(context, "PaymentService");
// SwaggerConfigurationHelper.Configure(context, "Payment Service API"); // SwaggerConfigurationHelper.Configure(context, "Payment Service API");

Loading…
Cancel
Save