daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function depositNotify(Request $request){
  2.         // Redirect here to Cinetpay with post data
  3.  
  4.         $deposit = Deposit::where('tx_id',$request->input('cpm_trans_id'))->first();
  5.        
  6.         if( $deposit ){
  7.             // We found the transaction in our database
  8.             if( $deposit->status == 'completed'){
  9.                 // The transaction is done
  10.                 die();
  11.             }else{
  12.                 $deposit->delete();
  13.             }
  14.         }
  15.      
  16.         $logs = var_export($_POST, true);
  17.         error_log($logs);
  18.         $deposit = new Deposit([
  19.             'amount' => $_POST['cpm_amount'],
  20.             'tx_id'=> $_POST['cpm_trans_id'],
  21.             'yustx_id' => $this->generateYustxId(),
  22.             'user_id' => $_POST['cpm_custom'],
  23.             'vendor' => 'cinetpay',
  24.             'method' => '',
  25.             'yus_fees_percentage' =>0,
  26.             'type' => 'deposit',
  27.             'status' => 'pending',
  28.             'ticker_symbol' =>'CFA',
  29.             'tx_hash' => $_POST['signature'],
  30.             'address' => $_POST['cel_phone_num']
  31.         ]);
  32.  
  33.         $deposit->save();
  34.  
  35.         //Let's now check the payment status
  36.  
  37.         $query = "?method=checkPayStatus";
  38.  
  39.         $response = $this->client->post($query,[
  40.             'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
  41.             'form_params' =>[
  42.                 'apikey'       => $this->cinetPay->apikey,
  43.                 'cpm_site_id'  => $this->siteId,
  44.                 'cpm_trans_id' => $deposit->tx_id
  45.             ]      
  46.         ]);
  47.  
  48.         $response = json_decode($response->getBody()->getContents());
  49.         $response = $response->transaction;
  50.         $logs = var_export($response, true);
  51.         error_log($logs);
  52.  
  53.         if( !empty($response->cpm_result) && $response->cpm_result == '00' && $response->cpm_amount == $deposit->amount && $response->signature == $deposit->tx_hash){
  54.             $deposit->status = 'completed';
  55.             $deposit->method= $_POST['payment_method'];
  56.             $deposit->save();
  57.  
  58.             // Update the user balance finally ...
  59.            
  60.             $userWallet = Wallet::where(['user_id'=>$deposit->user_id,'ticker_symbol'=>'CFA'])->first();
  61.  
  62.             $userWallet->balance += $response->cpm_amount;
  63.             $userWallet->save();
  64.  
  65.         }else{
  66.             $deposit->status = 'failed';
  67.             $deposit->save();
  68.         }
  69.  
  70.      }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top