Re: Test Question

gaferrero
Regular Visitor

Test Question

Hi All,

 

After downloading the vdp-c-sharp project and config the entired project with my keys, I executed the code but I received the Bad Request on the response.

 

I've attached the both files (unit test and the VISAAPICLient.cs).  I did a few modifications in order to tried differents approaches.

 

Does anyone can help or give me some tips in order to continue with the api test?

 

Thanks in advance.Sorry for my english.

 

Gustavo

3 REPLIES 3
gaferrero
Regular Visitor

Re: Test Question

MVISATest.cs

 

public MVisaTest()
        {
            visaAPIClient = new VisaAPIClient();
            string strDate = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ss");
            cashInPushPayments =
                 "{"
                 + "\"acquirerCountryCode\": \"643\","
				 + "\"acquiringBin\": \"400171\","
				 + "\"amount\": \"124.05\","
                 + "\"businessApplicationId\": \"CI\","
                 + "\"cardAcceptor\": {"
                                         + "\"address\": {"
                                                             + "\"city\": \"Bangalore\","
															 + "\"country\": \"IN\""
													  + "},"
                                         + "\"idCode\": \"ID-Code123\","
										 + "\"name\": \"Test Merchant\""
									   + "},"
                 + "\"localTransactionDateTime\": \""+ strDate + "\","
				 + "\"merchantCategoryCode\": \"6012\","
				 + "\"recipientPrimaryAccountNumber\": \"4123640062698797\","
				 + "\"retrievalReferenceNumber\": \"430000367618\","
				 + "\"senderAccountNumber\": \"4541237895236\","
				 + "\"senderName\": \"Mohammed Qasim\","
				 + "\"senderReference\": \"1234\","
                 + "\"systemsTraceAuditNumber\": \"313042\","
                 + "\"transactionCurrencyCode\": \"840\","
				 //+ "\"transactionIdentifier\": \"381228649430015\""
                 + "}";
        }

        [TestMethod]
        public void TestMVisaTransactions()
        {
            string baseUri = "visadirect/";
            string resourcePath = "mvisa/v1/cashinpushpayments";
            string status = visaAPIClient.DoMutualAuthCall(baseUri + resourcePath, "POST", "M Visa Transaction Test", cashInPushPayments);
            Assert.AreEqual(status, "OK");
        }

VisaAPIClient.cs

 

public string DoMutualAuthCall(string path, string method, string testInfo, string requestBodyString, Dictionary<string, string> headers = null)
		{
			string requestURL = ConfigurationManager.AppSettings["visaUrl"] + path;
			string userId = ConfigurationManager.AppSettings["userId"];
			string password = ConfigurationManager.AppSettings["password"];
			string certificatePath = ConfigurationManager.AppSettings["cert"];
			string certificatePassword = ConfigurationManager.AppSettings["certPassword"];
			string statusCode = "";
			LogRequest(requestURL, requestBodyString);

			// Create the POST request object
			ServicePointManager.Expect100Continue = true;
			//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
			ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

			// Create the POST request object 
			HttpWebRequest request = WebRequest.Create(requestURL) as HttpWebRequest;
			request.Method = method;
			if (method.Equals("POST") || method.Equals("PUT"))
			{
				//request.ContentType = "application/json";
				request.Accept = "application/json,application/octet-stream";

				// Load the body for the post request
				//var requestStringBytes = Encoding.UTF8.GetBytes(requestBodyString);
				//request.GetRequestStream().Write(requestStringBytes, 0, requestStringBytes.Length);

				using (var streamWriter = new StreamWriter(request.GetRequestStream()))
				{					
					streamWriter.Write(requestBodyString);
					streamWriter.Flush();
					streamWriter.Close();
				}
			}

			if (headers != null)
			{
				foreach (KeyValuePair<string, string> header in headers)
				{
					request.Headers[header.Key] = header.Value;
				}
			}
			
			// Add headers
			request.Headers["Authorization"] = GetBasicAuthHeader(userId, password);
			//request.Headers["ex-correlation-id"] = GetCorrelationId();
			

			// Add certificate
			var certificate = new X509Certificate2(certificatePath, certificatePassword);
			request.ClientCertificates.Add(certificate);
			request.PreAuthenticate = true;

			try
			{
				// Make the call
				using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
				{
					LogResponse(testInfo, response);
					statusCode = response.StatusCode.ToString();
				}
			}
			catch (WebException e)
			{
				if (e.Response is HttpWebResponse)
				{
					HttpWebResponse response = (HttpWebResponse)e.Response;
					LogResponse(testInfo, response);
					statusCode = response.StatusCode.ToString();
				}
			}
			return statusCode;
		}
API_Products
Visa Developer Support Specialist

Re: Test Question

Hi @gaferrero,                             

 

Thank you for your inquiry and interest in the Visa Direct mVisa API. Before moving forward with the next step, it is important to review the Visa Direct documentation via this link. https://developer.visa.com/capabilities/visa_direct/docs

 

In particular, please see the top few paragraphs that are shaded in yellow that discuss the requirements to use Visa Direct.

 

After having read the documentation, if you meet those requirements, then please click through the link in those paragraphs to the Visa Direct Program Implementation Questionnaire, fill it out, and submit to the email address listed on that form.

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Test Question

Hi @russellpitt,                             

 

If you are interested in using Visa Direct and/or receiving a Visa Direct error while testing code, please review the Visa Direct documentation using this link.  https://developer.visa.com/capabilities/visa_direct/docs

 

In particular, see the top few paragraphs that are shaded in yellow that discuss the requirements to use Visa Direct.

 

After having read the documentation, if you meet those requirements, then please click through the link in those paragraphs to the Visa Direct Program Implementation Questionnaire, fill it out, and submit to the email address listed on that form.

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.