aaaa

 avatar
unknown
php
4 years ago
27 kB
8
Indexable
<?php

require 'application/libraries/Shopier.php';

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



class Payment extends G_Controller {





	public function index()

	{

		if (!isset($this->session->userdata('info')['id'])) {

        	flash('Ups.', 'Yetkin Olmayan Bir Yere Giriş Yapmaya Çalışıyorsun.');

            redirect(base_url(), 'refresh');

            exit;

        }



		$amount = $this->input->post('amount');

			if(isset($amount))

			{

				$user = $this->db->where('id', $this->session->userdata('info')['id'])->get('user')->row();

		    	$payment = $this->db->where('status', 1)->get('payment')->row();



		    	if ($payment->id == 1) {

		    		$this->paytr($user->id, $amount, 0);

		    	}else if ($payment->id == 3) {

		    		$this->shopier($user->id, $amount, 0);

		    	}else if ($payment->id == 4) {

		    		$this->payhesap($user->id, $amount, 0);

		    	}else if ($payment->id == 5) {

		    		$this->paylith($user->id, $amount, 0);

		    	}

			}else{

				flash('Ups.', 'Yüklenecek Miktarı Seçin.');

				redirect(base_url('client'), 'refresh');

				exit;

			}

			$this->cart->destroy();

	}



	public function buyOnCart()

	{

		$properties = $this->db->where('id', 1)->get('properties')->row();

		$this->load->model('M_Payment');

		$encode = json_encode($this->cart->contents(), JSON_UNESCAPED_UNICODE);

		$user = $this->db->where('id', $this->session->userdata('info')['id'])->get('user')->row();

		$cart = $this->cart->contents();

		$price = $this->M_Payment->calculate($encode);

		$price = $price + number_format(($price * $properties->commission) / 100, 2, '.', '');

		$order_id = $this->M_Payment->addShop($user->id, $encode, $price, 1);

		$shop = $this->db->where('order_id', $order_id)->get('shop')->row();

		$properties = $this->db->where('id', 1)->get('properties')->row();

		$payment = $this->db->where('status', 1)->get('payment')->row();

		if ($payment->id == 1) {

			$this->paytr($user->id, $price, 1, $shop->id);

		}else if ($payment->id == 3) {

			$this->shopier($user->id, $price, 1);

		}else if ($payment->id == 4) {

			$this->payhesap($user->id, $price, 1);

		}else if ($payment->id == 5) {

			$this->paylith($user->id, $price, 1);

		}

		
	}



	public function callback()

    {

    	$payment = $this->db->where('status', 1)->get('payment')->row();

    	if ($payment->id == 1) {

    		$shop = $this->db->where('order_id', $post['merchant_oid'])->get('shop')->row();

    			if($shop->type == 0) {

    				$this->paytrCallback();

    			}else{

    				$this->paytrCallbackCart();

    			}

    	}else if ($payment->id == 3) {

    		$shop = $this->db->where('order_id', $_POST['platform_order_id'])->get('shop')->row();

		    	if($shop->type == 0) {

    				$this->shopierCallback();

    			}else{

    				$this->shopierCallbackCart();

    			}

    	}else if ($payment->id == 4) {

    		$shop = $this->db->where('order_id', $_POST["returnID"])->get('shop')->row();

	    		if($shop->type == 0) {

    				$this->payhesapCallback();

    			}else{

    				$this->payhesapCallbackCart();

    			}

				}else if ($payment->id == 5) {

					$shop = $this->db->where('order_id', $_POST['conversationId'])->get('shop')->row();
	
						if($shop->type == 0) {
	
							$this->paylithCallback();
	
						}else{
	
							$this->paylithCallbackCart();
	
						}
	
				}

    }

