private ICallbackData GetCallbackData(NameValueCollection query, PaymentType paymentType)
        {
            if (string.IsNullOrEmpty(query["data"]))
            {
                throw new ArgumentNullException("data");
            }
            string dataAsBase64 = query["data"];

            if (string.IsNullOrEmpty(query["ss2"]))
            {
                throw new ArgumentNullException("ss2");
            }
            string ss2AsBase64 = query["ss2"];

            string publicKeyPEMFileContents = CryptoUtility.DownloadPublicKey();

            byte[] publicKeyRawData = CryptoUtility.GetPublicKeyRawDataFromPEMFile(publicKeyPEMFileContents);;
            byte[] ss2 = CryptoUtility.DecodeBase64UrlSafeAsByteArray(ss2AsBase64);

            bool valid = CryptoUtility.VerifySS2(dataAsBase64, ss2, publicKeyRawData);

            if (!valid)
            {
                throw new InvalidOperationException("Signed data validation failed (SS2).");
            }

            string dataQuery = CryptoUtility.DecodeBase64UrlSafe(dataAsBase64);

            Dictionary <string, string> dataQueryParams = HttpQueryUtility.ParseQueryString(dataQuery);

            ICallbackData callbackData;

            switch (paymentType)
            {
            case PaymentType.Macro:
                MacroCallbackData macroCallbackData = new MacroCallbackData(dataQueryParams);
                callbackData = macroCallbackData;
                break;

            case PaymentType.Micro:
                MicroCallbackData microCallbackData = new MicroCallbackData(dataQueryParams);
                callbackData = microCallbackData;
                break;

            default:
                throw new NotSupportedException("Payment type " + paymentType + " is not supported.");
            }

            if (callbackData.ProjectId != this._projectId)
            {
                throw new Exception("Bad project Id " + callbackData.ProjectId + " should be " + this._projectId + ".");
            }

            return(callbackData);
        }
        private ICallbackData GetCallbackData(NameValueCollection query, PaymentType paymentType)
        {
            if (string.IsNullOrEmpty(query["data"]))
            {
                throw new ArgumentNullException("data");
            }
            string dataAsBase64 = query["data"];

            if (string.IsNullOrEmpty(query["ss2"]))
            {
                throw new ArgumentNullException("ss2");
            }
            string ss2AsBase64 = query["ss2"];

            string publicKeyPEMFileContents = CryptoUtility.DownloadPublicKey();
            byte[] publicKeyRawData = CryptoUtility.GetPublicKeyRawDataFromPEMFile(publicKeyPEMFileContents); ;
            byte[] ss2 = CryptoUtility.DecodeBase64UrlSafeAsByteArray(ss2AsBase64);

            bool valid = CryptoUtility.VerifySS2(dataAsBase64, ss2, publicKeyRawData);
            if (!valid)
            {
                throw new InvalidOperationException("Signed data validation failed (SS2).");
            }

            string dataQuery = CryptoUtility.DecodeBase64UrlSafe(dataAsBase64);

            Dictionary<string, string> dataQueryParams = HttpQueryUtility.ParseQueryString(dataQuery);

            ICallbackData callbackData;
            switch (paymentType)
            {
                case PaymentType.Macro:
                    MacroCallbackData macroCallbackData = new MacroCallbackData(dataQueryParams);
                    callbackData = macroCallbackData;
                    break;
                case PaymentType.Micro:
                    MicroCallbackData microCallbackData = new MicroCallbackData(dataQueryParams);
                    callbackData = microCallbackData;
                    break;
                default:
                    throw new NotSupportedException("Payment type " + paymentType + " is not supported.");
            }

            if (callbackData.ProjectId != this._projectId)
            {
                throw new Exception("Bad project Id " + callbackData.ProjectId + " should be " + this._projectId + ".");
            }

            return callbackData;
        }
        public MacroCallbackData GetMacroCallbackData(NameValueCollection query)
        {
            MacroCallbackData callbackData = (MacroCallbackData)this.GetCallbackData(query, PaymentType.Macro);

            return(callbackData);
        }