nshenry03 Posted May 4, 2009 Share Posted May 4, 2009 I am trying to set up a payment system for a client and the developers manual for the payment gateway says this: "All sensitive merchant data, including transaction amount and your Virtual Merchant credentials, should be placed in server side code, rather than placing hidden value fields on an HTML form. This will reduce the ability for malicious users to edit and use this data for their own fraudulent purposes." In their examples, it shows to set up a form and send info with the POST method, so I looked and found that curl could send info with the POST method as well, so this is what I did: $Curl_Session = curl_init('https://www.myvirtualmerchant.com/VirtualMerchant/process.do'); curl_setopt ($Curl_Session, CURLOPT_POST, 1); curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "ssl_amount=$amount&ssl_CAD_account=$account&ssl_CAD_birthday=$birthday&ssl_merchant_id=$MERCHANT_ID&ssl_pin=$PIN"); curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1); curl_exec ($Curl_Session); curl_close ($Curl_Session); now nothing happens, and I'm wondering what I did wrong of if there is something else I can do. Thanks, Link to comment https://forums.phpfreaks.com/topic/156854-payment-system-curl-and-post/ Share on other sites More sharing options...
redarrow Posted May 4, 2009 Share Posted May 4, 2009 first see if the system is set up properly. step 1. found this for u check it. <?php // This program checks for installed cURL versions - rtw819 - 12/9/2007 // Written in support of the Virtual Merchant Payment Module for Zen Cart // Use at your own risk. May not find all versions of curl installed on a system. // If you suspect you have curl in a different location, modify/add to the file list below. // // Version 1.2 - 12/13/2007 ?> <html> <body> <?php print "Checking for a PHP-based cURL installation... (curl_version.php version 1.2 - 12/13/2007 rtw819)\n<br />\n"; if (function_exists('curl_init')) { print "PHP based cURL was found!\n<br />\n"; $response_raw = curl_version(); // $CURL_VERSION="curl ".$response_raw['version']." (".$response_raw['host'].")" .$response_raw['ssl_version']." zlib/".$response_raw['libz_version']; $curl_vernum = $response_raw['version']; $curl_hostos = $response_raw['host']; $curl_sslver = $response_raw['ssl_version']; $curl_zlibver = $response_raw['libz_version']; if ( ! $curl_vernum == "" ) { $CURL_VERSION="curl ".$curl_vernum; if ( ! $curl_hostos == "" ) { $CURL_VERSION.= " (".$curl_hostos.")"; } if ( ! $curl_sslver == "" ) { $CURL_VERSION.= $curl_sslver; } if ( ! $curl_zlibver == "" ) { $CURL_VERSION.= " zlib/".$curl_zlibver; } } print "Version: " . $CURL_VERSION . "\n<br />\n"; if (!is_array($response_raw) ) { print curl_version()."\n<br />\n"; } } else { print "Sorry, PHP-based cURL is NOT installed.\n"; } $found_flag=0; $response_raw; $curlerrno; print "<br /><br />\nChecking for popular locations where a binary executable cURL program may be installed...\n<br />\n"; print "curl programs found (if any):<br />"; $file="/bin/curl"; whichfile($file); $file="/usr/bin/curl"; whichfile($file); $file="/usr/local/bin/curl"; whichfile($file); $file="/usr/local/sbin/curl"; whichfile($file); $file="/usr/sbin/curl"; whichfile($file); $file="/opt/curl/bin/curl"; whichfile($file); print "<br />------------\n<br />All done!\n"; function whichfile($file) { if (file_exists($file)) { print "FOUND: <b>". $file."</b> "; if (is_executable($file)) { print "Binary _IS_ executable! (Good) <br />"; $found_flag++; exec($file." -V", $response_raw, $curlerrno); $output_lines="\n"; foreach ($response_raw as $line_num => $line) { $output_lines.=$line."\n"; } print "Version: $output_lines\n"; } else { print "Binary is NOT executable! (Bad) "; } print"\n<br />"; } } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/156854-payment-system-curl-and-post/#findComment-826265 Share on other sites More sharing options...
redarrow Posted May 4, 2009 Share Posted May 4, 2009 i am sure this will work? <?php or ($i = 0; $i <= sizeof($post['key'])-1; $i++) {$string .= $post['key'][$i].'='.$post['value'][$i].'&';}//build post vars $string = substr($string, 0, -1); // not needed $ch = curl_init();//init curl options curl_setopt ($ch, CURLOPT_URL, $this->url); curl_setopt ($ch, CURLOPT_FRESH_CONNECT, 1); //no cache connection curl_setopt ($ch, CURLOPT_POST, 1); //enable the post of vars curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_TIMEOUT, 8 ); // seconds to wait for timeout curl_setopt ($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $string );//posted vars in fromat key1=value1&key2=value2& curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //enable return response $content = parse_response(curl_exec($ch)); ?> Link to comment https://forums.phpfreaks.com/topic/156854-payment-system-curl-and-post/#findComment-826282 Share on other sites More sharing options...
nshenry03 Posted June 27, 2009 Author Share Posted June 27, 2009 redarrow, this is what was returned from my client's server with the test script: Checking for a PHP-based cURL installation... (curl_version.php version 1.2 - 12/13/2007 rtw819) PHP based cURL was found! Version: curl l (l)l zlib/l libcurl/7.11.2 OpenSSL/0.9.7d ipv6 zlib/1.1.4 Checking for popular locations where a binary executable cURL program may be installed... curl programs found (if any): FOUND: /opt/curl/bin/curl Binary _IS_ executable! (Good) Version: curl 7.11.2 (i386-pc-solaris2.10) libcurl/7.11.2 OpenSSL/0.9.7d ipv6 zlib/1.1.4 Protocols: ftp gopher telnet dict ldap http file https ftps Features: IPv6 SSL libz NTLM Largefile ------------ All done! I think things are correct with the following code: $ch = curl_init("https://www.myvirtualmerchant.com/VirtualMerchant/process.do"); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "ssl_amount=$amount&ssl_CAD_account=$account&ssl_CAD_birthday=$birthday&ssl_merchant_id=$MERCHANT_ID&ssl_pin=$PIN&ssl_user_id=$USER_ID&ssl_test_mode=true&ssl_show_form=true&ssl_transaction_type=CCSALE"); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_exec($ch); curl_close ($ch); It works 100% on my server, sending to another test php script that reads the post variables, but when I move it to my clients server it seems to work 1/4 of the time on my clients server though... When it does not work, it just stalls forever... any advice? Link to comment https://forums.phpfreaks.com/topic/156854-payment-system-curl-and-post/#findComment-864649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.