		public function generatePaylithToken(
			string $apiKey,
			string $apiSecret,
			string $conversationId,
			string $userId,
			string $userEmail,
			string $userPhone,
			string $userIpAddress
		) {
				$hashStr = [
						'apiKey' => $apiKey,
						'conversationId' => $conversationId,
						'userId' => $userId,
						'userEmail' => $userEmail,
						'userPhone' => $userPhone,
						'userIpAddress' => $userIpAddress,
				];
		
				ksort($hashStr);
		
				$hash = hash_hmac('sha256', implode('|', $hashStr) . $apiSecret, $apiKey);
				return hash_hmac('md5', $hash, $apiKey);
		}

		private function paylith($user_id, $amount, $type) {
			$this->load->model('M_Payment');
			$user = $this->db->where('id', $user_id)->get('user')->row();
			$payment = $this->db->where('id', '5')->get('payment')->row();
			$encode = json_encode($this->cart->contents(), JSON_UNESCAPED_UNICODE);
			$randString = $this->M_Payment->addShop($user->id, $encode, $amount, $type);
			$shop = $this->db->where('order_id', $randString)->get('shop')->row();
			$properties = $this->db->where('id', 1)->get('properties')->row();
			if($shop->type == 0){
				$amount = $amount + number_format(($amount * $properties->commission) / 100, 2, '.', '');
			}
	
			if( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
				$ip = $_SERVER["HTTP_CLIENT_IP"];
			} elseif( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
				$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
			} else {
				$ip = $_SERVER["REMOTE_ADDR"];
			}
			$user_ip = $ip;
	
			$token = $this->generatePaylithToken($payment->api_key, $payment->secret_key, $randString, $user->id, $user->email, $user->phone, $user_ip);

			$fields = array(
				"locale" => "tr",
				"apiKey" => $payment->api_key,
				"token" => $token,
				"conversationId" => $randString,
				"userId" => $user->id,
				"userEmail" => $user->email,
				"userPhone" => $user->phone,
				"userIpAddress" => $user_ip,
				"productApi" => true,
				"productData" => array(
					"name" => $amount . "₺ Site Bakiyesi",
					"amount" => $amount * 100
					)
				);

			$ch = curl_init();
	
			curl_setopt_array($ch, array(
				CURLOPT_URL => "https://api.paylith.com/v1/token",
				CURLOPT_RETURNTRANSFER => true,
				CURLOPT_ENCODING => "",
				CURLOPT_MAXREDIRS => 10,
				CURLOPT_TIMEOUT => 30,
				CURLOPT_SSLVERSION => 6,
				CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
				CURLOPT_CUSTOMREQUEST => "POST",
				CURLOPT_POSTFIELDS => http_build_query($fields),
			));
	
			$result = curl_exec($ch);
			$result = json_decode($result, true);
	
			if ($result['status'] == "success") {
				$link = $result['paymentLink'];
				header("Location: $link"); // Müşteriyi sistemin bize gönderdiği ödeme sayfasına yönlendiriyoruz.
			} else print("Ödeme işlemi sırasında bir hata oluştu: " . $result["error"]["message"]);
	
			curl_close($ch);
		}

		private function paylithCallback() {
			$post = $_POST;

			$payment = $this->db->where('id', '6')->get('payment')->row();

			if (!isset($post['conversationId']) || !isset($post['orderId']) || !isset($post['hash']) ||
			!isset($post['paymentAmount']) || !isset($post['status']) || !isset($post['userId'])) {
				// Herhangi veri eksik ise, isteği sonlandırıyoruz.
				exit("Eksik Veri Gönderildi");
			}

			if ($post['status']) {

		    $conversationId = $post['conversationId'];
				$orderId = $post['orderId'];
		    $hash = $post['hash'];
				$amount = $post['paymentAmount'];
				$status = $post['status'];
				$userId = $post['userId'];

				$selfHash = hash_hmac('md5', hash_hmac('sha256', "$conversationId|$orderId|$amount|$status|$userId".$payment->secret_key, $payment->api_key), $payment->api_key);

				if($hash!=$selfHash) 
				{
						http_response_code(403);
						exit(json_encode(array("status"=>"error","message"=>"paymentHash is not vaild.")));
				}

				$order = $this->db->where('order_id', $conversationId)->get('shop')->row();

				if($order->status == 0){
					echo "OK";
					exit;
				}


				if( $status == 'SUCCESS' ) { ## Ödeme Onaylandı
					$this->load->model('M_Payment');
					$this->M_Payment->confirmShopForBalance($order->id);
					echo "OK";
					exit;
				} else { ## Ödemeye Onay Verilmedi
					echo $status;
					exit;
				}
				## Bildirimin alındığını PayTR sistemine bildir
				echo "OK";
				exit;
				}
			}

