From ecdbcb5e88ae4954ba1028b4df33747393b1947f Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 20 Oct 2021 15:08:25 +0300 Subject: [PATCH] Improvements on Donate scenario --- .../Localization/Payment/en.json | 9 +++- .../Pages/Payment/PostCheckout.cshtml | 46 ++++++++-------- .../Pages/Payment/PostCheckout.cshtml.cs | 10 +++- .../Pages/Payment/PreCheckout.cshtml | 54 ++++++++++--------- .../Pages/Payment/PreCheckout.cshtml.cs | 16 ++++-- .../src/Payment.Web/PaymentWebModule.cs | 3 +- 6 files changed, 85 insertions(+), 53 deletions(-) diff --git a/modules/payment/src/Payment.Domain.Shared/Localization/Payment/en.json b/modules/payment/src/Payment.Domain.Shared/Localization/Payment/en.json index 5cf8ce3..321f78d 100644 --- a/modules/payment/src/Payment.Domain.Shared/Localization/Payment/en.json +++ b/modules/payment/src/Payment.Domain.Shared/Localization/Payment/en.json @@ -1,9 +1,16 @@ + { "culture": "en", "texts": { "MyAccount": "My account", "SamplePageMessage": "A sample page for the Payment module", "YourPaymentCompletedSuccessfully": "Your payment has been completed successfully!", - "YourPaymentFailed": "Your payment has been failed unfortunetely!" + "YourPaymentFailed": "Your payment has been failed unfortunetely!", + "PaymentRequestIsNotWaiting": "The state isn't 'Waiting', so you can't pay this Payment Request at this time.", + "ProductName": "Product Name", + "Price": "Price", + "Status": "State", + "ProductInformation": "Product Information", + "CompletePayment": "Complete the Payment" } } \ No newline at end of file diff --git a/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml b/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml index 213df80..705a8d3 100644 --- a/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml +++ b/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml @@ -7,29 +7,31 @@ PageLayout.Content.Title = L["PaymentResult"] + L["Enum:PaymentRequestState:" + Model.PaymentRequest.State]; } - - -

@L["PaymentResult"]

-
+
+ + +

@L["PaymentResult"]

