• 30-12-2024, 14:53:02
    #1
    Merhabalar, paytr ödeme alabilmek için işlem yapıyorum ama php codeignater da {"status":"failed","reason":"merchant_oid alfanumerik olmalidir, ozel karakter iceremez"} hatası almaktayım.
    'merchant_oid'    => uniqid(),
    şekilde yapınca hata veriyor.
     'merchant_oid' => preg_replace('/[^a-zA-Z0-9]/', '', uniqid()),
    şeklide yazınca ise ödeme sayfası 401 hatası alıyorum. çözemedim yardımcı olur musunuz?
  • 30-12-2024, 14:59:05
    #2
    merhaba şunu dener misin

    'merchant_oid' => preg_replace('/[^a-zA-Z0-9]/', '', uniqid('', true))
  • 30-12-2024, 15:03:05
    #3
    fyazilim adlı üyeden alıntı: mesajı görüntüle
    merhaba şunu dener misin

    'merchant_oid' => preg_replace('/[^a-zA-Z0-9]/', '', uniqid('', true))
    Maalesef
    https://www.paytr.com/odeme/api/get-token
    adresi 401 hatası veriyor
  • 30-12-2024, 15:11:16
    #4
    $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);
    $result = @curl_exec($ch);
    
    echo "giden<pre>";print_r( $result); echo "</pre>";die();
    
    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']);
    bu kodu dener misin
  • 30-12-2024, 15:24:10
    #5
    fyazilim adlı üyeden alıntı: mesajı görüntüle
    $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);
    $result = @curl_exec($ch);
    
    echo "giden<pre>";print_r( $result); echo "</pre>";die();
    
    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']);
    bu kodu dener misin
    PAYTR IFRAME failed. reason: olarak döndü kod:
    <?php
    if (!defined('BASEPATH')) exit('No direct script access allowed');
    
    class Payments extends EduAppGT
    {
        private $runningYear = '';
    
        function __construct()
        {
            parent::__construct();
            $this->load->database();
            $this->load->library('session');
            $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
            $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
            $this->output->set_header('Pragma: no-cache');
            $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
            $this->runningYear = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;
        }
    
        public function paytr($invoiceId = '')
        {
            if ($this->session->userdata('login_type') != 'student' && $this->session->userdata('login_type') != 'parent') {
                redirect(base_url(), 'refresh');
            }
    
            // Fatura bilgilerini al
            $invoiceDetails = $this->db->get_where('invoice', array('invoice_id' => base64_decode($invoiceId)))->row();
            if (empty($invoiceDetails) || $invoiceDetails->amount <= 0) {
                $this->session->set_flashdata('flash_message', getEduAppGTLang('invalid_payment_data'));
                redirect(base_url() . 'student/invoice/', 'refresh');
                exit;
            }
    
            $studentId = $invoiceDetails->student_id;
            $amount = $invoiceDetails->amount;
    
            // Öğrenci bilgilerini al
            $studentDetails = $this->db->get_where('student', array('student_id' => $studentId))->row();
            $email = $studentDetails->email;
            $userName = isset($studentDetails->first_name) && !empty($studentDetails->first_name) ? $studentDetails->first_name . ' ' . $studentDetails->last_name : 'Misafir Kullanıcı';
            $userAddress = isset($studentDetails->address) && !empty($studentDetails->address) ? $studentDetails->address : 'Adres Bilgisi Yok';
            $userPhone = isset($studentDetails->phone) && !empty($studentDetails->phone) ? $studentDetails->phone : 'Telefon Bilgisi Yok';
    
            // Kullanıcı IP adresini al
            $userIp = $_SERVER['REMOTE_ADDR'];
    
            // PayTR ödeme entegrasyonu
            $paymentData = array(
                'merchant_id'     => 'XXXXXX', ÖZELLİKLE KAPATTIM
                'merchant_key'    => 'XXXXXX',
                'merchant_salt'   => 'XXXXXX',
                'email'           => $email,
                'user_name'       => $userName,
                'user_address'    => $userAddress,
                'user_phone'      => $userPhone,
                'payment_amount'  => $amount * 100, // TL -> Kuruş
                'merchant_oid'    => preg_replace('/[^a-zA-Z0-9]/', '', uniqid()),
                'user_basket'     => base64_encode(json_encode(array(
                    array("Fatura Ödemesi", $amount, 1)
                ))),
                'callback_url'    => base_url('payments/paytr_success'),
                'merchant_ok_url' => base_url('payments/paytr_success'),
                'merchant_fail_url' => base_url('payments/paytr_failure'),
                'currency'        => 'TL',
                'user_ip'         => $userIp,
                'no_installment'  => 0, // Taksit seçeneği açık
                'max_installment' => 12, // Maksimum taksit sayısı
                'test_mode'       => 1, // Canlı mod
            );
    
            // Hash oluşturma
            $hashStr = $paymentData['merchant_id'] . $paymentData['user_ip'] . $paymentData['merchant_oid'] .
                $paymentData['email'] . $paymentData['payment_amount'] . $paymentData['currency'] .
                $paymentData['user_basket'] . $paymentData['callback_url'] . $paymentData['no_installment'] .
                $paymentData['max_installment'] . $paymentData['merchant_salt'];
    
            $paymentData['paytr_token'] = base64_encode(hash_hmac('sha256', $hashStr, $paymentData['merchant_key'], true));
    
            // Verileri logla
            log_message('info', 'PayTR Gönderilen Veriler: ' . print_r($paymentData, true));
    
            // cURL ile API bağlantısı
            $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, $paymentData);
            curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 20);
            $result = @curl_exec($ch);
    
            if (curl_errno($ch)) {
                die("PAYTR IFRAME connection error. err:" . curl_error($ch));
            }
    
            curl_close($ch);
    
            $result = json_decode($result, true);
    
            if ($result['status'] == 'success') {
                $token = $result['token'];
                echo "<script>window.location.href='https://www.paytr.com/odeme/iframe/' + '$token';</script>";
            } else {
                die("PAYTR IFRAME failed. reason:" . $result['reason']);
            }
        }
    
        public function paytr_success()
        {
            // ...
        }
    
        public function paytr_failure()
        {
            $this->session->set_flashdata('flash_message', getEduAppGTLang('payment_failed'));
            redirect(base_url() . 'student/invoice/', 'refresh');
        }
    }
    mevcut kod yapısı