vendredi 18 janvier 2019

How can i update two table admission & payments when payment is successful in laravel paytm?

I am saving name, class ,subject, user_id in admission table except payment_status and then after clicking on pay now button payments data such as payment_id , user_id , transaction_id, payment_status etc is captured in Payments table now how can i update payment_status field in admission when payment is successful in paytm.

 public function paynow(Request $request, $slug)
    {

     

      $payment_gateway = $request->gateway;

          if($payment_gateway=='paytm'){

               
         $order_id = strtolower(str_random(25));


        $token = $this->preserveBeforeSave($item,$order_id, $type,  $payment_gateway, $other_details);

        $data_for_request = $this->handlePaytmRequest( $order_id, $amount );


        $paytm_txn_url = 'https://securegw.paytm.in/theia/processTransaction';
        $paramList = $data_for_request['paramList'];
        $checkSum = $data_for_request['checkSum'];



        return view('payments.paytm',compact('paytm_txn_url','token', 'paramList', 'checkSum' ));


      }

      dd('please wait...');
    }
    
    
    public function handlePaytmRequest( $order_id, $amount ) {
        // Load all functions of encdec_paytm.php and config-paytm.php
        $this->getAllEncdecFunc();
        $this->getConfigPaytmSettings();

        $checkSum = "";
        $paramList = array();

        // Create an array having all required parameters for creating checksum.
        $paramList["MID"] = 'ytrytrytrytrty';
        $paramList["ORDER_ID"] = $order_id;
        $paramList["CUST_ID"] = $order_id;
        $paramList["INDUSTRY_TYPE_ID"] = 'Rta109';
        $paramList["CHANNEL_ID"] = 'WEB';
        $paramList["TXN_AMOUNT"] = '299';
        $paramList["WEBSITE"] = 'WEBPROD';
        $paramList["CALLBACK_URL"] = url( 'https://www.ravi.com/payments/paytm/paytmCallback' );
        $paytm_merchant_key = 'ytgduzyMHCahghghg9LlXnHlZ';

        //Here checksum string will return by getChecksumFromArray() function.
        $checkSum = getChecksumFromArray( $paramList, $paytm_merchant_key );

        return array(
            'checkSum' => $checkSum,
            'paramList' => $paramList
        );
    }
    
    
    public function paytmCallback( Request $request ) {
      
   
        $order_id = $request['ORDERID'];
               $user = Auth::user();


        if ( 'TXN_SUCCESS' === $request['STATUS'] ) {
            $transaction_id = $request['TXNID'];
            $status = $request['STATUS'];
           
            if($this->paymentSuccess($request))
        {


       
        }
        else {
       
        }

      //REDIRECT THE USER BY LOADING A VIEW

                return \Redirect()->route('account')->with('danger', 'Your payment was successfull, now you can give exam within 15 days');

        } else if( 'TXN_FAILURE' === $request['STATUS'] ){
                return \Redirect()->route('account')->with('danger', 'Your payment was failed, kindly try again');
        }
    }
    
     public function preserveBeforeSave($item, $order_id, $package_type,$payment_method)
    {

  
      $payment          = new Payment();
      $payment->item_id     = $item->id;
      $payment->item_name     = $item->title;
      $payment->plan_type     = $package_type;
      $payment->payment_gateway = $payment_method;
      $payment->slug      = $order_id;
      $payment->cost      = $item->cost;
      $payment->user_id     = $user->id;
      $payment->payment_status  = PAYMENT_STATUS_PENDING;
    
      $payment->save();
      return $payment->slug;
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire