Browse Source

Add a donation sample

pull/69/head
enisn 5 years ago
parent
commit
c261304577
  1. 32
      src/EventHub.Web/Pages/Donate.cshtml
  2. 42
      src/EventHub.Web/Pages/Donate.cshtml.cs
  3. 1
      src/EventHub.Web/Pages/Index.cshtml

32
src/EventHub.Web/Pages/Donate.cshtml

@ -0,0 +1,32 @@
@page
@using EventHub.Localization
@using EventHub.Web.Pages
@using Microsoft.Extensions.Localization
@model DonateModel
@inject IStringLocalizer<EventHubResource> L
<main class="static-page container mt-5">
<form method="post">
<abp-card>
<abp-card-header>
<abp-card-title>
@L["Donation"]
</abp-card-title>
</abp-card-header>
<abp-card-body>
@L["DonationDescription"]
<hr />
<abp-input asp-for="Amount" />
</abp-card-body>
<abp-card-footer>
<abp-button type="submit" size="Block" button-type="Outline_Primary" text="@L["Donate"]" />
</abp-card-footer>
</abp-card>
</form>
</main>

42
src/EventHub.Web/Pages/Donate.cshtml.cs

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Mvc;
using Payment.PaymentRequests;
using Payment.Web.PaymentRequest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Users;
namespace EventHub.Web.Pages
{
public class DonateModel : EventHubPageModel
{
private readonly IPaymentRequestAppService _paymentRequestAppService;
private readonly IPaymentUrlBuilder _paymentUrlBuilder;
public DonateModel(
IPaymentRequestAppService paymentRequestAppService,
IPaymentUrlBuilder paymentUrlBuilder)
{
_paymentRequestAppService = paymentRequestAppService;
_paymentUrlBuilder = paymentUrlBuilder;
}
public decimal Amount { get; set; } = 5;
public async Task<IActionResult> OnPostAsync()
{
var paymentRequest = await _paymentRequestAppService.CreateAsync(new PaymentRequestCreationDto
{
CustomerId = CurrentUser.IsAuthenticated ? CurrentUser.Id.ToString() : Request.HttpContext.Connection.Id,
Price = Amount,
ProductId = "eventhub.donation",
ProductName = $"EventHub Donation | " + CurrentUser.UserName ?? Request.HttpContext.Connection.Id,
});
return Redirect(_paymentUrlBuilder.BuildCheckoutUrl(paymentRequest.Id).AbsoluteUri);
}
}
}

1
src/EventHub.Web/Pages/Index.cshtml

@ -41,6 +41,7 @@
</p>
<div>
<a href="@Url.Page("/Events/New")" class="btn btn-primary">Join Now</a>
<a href="@Url.Page("/Donate")" class="btn btn-primary">Donate</a>
</div>
</div>
</div>

Loading…
Cancel
Save