			private function paylithCallbackCart() {
				$post = $_POST;
	
				$payment = $this->db->where('id', '6')->get('payment')->row();
	
				if (!isset($post['conversationId']) || !isset($post['orderId']) || !isset($post['hash']) ||
				!isset($post['paymentAmount']) || !isset($post['status']) || !isset($post['userId'])) {
					// Herhangi veri eksik ise, isteği sonlandırıyoruz.
					exit("Eksik Veri Gönderildi");
				}
	
				if ($post['status']) {
	
					$conversationId = $post['conversationId'];
					$orderId = $post['orderId'];
					$hash = $post['hash'];
					$amount = $post['paymentAmount'];
					$status = $post['status'];
					$userId = $post['userId'];
	
					$selfHash = hash_hmac('md5', hash_hmac('sha256', "$conversationId|$orderId|$amount|$status|$userId".$payment->secret_key, $payment->api_key), $payment->api_key);
	
					if($hash!=$selfHash) 
					{
							http_response_code(403);
							exit(json_encode(array("status"=>"error","message"=>"paymentHash is not vaild.")));
					}
	
					$order = $this->db->where('order_id', $conversationId)->get('shop')->row();
	
					if($order->status == 0){
						echo "OK";
						exit;
					}
	
	
					if( $status == 'SUCCESS' ) { ## Ödeme Onaylandı
						$this->load->model('M_Payment');
						$this->cart->destroy();
						$this->M_Payment->confirmShopForCart($order->id);
						echo "OK";
						exit;
					} else { ## Ödemeye Onay Verilmedi
						echo $status;
						exit;
					}
					## Bildirimin alındığını PayTR sistemine bildir
					echo "OK";
					exit;
					}
				}

    private function shopier($user_id, $price, $type)

    {		

    		$properties = $this->db->where('id', 1)->get('properties')->row();

    		$user = $this->db->where('id', $user_id)->get('user')->row();

    		$this->load->model('M_Payment');

    		$shop = $this->db->where('id', '3')->get('payment')->row();



    		$shopier = new Shopier($shop->api_key, $shop->secret_key);

			$shopier->setBuyer([

				'id' => $user->id,

				'first_name' => $user->name,

				'last_name' => $user->surname,

				'email' => $user->email,

				'phone' => $user->phone,

				'price' => $price

			]);

			$shopier->setOrderBilling([

				'billing_address' => 'N/A - Dijital Ürün',

				'billing_city' => 'Istanbul',

				'billing_country' => 'Turkey',

				'billing_postcode' => '34000',

			]);

			$shopier->setOrderShipping([

				'shipping_address' => 'N/A - Dijital Ürün',

				'shipping_city' => 'Istanbul',

				'shipping_country' => 'Turkey',

				'shipping_postcode' => '34000',

			]);

			$encode = json_encode($this->cart->contents(), JSON_UNESCAPED_UNICODE);

			$order_id = $this->M_Payment->addShop($user->id, $encode, $price, $type);

			$shop = $this->db->where('order_id', $order_id)->get('shop')->row();

			if($shop->type == 0){

				$price = $price + number_format(($price * $properties->commission) / 100, 2, '.', '');

			}



			die($shopier->run($order_id, $price, base_url('payment/callback')));

    }



