Browse Source

Implement paypal flow

pull/48/head
enisn 5 years ago
parent
commit
540740456e
  1. 5
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj
  2. 7
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs
  3. 18
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs
  4. 12
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs
  5. 8
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebPaymentOptions.cs
  6. 43
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs

5
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.0" />
<PackageReference Include="Volo.Abp.AutoMapper" Version="5.0.0" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.0.0" />
</ItemGroup>
@ -26,6 +27,8 @@
<ProjectReference Include="..\..\..\..\shared\EShopOnAbp.Shared.Localization\EShopOnAbp.Shared.Localization.csproj" />
<ProjectReference Include="..\..\..\..\services\catalog\src\EShopOnAbp.CatalogService.HttpApi.Client\EShopOnAbp.CatalogService.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\services\basket\src\EShopOnAbp.BasketService.HttpApi.Client\EShopOnAbp.BasketService.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\services\payment\src\EShopOnAbp.PaymentService.Application.Contracts\EShopOnAbp.PaymentService.Application.Contracts.csproj" />
<!-- <ProjectReference Include="..\..\..\..\services\product\src\MyCompanyName.MyProjectName.ProductService.HttpApi.Client\MyCompanyName.MyProjectName.ProductService.HttpApi.Client.csproj" />-->
</ItemGroup>

7
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs

@ -0,0 +1,7 @@
namespace EShopOnAbp.PublicWeb
{
public static class EShopOnAbpPaymentConsts
{
public const string Currency = "USD";
}
}

18
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs

@ -0,0 +1,18 @@
using AutoMapper;
using EShopOnAbp.BasketService;
using EShopOnAbp.PaymentService;
namespace EShopOnAbp.PublicWeb
{
public class EShopOnAbpPublicAutoMapperProfile : Profile
{
public EShopOnAbpPublicAutoMapperProfile()
{
CreateMap<BasketItemDto, PaymentRequestProductCreationDto>()
.ForMember(p => p.ReferenceId, opts => opts.MapFrom(p => p.ProductId.ToString()))
.ForMember(p => p.Name, opts => opts.MapFrom(p => p.ProductName))
.ForMember(p => p.UnitPrice, opts => opts.MapFrom(p => p.TotalPrice / p.Count))
.ForMember(p => p.Quantity, opts => opts.MapFrom(p => p.Count));
}
}
}

12
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs

@ -22,6 +22,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AspNetCore.SignalR;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.EventBus.RabbitMq;
@ -68,6 +69,12 @@ namespace EShopOnAbp.PublicWeb
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
context.Services.AddAutoMapperObjectMapper<EShopOnAbpPublicWebModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<EShopOnAbpPublicWebModule>(validate: true);
});
Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = true;
@ -83,6 +90,11 @@ namespace EShopOnAbp.PublicWeb
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
});
Configure<EShopOnAbpPublicWebPaymentOptions>(options =>
{
options.PaymentSuccessfulCallbackUrl = configuration["App:SelfUrl"].EnsureEndsWith('/') + "PaymentCompleted";
});
context.Services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";

8
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebPaymentOptions.cs

@ -0,0 +1,8 @@
namespace EShopOnAbp.PublicWeb
{
public class EShopOnAbpPublicWebPaymentOptions
{
public string PaymentSuccessfulCallbackUrl { get; set; }
public string PaymentFailureCallbackUrl { get; set; }
}
}

43
apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs

@ -1,30 +1,59 @@
using System.Threading.Tasks;
using EShopOnAbp.BasketService;
using EShopOnAbp.BasketService;
using EShopOnAbp.PaymentService;
using EShopOnAbp.PaymentService.PaymentRequests;
using EShopOnAbp.PublicWeb.Basket;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Users;
namespace EShopOnAbp.PublicWeb.Pages;
[Authorize]
public class PaymentModel : AbpPageModel
{
private readonly IBasketAppService _basketAppService;
private readonly IPaymentRequestAppService _paymentRequestAppService;
private readonly UserBasketProvider _userBasketProvider;
private readonly EShopOnAbpPublicWebPaymentOptions _publicWebPaymentOptions;
public PaymentModel(IBasketAppService basketAppService)
public PaymentModel(
IPaymentRequestAppService paymentRequestAppService,
UserBasketProvider userBasketProvider,
IOptions<EShopOnAbpPublicWebPaymentOptions> publicWebPaymentOptions)
{
_basketAppService = basketAppService;
_paymentRequestAppService = paymentRequestAppService;
_userBasketProvider = userBasketProvider;
_publicWebPaymentOptions = publicWebPaymentOptions.Value;
}
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
Logger.LogInformation("Payment Proceeded...");
await _basketAppService.PurchaseAsync();
return RedirectToPage("PaymentCompleted");
var basket = await _userBasketProvider.GetBasketAsync();
var paymentRequest = await _paymentRequestAppService.CreateAsync(new PaymentRequestCreationDto
{
BuyerId = CurrentUser.GetId().ToString(),
Currency = EShopOnAbpPaymentConsts.Currency,
Products = ObjectMapper.Map<List<BasketItemDto>, List<PaymentRequestProductCreationDto>>(basket.Items)
});
var response = await _paymentRequestAppService.StartAsync(new PaymentRequestStartDto
{
ReturnUrl = _publicWebPaymentOptions.PaymentSuccessfulCallbackUrl,
PaymentRequestId = paymentRequest.Id,
CancelUrl = _publicWebPaymentOptions.PaymentFailureCallbackUrl,
});
return Redirect(response.CheckoutLink);
}
}
Loading…
Cancel
Save