Exemplo n.º 1
0
        public Result RegisterPaymentSystem(PaymentSystem system)
        {
            Result result = new Result();

            try
            {
                if (!system.IsValid())
                {
                    result.StatusCode = SharedCommonsGlobals.FAILURE_STATUS_CODE;
                    result.StatusDesc = $"{system.StatusDesc}";
                    return(result);
                }

                PaymentSystem old = PaymentSystem.FindAll().Where(i => i.PaymentSystemCode == system.StatusCode).FirstOrDefault();
                system.Id = old != null ? old.Id : system.Id;

                system.Save();
                result.StatusCode = SharedCommonsGlobals.SUCCESS_STATUS_CODE;
                result.StatusDesc = SharedCommonsGlobals.SUCCESS_STATUS_TEXT;
            }
            catch (Exception ex)
            {
                result.StatusCode = SharedCommonsGlobals.FAILURE_STATUS_CODE;
                result.StatusDesc = $"ERROR: {ex.Message}";
            }

            return(result);
        }
Exemplo n.º 2
0
        public override bool IsValid()
        {
            string propertiesThatCanBeNull = $"{nameof(Id)}|{nameof(PaymentNarration)}";
            string nullCheckResult         = SharedCommons.CheckForNulls(this, propertiesThatCanBeNull);

            if (nullCheckResult != SharedCommonsGlobals.SUCCESS_STATUS_TEXT)
            {
                StatusCode = SharedCommonsGlobals.FAILURE_STATUS_CODE;
                StatusDesc = nullCheckResult;
                return(false);
            }

            Payment duplicatePayment = Payment.QueryWithStoredProc("GetPaymentByPaymentSystemCodeAndID", PaymentId, PaymentSystemCode).FirstOrDefault();

            if (duplicatePayment != null)
            {
                StatusCode = SharedCommonsGlobals.SUCCESS_STATUS_CODE;
                StatusDesc = SharedCommonsGlobals.SUCCESS_STATUS_TEXT;
                return(false);
            }

            PaymentSystem system = PaymentSystem.QueryWithStoredProc("GetPaymentSystemByID", PaymentSystemCode).FirstOrDefault();

            if (system == null)
            {
                StatusCode = SharedCommonsGlobals.FAILURE_STATUS_CODE;
                StatusDesc = "INVALID PAYMENT SYSTEM CODE OR PASSWORD";
                return(false);
            }

            string hashedPassword = SharedCommons.GenearetHMACSha256Hash(system.SecretKey, Password);

            if (hashedPassword != system.Password)
            {
                StatusCode = SharedCommonsGlobals.FAILURE_STATUS_CODE;
                StatusDesc = "INVALID PAYMENT SYSTEM CODE OR PASSWORD";
                return(false);
            }

            string dataToSign = PaymentSystemCode + Password + PaymentAmount + PaymentId + PaymentChannel + PayerContact + PayerName;
            string hmacHash   = SharedCommons.GenearetHMACSha256Hash(system.SecretKey, dataToSign);

            if (DigitalSignature != hmacHash)
            {
                StatusCode = SharedCommonsGlobals.FAILURE_STATUS_CODE;
                StatusDesc = "INVALID DIGITAL SIGNATURE";
                return(false);
            }

            return(base.IsValid());
        }