    private function shopierCallback()

    {

    	if ($post) {

	    	$this->load->model('M_Payment');

	    	$shop = $this->db->where('id', 3)->get('payment')->row();

				$shopiers = new Shopier($shop->api_key, $shop->secret_key);

				if($shopiers->verifyShopierSignature($post)) {

					$payment = $this->db->where('order_id', $this->input->post('platform_order_id'))->get('shop')->row();				

					if(isset($payment->id) && $payment->status != 0) {

						$this->M_Payment->confirmShopForBalance($payment->id);

						flash('Harika!', 'Bakiye Yüklemesi Tamamlandı.');

						redirect(base_url(), 'refresh');

						exit;

					}else {

						flash('Ups!', 'Bir sorun oluştu.');

						redirect(base_url(), 'refresh');

						exit;

					}

				}else {

						flash('Ups!', 'Bir sorun oluştu.');

						redirect(base_url(), 'refresh');

						exit;

				}

    	}else{

    		echo "Eksik Bilgiler Mevcut";

			exit;

    	}

    }



    private function shopierCallbackCart()

    {

    	if ($post) {

	    	$this->load->model('M_Payment');

	    	$shop = $this->db->where('id', 3)->get('payment')->row();

				$shopiers = new Shopier($shop->api_key, $shop->secret_key);

				if($shopiers->verifyShopierSignature($post)) {

					$payment = $this->db->where('order_id', $this->input->post('platform_order_id'))->get('shop')->row();				

					if(isset($payment->id) && $payment->status != 0) {

						$this->M_Payment->confirmShopForCart($payment->id);

						flash('Harika!', 'Satın Alımın Tamamlandı.');

						redirect(base_url(), 'refresh');

						exit;

					}else {

						flash('Ups!', 'Bir sorun oluştu.');

						redirect(base_url(), 'refresh');

						exit;

					}

				}else {

						flash('Ups!', 'Bir sorun oluştu.');

						redirect(base_url(), 'refresh');

						exit;

				}

    	}else{

    		echo "Eksik Bilgiler Mevcut";

			exit;

    	}

    }



    private function paytr(int $user_id, $amount, $type)

