<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 16/10/2017
 * Time: 20:55
 */

include_once 'loader.php';

//$func->prnt($_SERVER,true);

$request = new \Iyzipay\Request\CreateThreedsPaymentRequest();
$request->setLocale(\Iyzipay\Model\Locale::TR);
$request->setConversationId($func->post('conversationId'));
$request->setPaymentId($func->post('paymentId'));
$request->setConversationData($func->post('conversationData'));

# make request
$threedsPayment = \Iyzipay\Model\ThreedsPayment::create($request, Config::options());

$request = json_decode($threedsPayment->getRawResult());
# print result
//$func->prnt($request,true);
if($request->status=='success'){
    $db->query("UPDATE ".DBPREFIX."order SET status='1' WHERE id='".$request->conversationId."'");
    $success->set('Ödemeniz başarıyla alınmıştır.');
    $session->uset('order_id');
    $func->location('success');

}else{
    $db->query("UPDATE ".DBPREFIX."order SET error='Başarısız Ödeme: 3D dönüşünde ödeme alınamadı.' WHERE id='".$request->conversationId."'");
    $error->set(($request->errorMessage?$request->errorMessage:'Ödemeniz alınamadı! Lütfen tekrar deneyiniz.'));
    $session->uset('order_id');
    $func->location('error');
}

//print_r($threedsPayment);