Esempio n. 1
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);
 }
Esempio n. 3
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));
        }