    {

            $properties = $this->db->where('id', 1)->get('properties')->row();

    		$this->load->model('M_Payment');

    		$user = $this->db->where('id', $user_id)->get('user')->row();

    		$payment = $this->db->where('id', '1')->get('payment')->row();

            $encode = json_encode($this->cart->contents(), JSON_UNESCAPED_UNICODE);

            $this->cart->destroy();

	        $randString = $this->M_Payment->addShop($user->id, $encode, $amount, $type);

	        $shop = $this->db->where('order_id', $randString)->get('shop')->row();

	        ## 1. ADIM için örnek kodlar ##



			####################### DÜZENLEMESİ ZORUNLU ALANLAR #######################

			#

			## API Entegrasyon Bilgileri - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz.

			$merchant_id 	= $payment->api_key;

			$merchant_key 	= $payment->secret_key;

			$merchant_salt	= $payment->token;

			#

			## Müşterinizin sitenizde kayıtlı veya form vasıtasıyla aldığınız eposta adresi

			$email = $user->email;

			#

			## Tahsil edilecek tutar.

			if($shop->type == 0){

				$amount = $amount + number_format(($amount * $properties->commission) / 100, 2, '.', '');

			}

			$payment_amount	= $amount * 100; //9.99 için 9.99 * 100 = 999 gönderilmelidir.

			#

			## Sipariş numarası: Her işlemde benzersiz olmalıdır!! Bu bilgi bildirim sayfanıza yapılacak bildirimde geri gönderilir.

			$merchant_oid = $randString;

			#

			## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız ad ve soyad bilgisi

			$user_name = $user->name . " " . $user->surname;

			#

			## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız adres bilgisi

			$user_address = "Istanbul";

			#

			## Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi

			$user_phone = $user->phone;

			#

			## Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa

			## !!! Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!

			## !!! Siparişi onaylayacağız sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).

			$merchant_ok_url = base_url('client/success');

			#

			## Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa

			## !!! Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır!

			## !!! Siparişi iptal edeceğiniz sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü).

			$merchant_fail_url = base_url('client/fail');

			#

			## Müşterinin sepet/sipariş içeriği

			$user_basket = base64_encode(json_encode(array(

				array("Dijital Ürün", $amount, 1) // 1. ürün (Ürün Ad - Birim Fiyat - Adet )

			)));

			#

			/* ÖRNEK $user_basket oluşturma - Ürün adedine göre array'leri çoğaltabilirsiniz

			$user_basket = base64_encode(json_encode(array(

				array("Örnek ürün 1", "18.00", 1), // 1. ürün (Ürün Ad - Birim Fiyat - Adet )

				array("Örnek ürün 2", "33.25", 2), // 2. ürün (Ürün Ad - Birim Fiyat - Adet )

				array("Örnek ürün 3", "45.42", 1)  // 3. ürün (Ürün Ad - Birim Fiyat - Adet )

			)));

			*/

			############################################################################################



			## Kullanıcının IP adresi

			if( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {

				$ip = $_SERVER["HTTP_CLIENT_IP"];

			} elseif( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {

				$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];

			} else {

				$ip = $_SERVER["REMOTE_ADDR"];

			}



			## !!! Eğer bu örnek kodu sunucuda değil local makinanızda çalıştırıyorsanız

			## buraya dış ip adresinizi (https://www.whatismyip.com/) yazmalısınız. Aksi halde geçersiz paytr_token hatası alırsınız.

			$user_ip=$ip;

			##



			## İşlem zaman aşımı süresi - dakika cinsinden

			$timeout_limit = "30";



			## Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz.

			$debug_on = 1;



		    ## Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir.

		    $test_mode = 0;



			$no_installment	= 1; // Taksit yapılmasını istemiyorsanız, sadece tek çekim sunacaksanız 1 yapın



			## Sayfada görüntülenecek taksit adedini sınırlamak istiyorsanız uygun şekilde değiştirin.

			## Sıfır (0) gönderilmesi durumunda yürürlükteki en fazla izin verilen taksit geçerli olur.

			$max_installment = 0;



			$currency = "TL";

			

			####### Bu kısımda herhangi bir değişiklik yapmanıza gerek yoktur. #######

			$hash_str = $merchant_id .$user_ip .$merchant_oid .$email .$payment_amount .$user_basket.$no_installment.$max_installment.$currency.$test_mode;

			$paytr_token=base64_encode(hash_hmac('sha256',$hash_str.$merchant_salt,$merchant_key,true));



			$post_vals=array(

					'merchant_id'=>$merchant_id,

					'user_ip'=>$user_ip,

					'merchant_oid'=>$merchant_oid,

					'email'=>$email,

					'payment_amount'=>$payment_amount,

					'paytr_token'=>$paytr_token,

					'user_basket'=>$user_basket,

					'debug_on'=>$debug_on,

					'no_installment'=>$no_installment,

					'max_installment'=>$max_installment,

					'user_name'=>$user_name,

					'user_address'=>$user_address,

					'user_phone'=>$user_phone,

					'merchant_ok_url'=>$merchant_ok_url,

					'merchant_fail_url'=>$merchant_fail_url,

					'timeout_limit'=>$timeout_limit,

					'currency'=>$currency,

		            'test_mode'=>$test_mode

				);

			

			$ch=curl_init();

			curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/get-token");

			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

			curl_setopt($ch, CURLOPT_POST, 1) ;

			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);

			curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);

			curl_setopt($ch, CURLOPT_TIMEOUT, 20);

			