+
- + - @if (Model.PaymentRequest.State == PaymentRequestState.Completed) - { - -

- @L["YourPaymentCompletedSuccessfully"] -
- } - else - { - -

- @L["YourPaymentFailed"] -
+ @if (Model.PaymentRequest.State == PaymentRequestState.Completed) + { + + + @L["YourPaymentCompletedSuccessfully"] + + } + else + { + +

+ @L["YourPaymentFailed"] +
- - } + + } -
-
\ No newline at end of file + + +
\ No newline at end of file diff --git a/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml.cs b/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml.cs index b88eb4b..e198f8c 100644 --- a/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml.cs +++ b/modules/payment/src/Payment.Web/Pages/Payment/PostCheckout.cshtml.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Payment.PaymentRequests; +using Payment.Web.PaymentRequest; using System; using System.Threading.Tasks; @@ -13,15 +14,20 @@ namespace Payment.Web.Pages.Payment public PaymentRequestDto PaymentRequest { get; protected set; } + public string GoBackLink { get; set; } + private readonly IPaymentRequestAppService _paymentRequestAppService; private readonly PaymentWebOptions _paymentWebOptions; + private readonly IPaymentUrlBuilder _paymentUrlBuilder; public PostCheckoutPageModel( IPaymentRequestAppService appService, - IOptions paymentWebOptions) + IOptions paymentWebOptions, + IPaymentUrlBuilder paymentUrlBuilder) { _paymentRequestAppService = appService; _paymentWebOptions = paymentWebOptions.Value; + _paymentUrlBuilder = paymentUrlBuilder; } public async Task OnGetAsync() @@ -33,6 +39,8 @@ namespace Payment.Web.Pages.Payment PaymentRequest = await _paymentRequestAppService.CompleteAsync(Token); + GoBackLink = _paymentUrlBuilder.BuildReturnUrl(PaymentRequest.Id).AbsoluteUri; + if (PaymentRequest.State == PaymentRequestState.Completed && !_paymentWebOptions.PaymentSuccessfulCallbackUrl.IsNullOrWhiteSpace()) { diff --git a/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml b/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml index 38b27e6..ebb7d2d 100644 --- a/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml +++ b/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml @@ -1,32 +1,38 @@ @page @using Payment.Web.Pages.Payment +@using Payment.PaymentRequests @inherits Payment.Web.Pages.PaymentPageBase @model Payment.Web.Pages.Payment.PreCheckoutPageModel @section scripts { - - - + + + } -

Checkout

- - - -

Product Information

-
- -
    -
  • Product name: @Model.PaymentRequest.ProductName
  • -
  • Amount: @Model.PaymentRequest.Price
  • -
-
-
- - - -
- Complete the payment -
-
-
\ No newline at end of file +
+ + +

@L["ProductInformation"]

+
+ +
    +
  • @L["ProductName"]: @Model.PaymentRequest.ProductName
  • +
  • @L["Price"]: @Model.PaymentRequest.Price @Model.PaymentRequest.Currency
  • +
  • @L["State"]: @Model.PaymentRequest.State
  • +
+
+ +
+ @if (Model.PaymentRequest.State != PaymentRequestState.Waiting) + { + @L["PaymentRequestIsNotWaiting"] + } + else + { + @L["CompletePayment"] + } +
+
+
+
\ No newline at end of file diff --git a/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml.cs b/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml.cs index 57aeeed..39c03d8 100644 --- a/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml.cs +++ b/modules/payment/src/Payment.Web/Pages/Payment/PreCheckout.cshtml.cs @@ -3,6 +3,7 @@ using Payment.PaymentRequests; using Payment.Web.PaymentRequest; using System; using System.Threading.Tasks; +using Volo.Abp; namespace Payment.Web.Pages.Payment { @@ -21,19 +22,28 @@ namespace Payment.Web.Pages.Payment IPaymentUrlBuilder paymentUrlBuilder) { _paymentRequestAppService = paymentRequestAppService; - this._paymentUrlBuilder = paymentUrlBuilder; + _paymentUrlBuilder = paymentUrlBuilder; } - public async Task OnGetAsync() + public async Task OnGetAsync() { PaymentRequest = await _paymentRequestAppService.GetAsync(PaymentRequestId); + + return Page(); } public async Task OnPostAsync() { + PaymentRequest = await _paymentRequestAppService.GetAsync(PaymentRequestId); + + if (PaymentRequest.CreationTime.AddMinutes(15) >= Clock.Now) + { + throw new UserFriendlyException("Payment requiest is timed out."); + } + var result = await _paymentRequestAppService.StartPaymentAsync(new StartPaymentDto { - PaymentRequestId = PaymentRequestId, + PaymentRequestId = PaymentRequest.Id, ReturnUrl = _paymentUrlBuilder.BuildReturnUrl(PaymentRequestId).AbsoluteUri, CancelUrl = _paymentUrlBuilder.BuildCheckoutUrl(PaymentRequestId).AbsoluteUri }); diff --git a/modules/payment/src/Payment.Web/PaymentWebModule.cs b/modules/payment/src/Payment.Web/PaymentWebModule.cs index 2e89082..48cf24d 100644 --- a/modules/payment/src/Payment.Web/PaymentWebModule.cs +++ b/modules/payment/src/Payment.Web/PaymentWebModule.cs @@ -2,14 +2,13 @@ using Microsoft.Extensions.DependencyInjection; using Payment.Localization; using Payment.Web.Menus; +using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation; using Volo.Abp.VirtualFileSystem; -using Payment.Permissions; -using Volo.Abp.AspNetCore.Mvc; namespace Payment.Web {