Exemplo n.º 1
0
 /**
  * manage confirm requests from EWAY API server
  */
 public function confirmPayment()
 {
     $response = $this->client->queryTransaction(Input::get('AccessCode'));
     $transactionResponse = $response->Transactions[0];
     if ($transactionResponse->TransactionStatus) {
         //echo 'Payment successful! ID: '.$transactionResponse->TransactionID;
         /*
         echo $transactionResponse->Options[0]['Value'].' <br/>';
         echo $transactionResponse->Options[1]['Value'].' <br/>';
         echo $transactionResponse->Options[2]['Value'];
         */
         $transaction = new IcePayTransaction();
         $transaction->user_id = Auth::user()->id;
         $transaction->tid = $transactionResponse->TransactionID;
         //transaction id or transaction bordereaux
         $transaction->sender_email = Auth::user()->email;
         //$payer['email']; //sender's email
         $transaction->receiver_email = $transactionResponse->Options[1]['Value'];
         //receiver's email or number
         $transaction->type = 'EWAY_' . $transactionResponse->Options[0]['Value'];
         $transaction->status = 'pending';
         //$transaction_json['related_resources'][0]['sale']['state'];
         $transaction->amount = $transactionResponse->TotalAmount / 100;
         //total amount deducted and transferred
         $transaction->currency = $transactionResponse->Options[2]['Value'];
         $transaction->save();
         $email = Auth::user()->email;
         //$payer['email'];
         $username = Auth::user()->username;
         Mail::send(['html' => 'emails.auth.transactions'], array('tdate' => date('Y-m-d H:i:s'), 'tid' => $transactionResponse->TransactionID, 'sender_email' => Auth::user()->email, 'sender_number' => Auth::user()->number, 'receiver_email' => $transaction->receiver_email, 'receiver_number' => $transaction->receiver_email, 'status' => 'PENDING', 'amount' => $transaction->amount - $transactionResponse->Options[3]['Value'] . ' ' . $transaction->currency, 'charge' => $transactionResponse->Options[3]['Value'] . ' ' . $transaction->currency, 'total' => $transaction->amount . ' ' . $transaction->currency, 'mode' => $transaction->type), function ($message) use($email, $username) {
             $message->to(array($email, '*****@*****.**', '*****@*****.**', '*****@*****.**'), $username)->subject('Transaction Receipt');
         });
         return Redirect::route('dashboard')->with('alertMessage', 'EWAY Transaction Successful');
     } else {
         $errors = str_split($transactionResponse->ResponseMessage);
         //previously splitte the string at the ', ' points
         foreach ($errors as $error) {
             $errmsg .= "Payment failed: " . \Eway\Rapid::getMessage($error) . "<br>";
         }
         return Redirect::route('dashboard')->with('alertError', $errmsg);
     }
 }
 /**
  *
  */
 public static function getErrorMessage($err)
 {
     return \Eway\Rapid::getMessage($err);
 }