			 // XXX: DİKKAT: lokal makinanızda "SSL certificate problem: unable to get local issuer certificate" uyarısı alırsanız eğer

		     // aşağıdaki kodu açıp deneyebilirsiniz. ANCAK, güvenlik nedeniyle sunucunuzda (gerçek ortamınızda) bu kodun kapalı kalması çok önemlidir!

		     // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			 

			$result = @curl_exec($ch);



			if(curl_errno($ch))

				die("PAYTR IFRAME connection error. err:".curl_error($ch));



			curl_close($ch);

			

			$result = json_decode($result,1);



			if($result['status']=='success')

				$token=$result['token'];

			else

				die("PAYTR IFRAME failed. reason:".$result['reason']);



			echo '<script src="https://www.paytr.com/js/iframeResizer.min.js"></script>

    <iframe src="https://www.paytr.com/odeme/guvenli/'. $token .'" id="paytriframe" frameborder="0" scrolling="no" style="width: 100%;"></iframe>

	<script>iFrameResize({},\'#paytriframe\');</script>';



    }



    private function paytrCallback()

    {
		$post = $post;



		$payment = $this->db->where('id', '1')->get('payment')->row();

		$merchant_key 	= $payment->secret_key;

		$merchant_salt	= $payment->token;



		$hash = base64_encode( hash_hmac('sha256', $post['merchant_oid'].$merchant_salt.$post['status'].$post['total_amount'], $merchant_key, true) );



		if( $hash != $post['hash'] )

			die('PAYTR notification failed: bad hash');



		$order = $this->db->where('order_id', $post['merchant_oid'])->get('shop')->row();



		if($order->status == 0){

			echo "OK";

			exit;

		}

        

		if( $post['status'] == 'success' ) { ## Ödeme Onaylandı

			$this->load->model('M_Payment');

			$this->M_Payment->confirmShopForBalance($order->id);

			echo "OK";

			exit;



		} else { ## Ödemeye Onay Verilmedi



			echo "OK";

			exit;

		}



		## Bildirimin alındığını PayTR sistemine bildir.

		echo "OK";

		exit;

    }



    private function paytrCallbackCart()

    {

		$post = $post;



		$payment = $this->db->where('id', '1')->get('payment')->row();

		$merchant_key 	= $payment->secret_key;

		$merchant_salt	= $payment->token;



		$hash = base64_encode( hash_hmac('sha256', $post['merchant_oid'].$merchant_salt.$post['status'].$post['total_amount'], $merchant_key, true) );



		if( $hash != $post['hash'] )

			die('PAYTR notification failed: bad hash');



		$order = $this->db->where('order_id', $post['merchant_oid'])->get('shop')->row();



		if($order->status == 0){

			echo "OK";

			exit;

		}

        

		if( $post['status'] == 'success' ) { ## Ödeme Onaylandı

			$this->load->model('M_Payment');

			$this->M_Payment->confirmShopForCart($order->id);

			echo "OK";

			exit;



		} else { ## Ödemeye Onay Verilmedi



			echo "OK";

			exit;

		}



		## Bildirimin alındığını PayTR sistemine bildir.

		echo "OK";

		exit;

    }





    private function payhesap(int $user_id, $amount, $type)

