Exemple #1
0
        public PaymentResponse CreatePaymentRequest(string amount, string mobile, string email, string description, long orderId)
        {
            amount = amount.Replace(",", "");
            var finalAmount = int.Parse(amount);
            var siteUrl     = _configuration.GetSection("payment")["siteUrl"];

            var client  = new RestClient($"https://{Prefix}.zarinpal.com/pg/rest/WebGate/PaymentRequest.json");
            var request = new RestRequest(Method.POST);

            request.AddHeader("Content-Type", "application/json");
            var body = new PaymentRequest
            {
                Mobile      = mobile,
                CallbackURL = $"{siteUrl}/Checkout?handler=CallBack&oId={orderId}",
                Description = description,
                Email       = email,
                Amount      = finalAmount,
                MerchantID  = MerchantId
            };

            request.AddJsonBody(body);
            var response       = client.Execute(request);
            var jsonSerializer = new RestSharp.Serialization.Json.JsonSerializer();

            return(jsonSerializer.Deserialize <PaymentResponse>(response));
        }
Exemple #2
0
        private T Post <T>(string resource, T entity)
        {
            var json    = new RestSharp.Serialization.Json.JsonSerializer();
            var jsonD   = new RestSharp.Serialization.Json.JsonDeserializer();
            var request = new RestRequest();

            request.Method   = Method.POST;
            request.Resource = resource;
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-type", "application/json");
            request.Parameters.Clear();
            request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody);
            request.AddObject(entity);
            var response = Client.Execute(request);

            //var content = response.Content; // raw content as string
            try
            {
                return(jsonD.Deserialize <T>(response));
            }
            catch (Exception)
            {
                return(default(T));
            }
        }
Exemple #3
0
        public void TestSimpleGETJSONObj()
        {
            var deserial = new RestSharp.Serialization.Json.JsonSerializer();
            var client   = new RestClient("http://localhost:3000/");
            var request  = new RestRequest("/posts/{postid}", Method.GET);

            request.AddUrlSegment("postid", 1);
            var content = client.Execute(request);
            var json    = deserial.Deserialize <Dictionary <string, string> >(content);
            var result  = json["author"];

            Assert.AreEqual(result, "typicode");
        }
Exemple #4
0
        public VerificationResponse CreateVerificationRequest(string authority, string amount)
        {
            var client  = new RestClient($"https://{Prefix}.zarinpal.com/pg/rest/WebGate/PaymentVerification.json");
            var request = new RestRequest(Method.POST);

            request.AddHeader("Content-Type", "application/json");

            amount = amount.Replace(",", "");
            var finalAmount = int.Parse(amount);

            request.AddJsonBody(new VerificationRequest
            {
                Amount     = finalAmount,
                MerchantID = MerchantId,
                Authority  = authority
            });
            var response       = client.Execute(request);
            var jsonSerializer = new RestSharp.Serialization.Json.JsonSerializer();

            return(jsonSerializer.Deserialize <VerificationResponse>(response));
        }