/// <summary>
        /// CTOR
        /// </summary>
        /// <param name="settings"></param>
        public HalkbankPaymentRequest(HalkbankSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            Storetype   = "3d_pay_hosting";
            Refreshtime = 5;
            Encoding    = "utf-8";
            Trantype    = "Auth";
            Currency    = "807";
            Lang        = "mk";

            StoreKey  = settings.StoreKey;
            Clientid  = settings.Clientid;
            PortalUrl = settings.PortalUrl;
            Rnd       = Helpers.GenerateRandom(6);
        }
Пример #2
0
        /// <summary>
        /// CTOR
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="requestBodyStream"></param>
        /// <returns></returns>
        public HalkbankPaymentResponse(HalkbankSettings settings, string requestBodyContent)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (string.IsNullOrEmpty(requestBodyContent))
            {
                throw new ArgumentNullException(nameof(requestBodyContent));
            }

            var parsed = requestBodyContent?
                         .Split('?')?
                         .LastOrDefault()?
                         .Split('&')?
                         .Select(pair =>
            {
                var segments = pair.Split('=');

                if (segments.Length < 2)
                {
                    return(new KeyValuePair <string, string>(segments.FirstOrDefault(), null));
                }

                return(new KeyValuePair <string, string>(segments.FirstOrDefault(), segments.LastOrDefault()));
            })?
                         .ToDictionary(x => x.Key, x => x.Value)
                         ?? new Dictionary <string, string>();

            parsed.TryGetValue("Response", out var response);
            parsed.TryGetValue("AuthCode", out var authCode);
            parsed.TryGetValue("HostRefNum", out var hostRefNum);
            parsed.TryGetValue("ProcReturnCode", out var procReturnCode);
            parsed.TryGetValue("TransId", out var transId);
            parsed.TryGetValue("ErrMsg", out var errMsg);
            parsed.TryGetValue("ClientIp", out var clientIp);
            parsed.TryGetValue("ReturnOid", out var returnOid);
            parsed.TryGetValue("MaskedPan", out var maskedPan);
            parsed.TryGetValue("PaymentMethod", out var paymentMethod);
            parsed.TryGetValue("rnd", out var rnd);
            parsed.TryGetValue("HASHPARAMS", out var hashparams);
            parsed.TryGetValue("HASHPARAMSVAL", out var hashparamsva);
            parsed.TryGetValue("HASH", out var hash);
            parsed.TryGetValue("mdStatus", out var mdStatus);
            parsed.TryGetValue("txstatus", out var txstatus);
            parsed.TryGetValue("eci", out var eci);
            parsed.TryGetValue("cavv", out var cavv);
            parsed.TryGetValue("mdErrorMsg", out var mdErrorMsg);
            parsed.TryGetValue("xid", out var xid);

            Response       = response;
            AuthCode       = authCode;
            HostRefNum     = hostRefNum;
            ProcReturnCode = procReturnCode;
            TransId        = transId;
            ErrMsg         = errMsg;
            ClientIp       = clientIp;
            ReturnOid      = returnOid;
            MaskedPan      = maskedPan;
            PaymentMethod  = paymentMethod;
            Rnd            = rnd;
            Hashparams     = hashparams;
            Hashparamsva   = hashparamsva;
            Hash           = hash;
            MdStatus       = mdStatus;
            Txstatus       = txstatus;
            Eci            = eci;
            Cavv           = cavv;
            MdErrorMsg     = mdErrorMsg;
            Xid            = xid;

            var concat  = $"{Hashparamsva}{settings.StoreKey}";
            var encoded = Helpers.Encode(concat, Helpers.HalkbankEncoding);
            var hashed  = Helpers.ToSha1(encoded);
            var base64  = Helpers.ToBase64String(hashed);

            Success = Response == "Approved" && base64 == Hash;
        }