Re: Visa direct push and pull request are not testable in the web on wamp saver

Solved! Go to solution
Noahfrancis
Regular Visitor

Visa direct push and pull request are not testable in the web on wamp saver

Can some one  give us aproper sample cod which we can test in the web

(Pleas dont take to long to respond this time)

..................................................................................................................................

<?php

namespace Vdp;

class VisaAPIClient {

public function __construct() {
$this->conf = parse_ini_file ( "configuration.ini", true );
$this->timeout = 80;
$this->connectTimeout = 30;
}

private function loggingHelper( $response, $curl, $testInfo, $requestBody ) {
printf("%s\n",$testInfo);
if(!$response) {
printf ('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
} else {
if (empty($requestBody) == false && $requestBody != '') {
$json = json_decode($requestBody);
$json = json_encode($json, JSON_PRETTY_PRINT);
printf("Request Body : %s\n", $json);
}
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
printf ("Response Status: %s\n",curl_getinfo($curl, CURLINFO_HTTP_CODE));
printf($header);
if (empty($body) == false && $body != '') {
$json = json_decode($body);
$json = json_encode($json, JSON_PRETTY_PRINT);
printf("Response Body : %s\n", $json);
}

}
}

/* Correlation Id ( ex-correlation-id ) is an optional header while making an API call. You can skip passing the header while calling the API's. */
private function getCorrelationId() {
$seed = str_split('abcdefghijklmnopqrstuvwxyz'
.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.'0123456789');
shuffle($seed);
$rand = '';
foreach (array_rand($seed, 12) as $k) $rand .= $seed[$k];
return $rand."_SC";
}

private function getBasicAuthHeader($userId, $password) {
$authString = $userId.":".$password;
$authStringBytes = utf8_encode($authString);
$authloginString = base64_encode($authStringBytes);
return "Authorization:Basic ".$authloginString;
}

public function doMutualAuthCall($method, $path, $testInfo, $requestBodyString, $inputHeaders = array()) {
$curl = curl_init ();
$method = strtolower ( $method );
$certificatePath = $this->conf ['VDP'] ['cert'];
$privateKey = $this->conf ['VDP'] ['key'];
$userId = $this->conf ['VDP'] ['userId'];
$password = $this->conf ['VDP'] ['password'];
$absUrl = $this->conf ['VDP'] ['visaUrl'].$path;
$authHeader = $this->getBasicAuthHeader($userId, $password);

$headers = (array("Accept: application/json", $authHeader, "ex-correlation-id: ".$this->getCorrelationId()));
if (count($inputHeaders) > 0) {
foreach ($inputHeaders as &$header) {
array_push($headers, $header);
}
}
$opts = array ();
if ($method == 'get') {
$opts [CURLOPT_HTTPGET] = 1;
} elseif ($method == 'post') {
array_push($headers, "Content-Type: application/json");
$opts [CURLOPT_POST] = 1;
$opts [CURLOPT_POSTFIELDS] = $requestBodyString;
}

$opts [CURLOPT_URL] = $absUrl;
$opts [CURLOPT_RETURNTRANSFER] = true;
$opts [CURLOPT_CONNECTTIMEOUT] = $this->connectTimeout;
$opts [CURLOPT_TIMEOUT] = $this->timeout;
$opts [CURLOPT_HTTPHEADER] = $headers;
$opts [CURLOPT_HEADER] = 1;
$opts [CURLOPT_SSLCERT] = $certificatePath;
$opts [CURLOPT_SSLKEY] = $privateKey;

curl_setopt_array ( $curl, $opts );
$response = curl_exec ( $curl );
$this->loggingHelper( $response, $curl, $testInfo, $requestBodyString );
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close ( $curl );
return $statusCode;
}

public function doXPayTokenCall($method, $baseUrl, $resource_path, $query_string, $testInfo, $requestBodyString, $inputHeaders = array()) {
$curl = curl_init ();
$method = strtolower ( $method );
$sharedSecret = $this->conf ['VDP'] ['sharedSecret'];
$apiKey = $this->conf ['VDP'] ['apiKey'];
$time = time(); 
$preHashString = $time.$resource_path.$query_string.$requestBodyString; 
$xPayToken = "xv2:".$time.":".hash_hmac('sha256', $preHashString, $sharedSecret);
$headers = (array("Accept: application/json", "X-PAY-TOKEN: ".$xPayToken, "ex-correlation-id: ".$this->getCorrelationId()));
$absUrl = $this->conf ['VDP'] ['visaUrl'].$baseUrl.$resource_path.'?'.$query_string;
if (count($inputHeaders) > 0) {
foreach ($inputHeaders as &$header) {
array_push($headers, $header);
}
}
$opts = array ();
if ($method == 'get') {
$opts [CURLOPT_HTTPGET] = 1;
} elseif ($method == 'post') {
array_push($headers, "Content-Type: application/json");
$opts [CURLOPT_POST] = 1;
$opts [CURLOPT_POSTFIELDS] = $requestBodyString;
} elseif ($method == 'put') {
array_push($headers, "Content-Type: application/json");
$opts [CURLOPT_CUSTOMREQUEST] = "PUT";
$opts [CURLOPT_POSTFIELDS] = $requestBodyString;
}

$opts [CURLOPT_URL] = $absUrl;
$opts [CURLOPT_RETURNTRANSFER] = true;
$opts [CURLOPT_CONNECTTIMEOUT] = $this->connectTimeout;
$opts [CURLOPT_TIMEOUT] = $this->timeout;
$opts [CURLOPT_HTTPHEADER] = $headers;
$opts [CURLOPT_HEADER] = 1;

curl_setopt_array ( $curl, $opts );
$response = curl_exec ( $curl );
$this->loggingHelper( $response, $curl, $testInfo, $requestBodyString );
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close ( $curl );
return $statusCode;
}

}

 

// sending money

$pullFundsRequest = json_encode ([
'acquirerCountryCode'=> '840',
'acquiringBin'=> '408999',
'amount'=> '124.02',
'businessApplicationId'=> 'AA',
'cardAcceptor'=> [
'address'=> [
'country'=> 'USA',
'county'=> 'San Mateo',
'state'=> 'CA',
'zipCode'=> '94404'
],
'idCode'=> 'ABCD1234ABCD123',
'name'=> 'Visa Inc. USA-Foster City',
'terminalId'=> 'ABCD1234'
],
'cavv'=> '0700100038238906000013405823891061668252',
'foreignExchangeFeeTransaction'=> '11.99',
'localTransactionDateTime'=> '2016-09-29T16=>52=>03',
'retrievalReferenceNumber'=> '330000550000',
'senderCardExpiryDate'=> '2015-10',
'senderCurrencyCode'=> 'USD',
'senderPrimaryAccountNumber'=> '4895142232120006',
'surcharge'=> '11.99',
'systemsTraceAuditNumber'=> '451001',
'merchantCategoryCode'=> 6012
]);



$pushFundsRequest = json_encode ([
'systemsTraceAuditNumber'=> 350420,
'retrievalReferenceNumber'=> '401010350420',
'localTransactionDateTime'=> $strDate,
'acquiringBin'=> 409999,
'acquirerCountryCode'=> '101',

'senderAccountNumber'=> '1234567890123456',
'senderCountryCode'=> 'USA',
'transactionCurrencyCode'=> 'USD',
'senderName'=> 'John Smith',
'senderAddress'=> '44 Market St.',
'senderCity'=> 'San Francisco',
'senderStateCode'=> 'CA',

'recipientName'=> 'Adam Smith',
'recipientPrimaryAccountNumber'=> '4957030420210454',
'amount'=> '112.00',

'businessApplicationId'=> 'PP',
'transactionIdentifier'=> 234234322342343,
'merchantCategoryCode'=> 6012,
'sourceOfFundsCode'=> '03',

'cardAcceptor'=> [
'name'=> 'John Smith',
'terminalId'=> '13655392',
'idCode'=> 'VMT200911026070',
'address'=> [
'state'=> 'CA',
'county'=> '081',
'country'=> 'USA',
'zipCode'=> '94105'
]
],
'feeProgramIndicator'=> '123'
]);


//
function testPullFunds() {
$baseUrl = "visadirect/";
$resourcePath = "fundstransfer/v1/pullfundstransactions";
$visaAPIClient->doMutualAuthCall ( 'post', $baseUrl.$resourcePath, 'Push Funds Transaction Test', $this->pullFundsRequest );
//$this->assertEquals($statusCode, "200");

echo $visaAPIClient;

}

function testPushFunds() {
$baseUrl = "visadirect/";
$resourcePath = "fundstransfer/v1/pullfundstransactions";
$visaAPIClient->doMutualAuthCall ( 'post', $baseUrl.$resourcePath, 'Push Funds Transaction Test', $this->pushFundsRequest );
//$this->assertEquals($statusCode, "200");


echo $visaAPIClient;
}


?>

 

 

 

 

.................................................................................................................................

3 REPLIES 3
API_Products
Visa Developer Support Specialist

Re: Visa direct push and pull request are not testable in the web on wamp saver

Hello,

 

Thanks for posting your question. Have you tried our Sandbox testing?  You can also use SOAPUI, a free and open source Web Service, as a functional API testing solution.

 

Sample code for a project is also available on the Visa Developer Center website.

 

Please see the following URLs below for information to help you get started.

 

To Get Started with developing Visa APIs. Please follow the steps in the “Get Started” link below to register and create a Visa Developer application.

 

Getting Started with Visa Developer

https://developer.visa.com/vdpguide#get-started-overview

 

Visa Developer Program > Sandbox Testing

https://developer.visa.com/developer_program

 

Getting Started with Visa Developer > Sample Code For Project

https://developer.visa.com/vdpguide#sample_code_for_project

 

Visa Direct > API Reference > Code Explorer

(Please Note: Code Explorer is the grey box located on the right of the webpage)

https://developer.visa.com/capabilities/visa_direct/reference

 

Testing Two-Way SSL Connectivity Using SOAPUI

https://developer.visa.com/vdpguide#twoway_ssl_mutual_authentication

 

API Explorer

https://developer.visa.com/apiexplorer

 

 

Thank you,

Diana

Visa Developer Team




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.

Noahfrancis
Regular Visitor

Re: Visa direct push and pull request are not testable in the web on wamp saver

Thanks friend am now don with geting the correct certificat and key. I am also able to call the class VisaAPIClient object from the browser.

I am now getting this error  when ever i try to make a transaction from both my local host and shared hosting 
(Push Funds Transaction Test Error: "Protocol {https not supported or disabled in libcurl" - Code: 1)

(https://openwebmarket.com/Backhome/Test/final.php)

 

Can you give me an advise on how to solve this problem.

API_Products
Visa Developer Support Specialist

Re: Visa direct push and pull request are not testable in the web on wamp saver

Hello,

Thanks for posting your inquiry. The issue is related to the curl installation not supporting SSL, which causes the https to not work. Can you please check if your curl installation supports SSL?  If the curl installation does not support SSL, you will need to reinstall with SSL enabled.

 

Thank you,

Diana

Visa Developer Team




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.