Click here to Skip to main content
14,382,805 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have this code which I am attempting to use to communicate an API via RestSharp.


 const string task = "pay";
 const string command_api_token = "9ufks6FjffGplu9HbaN7uq6XXPPVQXBP";
 const string merchant_email_on_voguepay = "mymail@mail.com";

 Random rnd = new Random();
 string refl =  DateTime.Now + rnd.Next(0,9999999).ToString();
 byte[] hash_target = Encoding.Default.GetBytes(command_api_token + task +  merchant_email_on_voguepay + refl);

 string hashD = BitConverter.ToString(new SHA512CryptoServiceProvider().ComputeHash(hash_target)).Replace("-", string.Empty).ToUpper();

 var keyValues = new Dictionary<string, string>
                    {
                         { "task", "pay"},
                         { "merchant", "3333-4444"},
                         { "ref",refl},
                         { "hash",hashD},
                         { "amount", "20"},
                         { "seller", "seller@mail.com"},
                         { "remarks", "payment"},                            

                    };

//serialization using Newtonsoft JSON 
  string json = JsonConvert.SerializeObject(keyValues);

//url encode the json
  var postString = Server.UrlEncode(json);

//calling API with Restsharp
  var client = new RestClient("https://voguepay.com/api/");
  var request = new RestRequest(Method.POST);
  request.AddParameter("json",json);
  IRestResponse response = client.Execute(request);

  Textbox1.Text = response.Content;


I think the arrangement of my code is not really ok, because I keep getting error message on each move I make.

If I try to post it as it is above, I get
"response":"X006","description":"Invalid hash"...

If try to get "url encode the json" involved in the "calling API with Restsharp", I get error message as
"response":"X001","description":"Invalid Merchant Id"...


I think I am not placing things right, can someone look at my work and point out what could be the issue with this code?

What I have tried:

I tried modifying the code to see if the error will go, but it still remain
Posted
Comments
Richard MacCutchan 22-Feb-17 9:13am
   
The problem is not your code, it is the bad values that you are sending, as shown in the error messages. You need to contact the support staff at voguepay for assistance.
Graeme_Grant 22-Feb-17 9:21am
   
Is the API using OAuth 1.0a? It appears so... [edit] check the encoding that you are using. Most expect UTF8.
Kornfeld Eliyahu Peter 22-Feb-17 14:57pm
   
It is clear that the problem with the way you compute the hash...
The problem is that the API documentation is not public, so you are on your own for the most part of it...
Please go back to the documentation and re-read the part talking about the hash... If you can you may share it here... Someone may spot the problem...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100