• 03-07-2023, 20:37:56
    #1
    Platin üye
    Merhaba arkadaşlar her şey tamam ama bildirim kısmında çözemediğim kısımlar var. Kod aşağıdaki gibi showBildirim kısmında post veri gelmiyor.

    public function showPayment(){
        $paytr=Payment::find(1);
        $config=Config::find(1);
        $whatsapp=Whatsapp::find(1);
        $headerfooters=HeaderFooters::find(1);
        
        $data = request()->all();
        
        $merchant_id    = $paytr->paymentsid;
        $merchant_key   = $paytr->paymentskey;
        $merchant_salt  = $paytr->paymentssalt;
    
        $urunid  = session('urunid');
        $adsoyad = session('adsoyad');
        $mail = session('mail');
        $telefon = session('telefon');
        $urunfiyat = session('urunfiyat');
    
        $random_id = "11".rand(1,999).rand(1,88)*rand(1,50);
        $email = $mail;
        $payment_amount =intval($urunfiyat * 100); //9.99 için 9.99 * 100 = 999 gönderilmelidir.
        $merchant_oid = $random_id;
        $user_name = $adsoyad;
        $user_address = "xxxxxxx";
        $user_phone = $telefon;
        $merchant_ok_url = "https://siteadresi.net/payments/paytr/onay";
        $merchant_fail_url = "https://siteadresi net/payments/paytr/hata";
        $user_basket = '1';
    
    
        $siparisler=new Siparisler;
        $siparisler->urunid=session('urunid');
        $siparisler->adsoyad=$adsoyad;
        $siparisler->mailadres=$mail;
        $siparisler->telno=$telefon;
        $siparisler->siparisfiyat=$urunfiyat;
        $siparisler->paytrid=$random_id;
        $siparisler->durum=0;
        $siparisler->save();
    
        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;
        $timeout_limit = "5";
        $debug_on = 1;
        $test_mode = 1;
    
        $no_installment = 1;
        $max_installment = 0;
    
        $currency = "TL";
    
        $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));
        $data_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, $data_vals);
        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,1);
    
        if($result['status']=='success')
            $token=$result['token'];
        else
            die("PAYTR IFRAME failed. reason:".$result['reason']);
    
             return view("payments/paytr/callback",compact("token", 'config','whatsapp','headerfooters'));
    
    
    }
    
    
    
    public function showBildirim(){
        
        $data =request()->all();
    
        $paytr=Payment::find(1);
        $config=Config::find(1);
        $whatsapp=Whatsapp::find(1);
        $headerfooters=HeaderFooters::find(1);
        $post =$_POST;
        $merchant_key     = $paytr->paymentskey;
        $merchant_salt    = $paytr->paymentssalt;
        
       $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');
    
        if( $post['status'] == 'success' ) {
            $urunid = session('urunid');
            $siparisler=Siparisler::findOrFail($urunid);
            $siparisler->durum=1;
            $siparisler->save();
    
            return view("payments/paytr/onay",compact('config','whatsapp','headerfooters'));
    
        } else { ## Ödemeye Onay Verilmedi
    
            $urunid = session('urunid');
            $siparisler=Siparisler::findOrFail($urunid);
            $siparisler->durum=2;
            $siparisler->save();
    
            $hatamesaj = $post['failed_reason_msg'];
            return view("payments/paytr/hata",compact('config','whatsapp','headerfooters','hatamesaj'));
            ## $post['failed_reason_code'] - başarısız hata kodu
            ## $post['failed_reason_msg'] - başarısız hata mesajı
        }
    }
  • 03-07-2023, 20:53:21
    #2
    Merhaba, öncelikle route yapısına bakılmalı eğer orada sorun yok ise ve csrf aktif ise showbildirim csrf ye takılıyor olabilir.
  • 03-07-2023, 21:00:02
    #3
    Platin üye
    HelluvA adlı üyeden alıntı: mesajı görüntüle
    Merhaba, öncelikle route yapısına bakılmalı eğer orada sorun yok ise ve csrf aktif ise showbildirim csrf ye takılıyor olabilir.
    Route yapısı bu şekilde

    Route::get('/payments/paytr/callback', [HomeController::class, 'showPayment'])->name('payments.paytr.callback');
  • 03-07-2023, 21:09:49
    #4
    Route'da "showBildirim" yerine "showPayment" fonksiyonunu tanımlamışsınız hocam.
  • 03-07-2023, 21:17:08
    #5
    Platin üye
    SinanSS adlı üyeden alıntı: mesajı görüntüle
    Route'da "showBildirim" yerine "showPayment" fonksiyonunu tanımlamışsınız hocam.
    Düzenledim gine aynı boş veri veriyor.

    Route::get('/payments/paytr/callback', [HomeController::class, 'showBildirim '])->name('payments.paytr.callback');
  • 03-07-2023, 21:18:11
    #6
    Dream4118 adlı üyeden alıntı: mesajı görüntüle
    Düzenledim gine aynı boş veri veriyor.

    Route::get('/payments/paytr/callback', [HomeController::class, 'showBildirim '])->name('payments.paytr.callback');
    showBildirim sonunda ki boşluğu sil birde öyle dene hocam
  • 03-07-2023, 21:21:43
    #7
    Platin üye
    SinanSS adlı üyeden alıntı: mesajı görüntüle
    showBildirim sonunda ki boşluğu sil birde öyle dene hocam
    sildim zaten hocam
  • 03-07-2023, 21:22:57
    #8
    Dream4118 adlı üyeden alıntı: mesajı görüntüle
    sildim zaten hocam
    Hocam o zaman özelden bi anydesk ya da teamviewer gönderin beraber bi bakalım 🤔
  • 03-07-2023, 22:01:51
    #9
    bu şekilde deneyin

    Route::post('/payments/paytr/onay', [HomeController::class, 'showBildirim'])->name('payments.paytr.onay');
    Route::post('/payments/paytr/hata', [HomeController::class, 'showBildirim'])->name('payments.paytr.hata');