コード例 #1
0
        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);
        }
コード例 #2
0
        public string BuildQueryString()
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();

            queryParams["id"]          = this._smsId.ToString();
            queryParams["msg"]         = this._message;
            queryParams["transaction"] = CryptoUtility.CalculateMD5(this._signPassword + "|" + this._smsId);
            string queryString = HttpQueryUtility.BuildQueryString(queryParams);

            return(queryString);
        }
コード例 #3
0
        public string BuildRequestUrl(MacroRequest request)
        {
            string data = request.ToBase64String();
            string sign = CryptoUtility.CalculateMD5(data + this._signPassword);

            Dictionary <string, string> requestQueryParams = new Dictionary <string, string>();

            requestQueryParams["data"] = data;
            requestQueryParams["sign"] = sign;

            string requestQuery = HttpQueryUtility.BuildQueryString(requestQueryParams);

            return(Client.PAY_URL + "?" + requestQuery);
        }
コード例 #4
0
 public MicroCallbackData(Dictionary <string, string> dataQueryParams)
 {
     this._to        = dataQueryParams["to"];
     this._message   = dataQueryParams["sms"];
     this._from      = dataQueryParams["from"];
     this._operator  = dataQueryParams["operator"];
     this._amount    = int.Parse(dataQueryParams["amount"]);
     this._currency  = dataQueryParams["currency"];
     this._country   = dataQueryParams["country"];
     this._smsId     = int.Parse(dataQueryParams["id"]);
     this._test      = HttpQueryUtility.QueryParameterToBoolean(dataQueryParams["test"]);
     this._keyword   = dataQueryParams["key"];
     this._projectId = int.Parse(dataQueryParams["projectid"]);
     this._version   = dataQueryParams["version"];
 }
コード例 #5
0
        public string ToBase64String()
        {
            Dictionary <string, string> dataQueryParams = new Dictionary <string, string>();

            dataQueryParams["projectid"]        = this._projectId.ToString();
            dataQueryParams["orderid"]          = this._orderId;
            dataQueryParams["accepturl"]        = this._acceptUrl;
            dataQueryParams["cancelurl"]        = this._cancelUrl;
            dataQueryParams["callbackurl"]      = this._callbackUrl;
            dataQueryParams["version"]          = this._version;
            dataQueryParams["lang"]             = this._language;
            dataQueryParams["amount"]           = HttpQueryUtility.ToQueryParameter(this._amount);
            dataQueryParams["currency"]         = this._currency;
            dataQueryParams["payment"]          = this._payment;
            dataQueryParams["country"]          = this._country;
            dataQueryParams["paytext"]          = this._payText;
            dataQueryParams["p_firstname"]      = this._paypalFirstName;
            dataQueryParams["p_lastname"]       = this._paypalLastName;
            dataQueryParams["p_email"]          = this._email;
            dataQueryParams["p_street"]         = this._paypalStreet;
            dataQueryParams["p_city"]           = this._paypalCity;
            dataQueryParams["p_state"]          = this._paypalState;
            dataQueryParams["p_zip"]            = this._paypalZip;
            dataQueryParams["p_countrycode"]    = this._paypalCountryCode;
            dataQueryParams["time_limit"]       = this._timeLimit;
            dataQueryParams["personcode"]       = this._personCode;
            dataQueryParams["test"]             = HttpQueryUtility.ToQueryParameter(this._test);
            dataQueryParams["repeat_request"]   = HttpQueryUtility.ToQueryParameter(this._repeatRequest);
            dataQueryParams["only_payments"]    = HttpQueryUtility.ToQueryParameter(this._allowPayments);
            dataQueryParams["disalow_payments"] = HttpQueryUtility.ToQueryParameter(this._disallowPayments);

            foreach (KeyValuePair <string, string> param in this._additionalParameters)
            {
                if (!dataQueryParams.ContainsKey(param.Key))
                {
                    dataQueryParams[param.Key] = param.Value;
                }
            }

            string dataQuery         = HttpQueryUtility.BuildQueryString(dataQueryParams);
            string dataQueryAsBase64 = CryptoUtility.EncodeBase64UrlSafe(dataQuery);

            return(dataQueryAsBase64);
        }
コード例 #6
0
        public MacroCallbackData(Dictionary <string, string> dataQueryParams)
        {
            EnhancedDictionary <string, string> parameters = new EnhancedDictionary <string, string>(dataQueryParams);

            this._projectId = int.Parse(parameters.Take("projectid"));
            this._orderId   = parameters.Take("orderid");
            this._amount    = int.Parse(parameters.Take("amount"));
            this._currency  = parameters.Take("currency");
            this._payment   = parameters.Take("payment");
            this._payText   = parameters.Take("paytext");
            this._status    = int.Parse(parameters.Take("status"));
            this._test      = HttpQueryUtility.QueryParameterToBoolean(parameters.Take("test"));

            if (parameters.ContainsKey("country"))
            {
                this._country = parameters.Take("country");
            }
            if (parameters.ContainsKey("lang"))
            {
                this._language = parameters.Take("lang");
            }
            if (parameters.ContainsKey("name"))
            {
                this._firstName = parameters.Take("name");
            }
            if (parameters.ContainsKey("surename"))
            {
                this._lastName = parameters.Take("surename");
            }
            if (parameters.ContainsKey("p_email"))
            {
                this._email = parameters.Take("p_email");
            }
            if (parameters.ContainsKey("requestid"))
            {
                this._requestId = int.Parse(parameters.Take("requestid"));
            }
            if (parameters.ContainsKey("payamount"))
            {
                this._payAmount = int.Parse(parameters.Take("payamount"));
            }
            if (parameters.ContainsKey("paycurrency"))
            {
                this._payCurrency = parameters.Take("paycurrency");
            }
            if (parameters.ContainsKey("version"))
            {
                this._version = parameters.Take("version");
            }
            if (parameters.ContainsKey("account"))
            {
                this._account = parameters.Take("account");
            }
            if (parameters.ContainsKey("personcodestatus"))
            {
                this._personCodeStatus = int.Parse(parameters.Take("personcodestatus"));
            }

            if (parameters.Count != 0)
            {
                foreach (KeyValuePair <string, string> param in parameters)
                {
                    this._additionalParameters[param.Key] = param.Value;
                }
            }
        }