Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //Coger eventos del día siguiente
     $events = Evento::getNextDayEventos()->get();
     foreach ($events as $e) {
         //Coger los gcm_regids de los voluntarios asignados al evento que pueden recibir notificaciones
         $registration_ids = Asistencia::getUsersToNotificate($e->ideventos)->get()->lists('gcm_token');
         $title = 'AFI Perú - Evento';
         $message = 'Recordatorio de evento: ' . $e->nombre . ' - ' . $e->fecha_evento;
         $type = 1;
         $m = ['title' => $title, 'message' => $message, 'type' => $type];
         $response = Helpers::pushGCM($registration_ids, $m);
         //$this->info(var_dump($response));
     }
     ///Coger todos los padrinos
     $sponsors = Padrino::getActivePadrinosPushInfo()->get();
     foreach ($sponsors as $s) {
         //Si el padrino tiene activado el push de pagos y tiene registadro su gcm_token
         if ($s->push_pagos && $s->gcm_token) {
             //Buscar si hay una deuda pendiente para el día siguiente
             $fee = CalendarioPago::getCalendarioPagoPendienteNextDayByPadrino($s->idpadrinos)->first();
             if ($fee) {
                 //$this->info(var_dump($s->gcm_regid));
                 $title = 'AFI Perú - Padrino';
                 $message = 'Recordatorio de pago: ' . $fee->vencimiento;
                 $type = 2;
                 $m = ['title' => $title, 'message' => $message, 'type' => $type];
                 $response = Helpers::pushGCM(array($s->gcm_token), $m);
                 //$this->info(var_dump($response));
             }
         }
     }
 }
 public function submit_registrar_pagos()
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         $data["permisos"] = Session::get('permisos');
         if (in_array('side_registrar_pago', $data["permisos"])) {
             $rules = array('comprobante' => 'required|numeric', 'banco' => 'required|alpha_spaces|min:2|max:100');
             $validator = Validator::make(Input::all(), $rules);
             $url = "padrinos/list_registrar_pagos";
             if ($validator->fails()) {
                 return Redirect::to($url)->withErrors($validator);
             } else {
                 $data["search"] = null;
                 $idcalendario_pagos = Input::get('idcalendario_pagos');
                 $num_comprobante = Input::get('comprobante');
                 $banco = Input::get('banco');
                 $pago = CalendarioPago::find($idcalendario_pagos);
                 $pago->fecha_pago = date("Y-m-d");
                 $pago->banco = $banco;
                 $pago->num_comprobante = $num_comprobante;
                 $pago->aprobacion = null;
                 $pago->save();
                 $descripcion_log = "Se registró el pago con id {{$pago->idcalendario_pagos}}";
                 Helpers::registrarLog(3, $descripcion_log);
                 return Redirect::to($url);
             }
         } else {
             // Llamo a la función para registrar el log de auditoria
             $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
             Helpers::registrarLog(10, $descripcion_log);
             Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.');
             return Redirect::to('/dashboard');
         }
     } else {
         return View::make('error/error');
     }
 }
Ejemplo n.º 3
0
 public function getPaymentStatus()
 {
     // Get the payment ID before session clear
     $payment_id = Session::get('paypal_payment_id');
     //echo '<pre>';print_r($payment_id);echo '</pre>';exit;
     // clear the session payment ID
     Session::forget('paypal_payment_id');
     //echo '<pre>';print_r(1);echo '</pre>';exit;
     if (!Input::get('PayerID') || !Input::get('token')) {
         return Redirect::to('padrinos/list_registrar_pagos')->with('error', 'El pago no se realizó correctamente');
     }
     //echo '<pre>';print_r($this->_api_context);echo '</pre>';exit;
     $payment = Payment::get($payment_id, $this->_api_context);
     // PaymentExecution object includes information necessary
     // to execute a PayPal account payment.
     // The payer_id is added to the request query parameters
     // when the user is redirected from paypal back to your site
     $execution = new PaymentExecution();
     $execution->setPayerId(Input::get('PayerID'));
     //Execute the payment
     $result = $payment->execute($execution, $this->_api_context);
     //echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later
     if ($result->getState() == 'approved') {
         // payment made
         $idpago = Session::get('idcalendario_pago');
         //echo '<pre>';print_r($idpago);echo '</pre>';exit;
         $pago = CalendarioPago::find($idpago);
         $pago->fecha_pago = date("Y-m-d");
         $pago->banco = "PayPal";
         $pago->aprobacion = 1;
         $pago->save();
         return Redirect::to('padrinos/list_registrar_pagos')->with('message', 'El pago se realizó correctamente');
     }
     return Redirect::to('padrinos/list_registrar_pagos')->with('error', 'El pago no se realizó correctamente');
 }
