<?php 

function turkpin($siparis,$adet){

			$data=urun($siparis);
$xml_data ='DATA=<?xml version="1.0" encoding="utf-8"?>
<APIRequest>
<params>
<cmd>epinSiparisYarat</cmd>
<username>'.settings("turkpin_user").'</username>
<password>'.settings("turkpin_pass").'</password>
<oyunKodu>'.$data["oyunKod"].'</oyunKodu>
<urunKodu>'.$data["epinKod"].'</urunKodu>
<adet>'.$adet.'</adet>
</params>
</APIRequest>
';
$url = "https://www.turkpin.com/api.php";
  
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);      
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$xml   = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOCDATA);

$array = json_decode(json_encode((array)$xml), TRUE);
$durums=$array["params"]["HATA_NO"]; 
if($durums=="000"){
    if($array["params"]["epin_list"]["epin"]["code"]!=Null){
                    return $array["params"]["epin_list"]["epin"]["code"];
    }
    else{
        $yaz="";
        foreach($array["params"]["epin_list"]["epin"] as $deg => $val){
            if($yaz==Null){
            $yaz=$yaz." ".$val["code"];
            }
            else{
            $yaz=$yaz." | ".$val["code"];
            }
        }
        return $yaz;
    }
		
}
else{
return "";
}
}
