2

I have successfully integrated mastercard payment gateway (MIGS) from Asp.net with C# code. But I am unable to query each transaction. I need to query the server for individual transaction. But I am not able to get proper response a mentioned in VPC client guide.

my code:

            string vpcURL = "https://migs.mastercard.com.au/ma/login.s?mappedUrl=/network";

        try
        {
            DataSet ds = new DataSet();
            byte[] response;
            var data = new NameValueCollection();
            data["vpc_Version"] = "1";
            data["vpc_AccessCode"] = "182F61A1";
            data["vpc_Command"] = "QueryDR";
            data["vpc_Merchant"] = "TEST001110246097";
            data["vpc_MerchTxnRef"] = "1W7sVZAMEuQ4=";
            data["vpc_User"] = "XXXXXXXX";
            data["vpc_Password"] = "XXXXXXXX";
            var redirectUrl = vpcURL + "?" + postData;


            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            response= webClient.UploadValues(vpcURL, "POST", data);

            string strresponse = Encoding.UTF8.GetString(response);
            StringReader reader = new StringReader(strresponse);

            ds.ReadXml(reader);

        }
        catch (Exception ex)
        { 

        }

In the response I am getting a blank html form, and not the expected fields as mentioned in the server.

I need one complete code for querying the server.

thanks

santubangalore
  • 796
  • 1
  • 12
  • 25

1 Answers1

2

You've probably sorted this out a long time ago but I've recently written a working code for this and maybe it will come useful to others

var args = new SortedDictionary<string, string>()
            {
                {"vpc_Version", "1"},
                {"vpc_Command", "queryDR"},
                {"vpc_MerchTxnRef", MerchTxnRef},
                {"vpc_AccessCode", "XXXXXX"},
                {"vpc_Merchant", "XXXXXX"},
                {"vpc_User", "XXXXX"},
                {"vpc_Password", "XXXXX"}
            };
            var client = new HttpClient();
            var result = await client.PostAsync("https://migs.mastercard.com.au/vpcdps", new FormUrlEncodedContent(args));
            var reply = await result.Content.ReadAsStringAsync();

I use SortedDictionary because arguments need to be supplied in alphabetical order. You can sort them manually if you prefer. I'm not sure if you have the proper URL, maybe it was different 2 years ago, refer to current MIGS integration guide. vpc_User and vpc_Password fields need to be supplied with a user created with proper "Advanced Features" flag set.