Ejemplo n.º 4
0
 public function verify()
 {
     $rules = array('payment_id' => 'required', 'payment_client' => 'required', 'fee_id' => 'required');
     $validator = \Validator::make(\Input::all(), $rules);
     if ($validator->fails()) {
         return \Response::json(['error' => 'Los parámetros payment_id, payment_client y fee_id son obligatorios.'], 200);
     }
     $payment_id = \Input::get('payment_id');
     $payment_client = json_decode(\Input::get('payment_client'));
     $fee_id = \Input::get('fee_id');
     if (!$payment_client) {
         return \Response::json(['error' => 'Error en el parámetro payment_client'], 200);
     }
     // get access token
     $credentials = 'AaojGtvv8YNz-PGOlN3B9qeKdu8UaWRDgGg5RBQgByyAaru1-kVTY4B5zQB1ZnSFqcKMBmuXsSdaHmow' . ':' . 'EOutb3ahbyP4iJsRL2NAGTfaJJZaoxqNW3Rqp-olcludUMKs0l2VB4Izo_WTt6hsTOvF0j7cjl-ABqJ6';
     $process = curl_init('https://api.sandbox.paypal.com/v1/oauth2/token');
     curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($process, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($process, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Accept-Language: en_US', 'Authorization: Basic ' . base64_encode($credentials)));
     curl_setopt($process, CURLOPT_HEADER, FALSE);
     //curl_setopt($process, CURLOPT_USERPWD, 'EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp' . ':' . 'EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp');
     //curl_setopt($process, CURLOPT_TIMEOUT, 30);
     //curl_setopt($process, CURLOPT_POST, 1);
     curl_setopt($process, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
     curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
     $response = curl_exec($process);
     curl_close($process);
     if (!$response) {
         return \Response::json(['error' => 'No hubo respuesta en la autenticacion a paypal'], 200);
     }
     $response_json = json_decode($response);
     $token = $response_json->access_token;
     // get payment details
     $process = curl_init('https://api.sandbox.paypal.com/v1/payments/payment/' . $payment_id);
     curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($process, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $token));
     curl_setopt($process, CURLOPT_HEADER, FALSE);
     curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
     $response = curl_exec($process);
     curl_close($process);
     if (!$response) {
         return \Response::json(['error' => 'No hubo respuesta en la peticion del detalle del pago a paypal.'], 200);
     }
     $payment = json_decode($response);
     //$payment = json_decode(\Input::get('payment_test'));
     //return \Response::json($payment, 200);
     if (!array_key_exists('state', $payment)) {
         return \Response::json(['error' => 'No se encontró el pago con id = ' . $payment_id], 200);
     }
     // verify the state approved
     if ($payment->state != 'approved') {
         return \Response::json(['error' => 'El pago no ha sido aprobado. Su estado es ' . $payment->state], 200);
     }
     // amount on client side
     $amount_client = $payment_client->amount;
     // currency on client side
     $currency_client = $payment_client->currency_code;
     // PayPal transactions
     $transactions = $payment->transactions;
     $transaction = $transactions[0];
     // amount on server side
     $amount_server = $transaction->amount->total;
     // currency on server side
     $currency_server = $transaction->amount->currency;
     $related_resources = $transaction->related_resources;
     $sale_state = $related_resources[0]->sale->state;
     // verify the amount
     if ($amount_server != $amount_client) {
         return \Response::json(['error' => 'Los montos del pago no coinciden.'], 200);
     }
     // verify the currency
     if ($currency_server != $currency_client) {
         return \Response::json(['error' => 'El tipo de moneda no coincide.'], 200);
     }
     // verify the sale state
     if ($sale_state != 'completed') {
         return \Response::json(['error' => 'Venta no completada.'], 200);
     }
     // update payment in the db
     $fee = \CalendarioPago::find($fee_id);
     //return $fee;
     $fecha_pago = \DateTime::createFromFormat('Y-m-d\\TH:i:s\\Z', $payment->create_time);
     $fee->fecha_pago = $fecha_pago->format('Y-m-d H:i:s');
     $fee->aprobacion = 2;
     $fee->save();
     return \Response::json(['success' => 1], 200);
 }