    {

    		$this->load->model('M_Payment');

    		$user = $this->db->where('id', $user_id)->get('user')->row();

    		$payment = $this->db->where('id', '4')->get('payment')->row();

    		$encode = json_encode($this->cart->contents(), JSON_UNESCAPED_UNICODE);

	        $randString = $this->M_Payment->addShop($user->id, $encode, $amount, $type);

	        $shop = $this->db->where('order_id', $randString)->get('shop')->row();


	        $properties = $this->db->where('id', 1)->get('properties')->row();
	        if($shop->type == 0){

				$amount = $amount + number_format(($amount * $properties->commission) / 100, 2, '.', '');

			}



    		$posts = [

		    "hash" => $payment->api_key,

		    "order_id" => $randString,

		    "callback_url" => base_url('client/callback'), //İşlem durumu hakkında bilgiler ve Payhesap üzerinden ödeme sorgulama aşaması

		    "amount" => $amount,

		    "installment" => "1",

		    "success_url" => base_url('client/success'), //Ödeme başarılı ise sayfa buraya yönlencek

		    "fail_url" => base_url('client/fail'),  //Ödeme başarısız ise sayfa buraya yönlencek

		    "name" => $user->name,

			"email" => $user->email,

			"phone" => $user->phone,

		    "city" => "İstanbul",

		    "state" => "Şişli",

		    "address" => "N/A - Bakiye Yüklemesi",

		    "ip" => $_SERVER['REMOTE_ADDR']

		];



		$encode = json_encode($posts, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);



		$ch = curl_init('https://www.payhesap.com/api/iframe/pay');

		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

		curl_setopt($ch, CURLOPT_POSTFIELDS, $encode);

		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		curl_setopt($ch, CURLOPT_HTTPHEADER, [

		        'Content-Type: application/json',

		        'Content-Length: ' . strlen($encode)

		    ]

		);

		$result = curl_exec($ch);



		$decode = json_decode($result, true);



		if(isset($decode['data']['token'])){ ?>



		    <script src="https://www.payhesap.com/iframe/iframeResizer.min.js"></script>

		    <iframe src="https://payhesap.com/api/iframe/<?=$decode['data']['token'];?>" id="payhesapiframe" frameborder="0" scrolling="yes" style="width: 100%;"></iframe>

		    <script>iFrameResize({},'#payhesapiframe');</script>

		<?php

		}else{

		    print_r($decode); // Bir sorun var mesajlar burada

		}

    }



    private function payhesapCallback()

 	{

 		if ($post['STATUS']) {

		    $orderID = $post['ORDER_REF_NUMBER'];

		    $hash = $post['HASH'];



		    $ch = curl_init('https://www.payhesap.com/api/pay/checkOrder');

		    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

		    curl_setopt($ch, CURLOPT_POSTFIELDS, array('hash' => $hash));

		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);;

		    $result = json_decode(curl_exec($ch),true);



		    if($result['statusID'] == 1 ){

		        $payment = $this->db->where('order_id', $orderID)->get('shop')->row();

		        if ($payment && $payment->status != 0) {

		        	$this->load->model('M_Payment');

		        	$cart = json_decode($payment->product, true);

		        	$this->M_Payment->confirmShopForBalance($payment->id);

		        	echo "OK";

		        	exit;

					}else {

						echo "OK";

						exit;

					}

		    }else{

		    	echo "OK";

				exit;

		    }

    	}else{

    		redirect(base_url('client/account'), 'refresh');

    	}

 	}



 	private function payhesapCallbackCart()

 	{

 		if ($post['STATUS']) {

		    $orderID = $post['ORDER_REF_NUMBER'];

		    $hash = $post['HASH'];



		    $ch = curl_init('https://www.payhesap.com/api/pay/checkOrder');

		    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

		    curl_setopt($ch, CURLOPT_POSTFIELDS, array('hash' => $hash));

		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);;

		    $result = json_decode(curl_exec($ch),true);



		    if($result['statusID'] == 1 ){

		        $payment = $this->db->where('order_id', $orderID)->get('shop')->row();

		        if ($payment && $payment->status != 0) {

		        	$this->load->model('M_Payment');

		        	$cart = json_decode($payment->product, true);

		        	$this->M_Payment->confirmShopForCart($payment->id);

		        	echo "OK";

		        	exit;

					}else {

						echo "OK";

						exit;

					}

		    }else{

		    	echo "OK";

				exit;

		    }

    	}else{

    		redirect(base_url('client/account'), 'refresh');

    	}

 	}

}

Editor is loading...