<?php

include 'common.php';


$appid = "696960";
$key = "97E44C8D71A80DAD981DCB66DC684403";

$json = json_decode(file_get_contents('php://input'));
$platform = $json->platform;
$orderid = $json->orderid;
$steamid = $json->steamid;
$itemcount = $json->itemcount;
$language = $json->language;
$currency = $json->currency;
$item_json = $json->item;
$item_array = json_decode($item_json);

$itemid_array = array();
$qty_array = array();
$amount_array = array();
$description_array = array();

for ($i = 0; $i < sizeof($item_array); $i++)
{
	array_push($itemid_array, $item_array[$i]->itemid);
	array_push($qty_array, $item_array[$i]->qty);
	array_push($amount_array, $item_array[$i]->amount);
	array_push($description_array, $item_array[$i]->description);
}

$url = 'https://partner.steam-api.com/ISteamMicroTxn/InitTxn/v3/'; //ÁÖ¼Ò¼ÂÆÃ
//$url = 'https://partner.steam-api.com/ISteamMicroTxnSandbox/InitTxn/v3/'; //ÁÖ¼Ò¼ÂÆÃ
$postfields["key"] = $key;
$postfields["orderid"] = $orderid;
$postfields["steamid"] = $steamid;
$postfields["appid"] = $appid;
$postfields["itemcount"] = $itemcount;
$postfields["language"] = $language;
$postfields["currency"] = $currency;
$postfields["itemid"] = $itemid_array;
$postfields["qty"] = $qty_array;
$postfields["amount"] = $amount_array;
$postfields["description"] = $description_array;

$ch = curl_init(); //curl ·Îµù

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_POST, true);

$curl_result = curl_exec ($ch); // curl ½ÇÇà ¹× °á°ú°ª ÀúÀå
curl_close ($ch); // curl Á¾·á

//$json_result = json_decode($curl_result, true);
var_dump($curl_result);
echo $curl_result;
?>