Browse Source

updated payment pages

pull/57/head
Galip Tolga Erdem 4 years ago
parent
commit
ca109136a2
  1. 1
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPaymentConsts.cs
  2. 5
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs
  3. 15
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/PaymentCompleted.cshtml.cs
  4. 8
      apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.js
  5. 6
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs

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

@ -3,6 +3,7 @@
public static class EShopOnAbpPaymentConsts
{
public const string Currency = "USD";
public const string PaymentIdCookie = "selected_payment_id"; // Setted in payment-widget.js
public static class DemoAddressTypes
{

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

@ -59,7 +59,7 @@ public class PaymentModel : AbpPageModel
var placedOrder = await _orderAppService.CreateAsync(new OrderCreateDto()
{
PaymentTypeId = model.SelectedPaymentId,
PaymentTypeId = model.SelectedPaymentId,
Address = GetUserAddress(model.SelectedAddressId),
Products = productItems
});
@ -75,9 +75,10 @@ public class PaymentModel : AbpPageModel
var response = await _paymentRequestAppService.StartAsync(new PaymentRequestStartDto
{
PaymentTypeId = model.SelectedPaymentId,
PaymentRequestId = paymentRequest.Id,
ReturnUrl = _publicWebPaymentOptions.PaymentSuccessfulCallbackUrl,
CancelUrl = _publicWebPaymentOptions.PaymentFailureCallbackUrl,
CancelUrl = _publicWebPaymentOptions.PaymentFailureCallbackUrl
});
return Redirect(response.CheckoutLink);

15
apps/public-web/src/EShopOnAbp.PublicWeb/Pages/PaymentCompleted.cshtml.cs

@ -24,12 +24,23 @@ public class PaymentCompletedModel : AbpPageModel
public async Task<IActionResult> OnGetAsync()
{
PaymentRequest = await _paymentRequestAppService.CompleteAsync(Token);
int selectedPaymentId = 0;
if (HttpContext.Request.Cookies.TryGetValue(EShopOnAbpPaymentConsts.PaymentIdCookie,
out var selectedPaymentIdString))
{
selectedPaymentId = string.IsNullOrEmpty(selectedPaymentIdString) ? 0 : int.Parse(selectedPaymentIdString);
}
PaymentRequest = await _paymentRequestAppService.CompleteAsync(
new PaymentRequestCompleteInputDto() {Token = Token, PaymentTypeId = selectedPaymentId});
IsSuccessful = PaymentRequest.State == PaymentRequestState.Completed;
if (IsSuccessful)
{
return RedirectToPage("OrderReceived", new { orderNo = PaymentRequest.OrderNo });
// Remove cookie so that can be set again when default payment type is set
HttpContext.Response.Cookies.Delete(EShopOnAbpPaymentConsts.PaymentIdCookie);
return RedirectToPage("OrderReceived", new {orderNo = PaymentRequest.OrderNo});
}
return Page();

8
apps/public-web/src/EShopOnAbp.PublicWeb/wwwroot/components/payment/payment-widget.js

@ -1,4 +1,8 @@
(function () {
// Write selected payment type to cookie anyways
const paymentTypeId = $(".payment-list").find(".is-selected").attr('data-payment-id');
abp.utils.setCookieValue("selected_payment_id", paymentTypeId);
abp.widgets.PaymentWidget = function ($wrapper) {
var widgetManager = $wrapper.data('abp-widget-manager');
@ -7,7 +11,6 @@
.find('.address-list .card')
.click(function () {
const $this = $(this);
// const addressId = $this.attr('data-address-id');
$this.parents(".address-list").find('.card').removeClass("is-selected");
$this.addClass("is-selected");
});
@ -16,7 +19,8 @@
.find('.payment-list .card')
.click(el => {
const $this = $(el.currentTarget);
// const paymentTypeId = $this.attr('data-payment-id');
const paymentTypeId = $this.attr('data-payment-id');
abp.utils.setCookieValue("selected_payment_id", paymentTypeId);
$this.parents(".payment-list").find('.card').removeClass("is-selected");
$this.addClass("is-selected");
});

6
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs

@ -7,16 +7,16 @@ namespace EShopOnAbp.OrderingService.Orders;
public class PaymentType : Enumeration
{
public static PaymentType Demo = new PaymentType(0, nameof(Demo).ToLowerInvariant());
public static PaymentType Paypal = new PaymentType(1, nameof(Paypal).ToLowerInvariant());
public static PaymentType Demo = new PaymentType(2, nameof(Paypal).ToLowerInvariant());
public PaymentType(int id, string name) : base(id, name)
{
}
public static IEnumerable<PaymentType> List() =>
new[] {Paypal, Demo};
new[] {Demo, Paypal};
public static PaymentType FromName(string name)
{
var state = List()

Loading…
Cancel
Save