/// <summary>
        /// Validates if the postback is submitted by the client
        /// </summary>
        /// <param name="secret">Api secret</param>
        /// <returns></returns>
        public static bool IsApiSubmitted(OrderPostBack op, string secret)
        {
            if (op == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(op.order_id) || string.IsNullOrEmpty(op.order_timestamp))
            {
                return(false);
            }

            StringBuilder sb = new StringBuilder();

            using (SHA256 hash = SHA256Managed.Create())
            {
                byte[] result = hash.ComputeHash(Encoding.UTF8.GetBytes(string.Format("{0}{1}{2}", op.order_id, op.order_timestamp, secret)));

                foreach (var item in result)
                {
                    sb.Append(item.ToString("x2"));
                }
            }

            return(op.checksum == sb.ToString());
        }
Exemple #2
0
 public PostbackEventArgs(OrderPostBack order)
 {
     this.Order = order;
 }
Exemple #3
0
 /// <summary>
 /// On new postback
 /// </summary>
 /// <param name="order"></param>
 protected virtual void OnPostback(OrderPostBack order)
 {
     this.Postback?.Invoke(new PostbackEventArgs(order));
 }