<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class PaygPaypalController extends CI_Controller {
	
	function  __construct(){
        parent::__construct();
        $this->load->library('Paypal_lib');
		$this->load->model('GalleryModel');
    }
     
    function galleryipn(){
        $paypalInfo = $this->input->post();
        if(!empty($paypalInfo)){
            $ipnCheck = $this->paypal_lib->validate_ipn($paypalInfo);
            if($ipnCheck){
                $data['guest_id']       = $paypalInfo["custom"];
                $data['gallery_id']     = $paypalInfo["item_number"];
                $data['txn_id']         = $paypalInfo["txn_id"];
                $data['payment_gross']  = $paypalInfo["mc_gross"];
                $data['currency_code']  = $paypalInfo["mc_currency"];
                $data['payer_email']    = $paypalInfo["payer_email"];
                $data['payment_status'] = $paypalInfo["payment_status"];
                $data['created_at']     = date('Y-m-d H:i:s');

                $this->GalleryModel->insertTransaction($data);
                
                $this->session->set_userdata('payg-gallery', $data);
            }
        }
    }
    
    public function disablepg()
	{
	    $gallery_id = $this->input->post('gallery_id', TRUE);
		$this->session->unset_userdata('payg-gallery');
		echo "success";
	}
    
    function videoipn(){
        $paypalInfo = $this->input->post();
        if(!empty($paypalInfo)){
            $ipnCheck = $this->paypal_lib->validate_ipn($paypalInfo);
            if($ipnCheck){
                $data['guest_id']       = $paypalInfo["custom"];
                $data['gallery_id']     = $paypalInfo["item_number"];
                $data['txn_id']         = $paypalInfo["txn_id"];
                $data['payment_gross']  = $paypalInfo["mc_gross"];
                $data['currency_code']  = $paypalInfo["mc_currency"];
                $data['payer_email']    = $paypalInfo["payer_email"];
                $data['payment_status'] = $paypalInfo["payment_status"];
                $data['created_at']     = date('Y-m-d H:i:s');

                $this->GalleryModel->insertTransaction($data);
                
                $this->session->set_userdata('payg-video', $data);
            }
        }
    }
    
    public function disablepv()
	{
	    $video_id = $this->input->post('video_id', TRUE);
		$this->session->unset_userdata('payg-video');
		echo "success";
	}
}