示例#1
0
        public async Task <IViewComponentResult> InvokeAsync(int orderId)
        {
            var user = await _userService.GetCurrentUserAsync(HttpContext.RequestAborted);

            if (user == null)
            {
                return(View()); // Default view displays nothing to the end user.
            }
            var order = await _orderService.GetUserOrderAsync(user, orderId, HttpContext.RequestAborted);

            if (order == null)
            {
                return(View()); // Default view displays nothing to the end user.
            }
            if (order.AmountPaidCents >= order.TotalAmountCents)
            {
                return(View()); // Default view displays nothing to the end user.
            }
            if (order.IsCancelled)
            {
                return(View()); // Default view displays nothing to the end user.
            }
            // TODO: Generate a payment uniquie reference number for the order id
            return(View("Input", new BankTransferViewModel
            {
                Order = new OrderViewModel(order),
                PaymentReference = $"{order.Id}{DammAlgorithm.GetCheck(order.Id)}",
                TotalCents = order.AmountOwingCents,
                BankAccountName = _bankOptions.Value.AccountName,
                BankAccountNumber = _bankOptions.Value.AccountNumber,
            }));
        }
示例#2
0
        public async Task <Order> GetOrderByRef(int orderRef, CancellationToken cancellationToken = default)
        {
            // Use Damm algorithum to verify order reference for mistyped value.
            if (!DammAlgorithm.IsValid(orderRef))
            {
                throw new ArgumentOutOfRangeException("Invalid checksum value", nameof(orderRef));
            }

            // Strip the check value from our orderRef to get the orderId
            return(await GetOrderById(orderRef / 10, cancellationToken));
        }
 public override bool IsValid(object value)
 {
     if (value is int intValue)
     {
         return(DammAlgorithm.IsValid(intValue));
     }
     else if (value is string stringValue && int.TryParse(stringValue, out intValue))
     {
         return(DammAlgorithm.IsValid(intValue));
     }
     return(false);
 }
示例#4
0
        public async Task <IActionResult> VerifyOrderRef(string orderReference)
        {
            if (!int.TryParse(orderReference, out var orderRefAsInt))
            {
                return(Json("Order reference must only contain digits"));
            }

            if (!DammAlgorithm.IsValid(orderRefAsInt))
            {
                return(Json("Invalid reference number"));
            }

            var order = await _orderService.GetOrderByRef(orderRefAsInt, HttpContext.RequestAborted);

            if (order == null)
            {
                return(Json("No order found with this id"));
            }

            return(Json(true));
        }