Pogledajte određenu poruku
Staro 13. 11. 2005.   #3
Ilija Studen
Direktor Kombinata
Invented the damn thing
 
Avatar Ilija Studen
 
Datum učlanjenja: 07.06.2005
Poruke: 2.669
Hvala: 44
119 "Hvala" u 64 poruka
Ilija Studen će postati "faca" uskoroIlija Studen će postati "faca" uskoro
Default

Samu funkciju sam negde "pokupio" i malo prilagodio. Klasa i test primer odakle je ovo izvučeno je prikačeno na poruku. Probao sam da vidim nešto gotovo pošto nisam imao vremena sam da se cimam (par sati proučavanja dokumentacije i eksperimentisanja), ali mi se čini da će na kraju ipak biti tako... Korisnik se redirektuje na Success stranicu, ali verifikacija ne prođe kako treba.

Pri kraju je dodato logovanje odgovora u fajl, a $this->finish_order() menja stanje porudžbine i čuva izmene u bazu podataka.

PHP kôd:
/**
* OK, verify payment
*
* @access public
* @param void
* @return null
*/
function paypal_notify() {
  
  
// Prepare
  
$url_parsed   parse_url('https://www.paypal.com/cgi-bin/webscr');
  
$ipn_data     = array();
  
$ipn_response '';
  
$post_string  '';

  
// Generate the post string from the $_POST vars aswell as load the
  // $_POST vars into an arry so we can play with them from the calling
  // script.
  
foreach ($_POST as $field => $value) { 
    
$ipn_data[$field] = $value;
    
$post_string .= $field.'='.urlencode($value).'&'
  } 
// foreach
  
  // Add to post string...
  
$post_string .= 'cmd=_notify-validate'// append ipn command
  
  // Init..
  
$err_no null;
  
$err_str null;

  
// open the connection to paypal
  
$fp fsockopen($url_parsed['host'], '80'$err_no$err_str30); 
  
  
// FSock?
  
if(!$fp) {
    die();
  } else { 

    
// Post the data back to paypal
    
fputs($fp"POST" $url_parsed['path'] .  "HTTP/1.1\r\n"); 
    
fputs($fp"Host: " $url_parsed['host'] . "\r\n"); 
    
fputs($fp"Content-type: application/x-www-form-urlencoded\r\n"); 
    
fputs($fp"Content-length: " strlen($post_string) . "\r\n"); 
    
fputs($fp"Connection: close\r\n\r\n"); 
    
fputs($fp$post_string "\r\n\r\n"); 
    
    
// loop through the response from the server and append to variable
    
while(!feof($fp)) $ipn_response .= fgets($fp1024);
    
fclose($fp); // close connection

  
// if
  
  // Prepare for file and write it to the file...
  
$for_file "Post string:\r\n\r\n$post_string\r\n\r\nResponse:\r\n\r\n$ipn_response";
  @
write_in_filedirname(__FILE__) . '/lasttransaction.txt'$for_file );
  
  
// Vefied?
  
if (eregi("VERIFIED"$ipn_response)) {
    
$this->finish_order(false);
  } 
// if

// paypal_notify 
Priloženi fajlovi
Tip fajla: zip paypal-1.0.0.zip (6,1 KB, 972 pregleda)
Ilija Studen je offline   Odgovorite uz citat