home *** CD-ROM | disk | FTP | other *** search
/ 79.96.193.101 / 79.96.193.101.tar / 79.96.193.101 / www / przelewy24_callback.php < prev    next >
PHP Script  |  2014-10-20  |  6KB  |  152 lines

  1. <?php
  2. //============================================
  3. // Easy 2.0
  4. // Copyright     : .exe Evolution
  5. // Wersja        : 2.0
  6. // Uwagi         : Brak
  7. //============================================
  8. define("BASEDIR", dirname(__FILE__));
  9. include(BASEDIR . "/inc/init.php");
  10.  
  11. $tmpl = new Easy("templates/$THEME/");
  12. include(BASEDIR . "/system/shop/shopinc.php");
  13.  
  14. $this_url = "http://" .$_SERVER['HTTP_HOST'] . str_replace('/przelewy24_callback.php','',$_SERVER['PHP_SELF']);
  15.  
  16.  
  17. $sql_pp = $db->Query("SELECT inst_id FROM ".PREFIX."_shop_payment_methods WHERE id='9'");
  18. $row_pp = $sql_pp->fetchrow();
  19. define("SPID", $row_pp->inst_id); 
  20.  
  21. if($_POST["p24_error_code"]!="") {
  22.     $meta = '<meta http-equiv="refresh" content="0;URL='.$this_url.'/index.php?p=shop_orderconfirm&id=2&cid='.$za_id.'">';
  23. } else {
  24.   $za_id = $_POST["p24_session_id"];
  25.   $kwota = $_POST["p24_kwota"];
  26.   $za_kwota = number_format($_POST["p24_kwota"]/100,2,".","");
  27.   $order_id = $_POST["p24_order_id"];
  28.  
  29.     $q = "
  30.         SELECT
  31.             a.*,
  32.             b.email
  33.         FROM
  34.             " . PREFIX . "_shop_orders as a,
  35.             " . PREFIX . "_user as b
  36.         WHERE
  37.             a.control = '$za_id' AND
  38.             a.ovall = ".$za_kwota." AND
  39.             a.status_o != 'failed' AND
  40.             a.status_o != 'ok' AND
  41.             b.uid = a.uid
  42.         ";
  43.     $sql = $db->Query($q);
  44.     $row_u = $sql->fetchrow();
  45.     $uemail = $row_u->email;
  46.  
  47.     if($sql->numrows() == 1){
  48.  
  49.     $header  = "POST /transakcjanossl.php HTTP/1.1\r\n";
  50.     $header .= "Host: secure.przelewy24.pl\r\n";
  51.     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  52.  
  53.     $fp = fsockopen ("secure.przelewy24.pl", 80, $errno, $errstr, 30);
  54.     $P[] = urlencode("p24_id_sprzedawcy")."=".urlencode(SPID);
  55.     $P[] = urlencode("p24_session_id")."=".urlencode($za_id);
  56.     $P[] = urlencode("p24_order_id")."=".urlencode($order_id);
  57.     $P[] = urlencode("p24_kwota")."=".urlencode($kwota);
  58.     $post = join("&",$P);
  59.  
  60.     $req .= "Content-Length: ".strlen( $post )."\r\n\r\n";
  61.     $req .= $post;
  62.  
  63.     if(!$fp) {
  64.                 PutLog("Przelewy24: could not connect to secure.przelewy24.pl:80", PRIO_ERROR, __FILE__, __LINE__);
  65.         $meta = '<meta http-equiv="refresh" content="0;URL='.$this_url.'/index.php?p=shop_orderconfirm&id=2&cid='.$za_id.'">';
  66.     } else {
  67.       fputs ($fp, $header . $req);
  68.       $res = false;
  69.       while (!feof($fp)) {
  70.         $line = ereg_replace("[\n\r]","",fgets ($fp, 1024));
  71.         if($line != "RESULT" and !$res) continue;
  72.         if($res)$RET[] = $line;
  73.         else $res = true;
  74.       }
  75.       if($RET[0] == "TRUE") {
  76.                                 $sql_first = $db->Query("UPDATE ". PREFIX ."_shop_orders SET status_o = 'progress', order_id='".$order_id."' WHERE control = '$za_id' ");
  77.                 $items = explode(',', $row_u->articles);
  78.                                 $download_files = '';
  79.                 foreach($items as $item){
  80.                     $sql_esd = $db->Query("SELECT id,artnumber,esd_download,esd_dltimes,esd_timespan FROM " . PREFIX . "_shop_articles WHERE artnumber='$item'");
  81.                     $row_esd = $sql_esd->fetchrow();
  82.                     $esd_timespan = ($row_esd->esd_timespan=='') ? 0 : $row_esd->esd_timespan ;
  83.  
  84.                     $time_end = mktime(date("H")+$esd_timespan, date("i"), date("s"),date("m"), date("d"), date("Y"));
  85.                     if($row_esd->esd_download != '') {
  86.                         $itemkey = makepass(10);
  87.                         $sql_newesd = $db->Query("INSERT INTO " . PREFIX . "_shop_esd (id,uid,dltimes,dlid,dltimespan,itemkey) VALUES ('','$userId','','$row_esd->id','$time_end','$itemkey')");
  88.  
  89.                         $download_files .= "\n---------------------------------------\n$row_esd->esd_download ($row_esd->esd_dltimes ".$lang['shop_max_downloads_esd'].")\nhttp://" .$_SERVER['HTTP_HOST'] . str_replace('/przelewy24_callback.php','',$_SERVER['PHP_SELF']) . "/index.php?p=shop&action=downloadfile&file_id=$row_esd->id&itemkey=$itemkey\n";
  90.                         $download_files_copy .= "\n$row_esd->esd_download";
  91.                     }
  92.  
  93.                 }
  94.                 
  95.                                 if($download_files!=''){
  96.                     $body_first = str_replace("__TRANSID__", $za_id, $lang['shop_subject_cc_transaction_ok_header']);
  97.                     $mails = $body_first . "\n" . $download_files . "\n" . $lang['shop_footer_ccokesd_2'] . "\n\n" . SHOPADRESS;
  98.  
  99.                     $thismail = new MIMEMail();
  100.                     $thismail->from_email = EMAILFROM;
  101.                     $thismail->subject = $lang['shop_subject_cc_transaction_ok'];
  102.                     $thismail->to = $uemail;
  103.                     $thismail->headers();
  104.                     $thismail->addtextpart( false, $mails);
  105.                     $thismail->finish();
  106.                     $thismail->send();
  107.                 } else {
  108.                                     $body_first = str_replace("__TRANSID__", $za_id, $lang['shop_subject_cc_transaction_ok_header2']);
  109.                     $mails = $body_first . "\n\n" . SHOPADRESS;
  110.  
  111.                     $thismail = new MIMEMail();
  112.                     $thismail->from_email = EMAILFROM;
  113.                     $thismail->subject = $lang['shop_subject_cc_transaction_ok'];
  114.                     $thismail->to = $uemail;
  115.                     $thismail->headers();
  116.                     $thismail->addtextpart( false, $mails);
  117.                     $thismail->finish();
  118.                     $thismail->send();
  119.                 }
  120.  
  121.                                 $copybody = $lang['shop_subject_cc_transaction_ok_header_copy'];
  122.                 $copybody  = str_replace("__OVALL__", $za_kwota,$copybody);
  123.                 $copybody  = str_replace("__TRANSID__", $za_id ,$copybody);
  124.                 $copybody  = str_replace("__USERID__", $row_u->uid,$copybody);
  125.                 $copybody  = str_replace("__UEMAIL__", $uemail,$copybody);
  126.                 if($download_files_copy!='') $copybody .= "\n\n" . $lang['shop_copy_esdfoot_admin'] . "\n" . $download_files_copy;
  127.  
  128.                 $thismail = new MIMEMail();
  129.                 $thismail->from_email = EMAILFROM;
  130.                 $thismail->subject = $lang['shop_subject_cc_transaction_ok'];
  131.                 $thismail->to = EMAILTO;
  132.                 $thismail->headers();
  133.                 $thismail->addtextpart( false, $copybody);
  134.                 $thismail->finish();
  135.                 $thismail->send();
  136.                             $meta = '<meta http-equiv="refresh" content="0;URL='.$this_url.'/index.php?p=shop_orderconfirm&id=1&cid='.$za_id.'">';
  137.       }else {
  138.             PutLog("Przelewy24: got INVALID while trying to validate payment (" . $za_id . " / ".$RET[1]." )", PRIO_WARNING, __FILE__, __LINE__);
  139.                                     $meta = '<meta http-equiv="refresh" content="0;URL='.$this_url.'/index.php?p=shop_orderconfirm&id=2&cid='.$za_id.'">';
  140.       }
  141.     }
  142.     fclose ($fp);
  143.  
  144.     } else {
  145.                 PutLog("Przelewy24: incorrect order control or amount (" . $za_id ." )", PRIO_WARNING, __FILE__, __LINE__);
  146.         $meta = '<meta http-equiv="refresh" content="0;URL='.$this_url.'/index.php?p=shop_orderconfirm&id=2&cid='.$za_id.'">';
  147.     }
  148. }
  149. if(!isset($_GET["auto"])) echo $meta;
  150. else echo(strpos($meta,"id=1")!==false)?1:0;
  151.  
  152. ?>