Advertisement
mr_maui

Untitled

Jun 23rd, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.84 KB | None | 0 0
  1. <?php
  2.  
  3. class PaypalController extends BaseController {
  4.  
  5. public function __construct()
  6. {
  7. $this->beforeFilter('authcliente');
  8. $this->beforeFilter('levelcliente');
  9. $this->beforeFilter('csrf', array('on' => array('post', 'delete', 'put')));
  10. $this->id_usuario = Session::get('id_usuario');
  11.  
  12. }
  13.  
  14.  
  15. public function getPaypal($costo)
  16. {
  17.  
  18. require_once('paypal/PPBootStrap.php');
  19.  
  20.  
  21. $url = dirname('http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']);
  22. $returnUrl = "$url/pagado";
  23. $cancelUrl = "$url/cancelado" ;
  24.  
  25. $currencyCode = "MXN";
  26.  
  27. // details about payment
  28. $paymentDetails = new PaymentDetailsType();
  29.  
  30. // total order amount
  31. //$paymentDetails->OrderTotal = new BasicAmountType($currencyCode, $_REQUEST['orderTotal']);
  32. $paymentDetails->OrderTotal = new BasicAmountType($currencyCode, $costo);
  33.  
  34. $paymentDetails->PaymentAction = "Sale";
  35.  
  36. $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
  37. $setECReqDetails->PaymentDetails[0] = $paymentDetails;
  38.  
  39. $setECReqDetails->CancelURL = $cancelUrl;
  40.  
  41. $setECReqDetails->ReturnURL = $returnUrl;
  42.  
  43. $setECReqType = new SetExpressCheckoutRequestType();
  44. $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
  45. $setECReq = new SetExpressCheckoutReq();
  46. $setECReq->SetExpressCheckoutRequest = $setECReqType;
  47.  
  48.  
  49. $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
  50. try {
  51. $setECResponse = $paypalService->SetExpressCheckout($setECReq);
  52. } catch (Exception $ex) {
  53. return "Error";
  54. }
  55. if(isset($setECResponse)) {
  56.  
  57. if($setECResponse->Ack =='Success') {
  58. return $token = $setECResponse->Token;
  59. }else {
  60. return "Error";
  61.  
  62. }
  63. }
  64. // require_once 'paypal/Response.php';
  65. }//end function
  66.  
  67.  
  68. public function setPaypal(){
  69.  
  70.  
  71. require_once('paypal/PPBootStrap.php');
  72.  
  73. $token =urlencode( $_REQUEST['token']);
  74. $payerId=urlencode( $_REQUEST['PayerID']);
  75. $paymentAction = "Sale";
  76.  
  77. $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
  78. $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
  79. $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
  80.  
  81. $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
  82. try {
  83. $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
  84. } catch (Exception $ex) {
  85. include_once("paypal/samples/Error.php");
  86. return "Error";
  87. }
  88.  
  89. $costo = Session::get('costo');
  90. $orderTotal = new BasicAmountType();
  91. $orderTotal->currencyID = "MXN";
  92. $orderTotal->value = $costo;
  93.  
  94. $paymentDetails= new PaymentDetailsType();
  95. $paymentDetails->OrderTotal = $orderTotal;
  96.  
  97. if(isset($_REQUEST['notifyURL']))
  98. {
  99. $paymentDetails->NotifyURL = $_REQUEST['notifyURL'];
  100. }
  101.  
  102. $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
  103. $DoECRequestDetails->PayerID = $payerId;
  104. $DoECRequestDetails->Token = $token;
  105. $DoECRequestDetails->PaymentAction = $paymentAction;
  106. $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
  107.  
  108. $DoECRequest = new DoExpressCheckoutPaymentRequestType();
  109. $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
  110.  
  111. $DoECReq = new DoExpressCheckoutPaymentReq();
  112. $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
  113.  
  114. try {
  115. $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
  116. } catch (Exception $ex) {
  117. // include_once("paypal/samples/Error.php");
  118. //return "Error";
  119. Session::flash('message', 'Ocurrio un problema, por favor contacte al proveedor.');
  120. return Redirect::to("/publicidad-client");
  121. }
  122.  
  123. if(isset($DoECResponse)) {
  124.  
  125. if(isset($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo)) {
  126.  
  127. define('TO', 'autorizaciones@yalahice.com');
  128. define('SUBJECT', 'Revision de nuevo contenido');
  129.  
  130. $nn = Session::get('titulo');
  131. $em = Session::get('name');
  132.  
  133.  
  134. $contratar = Session::get('contratar');
  135.  
  136. if ($contratar == "publicidad"){
  137. $body = "";
  138. $body .= "Se ha registrado una nueva publicidad que necesita ser aprobado <br />";
  139. $body .= "<br />";
  140. $body .= "Los Datos son: <br />";
  141. $body .= "Cliente: ".$em."<br />";
  142. $body .= "Titulo: ".$nn."<br />";
  143.  
  144. }else {
  145.  
  146. $body = "";
  147. $body .= "Se ha registrado una nueva propiedad que necesita ser aprobado <br />";
  148. $body .= "<br />";
  149. $body .= "Los Datos son: <br />";
  150. $body .= "Cliente: ".$em."<br />";
  151. $body .= "Titulo: ".$nn."<br />";
  152.  
  153.  
  154. }
  155.  
  156.  
  157. $sCabeceras = "From:judijemaui@gmail.com\n";
  158. $sCabeceras .= "CC:yalahice@hotmail.com\n";
  159.  
  160. //mail(TO, SUBJECT, $body, $sCabeceras);
  161.  
  162. require 'mailer/PHPMailer-master/PHPMailerAutoload.php';
  163.  
  164.  
  165. $mail = new PHPMailer;
  166.  
  167. $mail->Host = "smtpout.secureserver.net"; // SMTP server
  168. $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  169. $mail->SMTPAuth = true; // enable SMTP authentication
  170. // sets the SMTP server
  171. $mail->Port = 80; // set the SMTP port for the server
  172. $mail->Username = "yalahice.qroo@gmail.com"; // SMTP account username
  173. $mail->Password = "50p0r73@CZM"; // SMTP account password
  174. //$mail->AddAddress($email);
  175. $mail->AddAddress('webmaster@yalahice.com');
  176. $mail->AddAddress('autorizaciones@yalahice.com');
  177. $mail->AddAddress('alejandrovazquez@yalahice.com');
  178. $mail->Subject="Yalahice - Publicidad Cancelada.";
  179. // $mail->AddCC("dmas@bpmtech.com", "Bpmtechide");
  180.  
  181. $mail->SetFrom('yalahice.qroo@gmail.com', 'Yalahice');
  182.  
  183. $mail->MsgHTML($body);
  184.  
  185. if (!$mail->send()) {
  186. echo "Mailer Error: " . $mail->ErrorInfo;
  187. } else {
  188.  
  189. Session::flash('message', 'El pago se realizo con exito, un administrador validara su publicidad y sera publicada desde de las proximas 24 horas.');
  190. return Redirect::to("/publicidad-client");
  191. }
  192.  
  193.  
  194.  
  195.  
  196. }else {
  197. Session::flash('message', 'Ocurrio un problema, por favor contacte al proveedor.');
  198. return Redirect::to("/publicidad-client");
  199.  
  200. }
  201.  
  202. }
  203. //require_once 'paypal/samples/Response.php';
  204.  
  205.  
  206.  
  207.  
  208. }
  209.  
  210.  
  211. public function cancelPaypal(){
  212.  
  213.  
  214.  
  215.  
  216. $token = urlencode( $_REQUEST['token']);
  217.  
  218.  
  219. $contratar = Session::put('contratar');
  220.  
  221. if ($contratar == "publicidad"){
  222.  
  223. $cancelacion = Publicidad::where('ap', '=', $token)->get();
  224.  
  225. foreach ($cancelacion as $key) {
  226. $id = $key->id;
  227. $nn = $key->titulo;
  228. $id_cliente = $key->id_cliente;
  229.  
  230. }
  231.  
  232. $infos = User::where('id', '=', $id_cliente)->first();
  233. $em = $infos->name;
  234.  
  235.  
  236. define('TO', 'dmas@bpmtech.com');
  237. define('SUBJECT', 'Publicidad Cancelada');
  238.  
  239. $body = "";
  240. $body .= "Un contrato de publicidad no se completo correctamente, fue cancelada por el usuario <br />";
  241. $body .= "<br />";
  242. $body .= "Los Datos son: <br />";
  243. $body .= "Cliente: ".$em."<br />";
  244. $body .= "Titulo: ".$nn."<br />";
  245.  
  246.  
  247. $sCabeceras = "From:judijemaui@gmail.com\n";
  248. $sCabeceras .= "CC:yalahice@hotmail.com\n";
  249.  
  250. //mail(TO, SUBJECT, $body, $sCabeceras);
  251.  
  252. $publicidad = Publicidad::find($id);
  253. $publicidad->delete();
  254.  
  255. require 'mailer/PHPMailer-master/PHPMailerAutoload.php';
  256.  
  257.  
  258. $mail = new PHPMailer;
  259.  
  260. $mail->Host = "smtpout.secureserver.net"; // SMTP server
  261. $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  262. $mail->SMTPAuth = true; // enable SMTP authentication
  263. // sets the SMTP server
  264. $mail->Port = 80; // set the SMTP port for the server
  265. $mail->Username = "yalahice.qroo@gmail.com"; // SMTP account username
  266. $mail->Password = "50p0r73@CZM"; // SMTP account password
  267. //$mail->AddAddress($email);
  268. $mail->AddAddress('webmaster@yalahice.com');
  269. $mail->AddAddress('autorizaciones@yalahice.com');
  270. $mail->AddAddress('alejandrovazquez@yalahice.com');
  271. $mail->Subject="Yalahice - Publicidad Cancelada.";
  272. // $mail->AddCC("dmas@bpmtech.com", "Bpmtechide");
  273.  
  274. $mail->SetFrom('yalahice.qroo@gmail.com', 'Yalahice');
  275.  
  276. $mail->MsgHTML($body);
  277.  
  278. if (!$mail->send()) {
  279. echo "Mailer Error: " . $mail->ErrorInfo;
  280. } else {
  281.  
  282. Session::flash('message', 'La Cancelacion de la contratación se realizo correctamente.');
  283. return Redirect::to("/publicidad-client");
  284. }
  285.  
  286.  
  287.  
  288.  
  289. }else {
  290.  
  291.  
  292.  
  293. $cancelacion = Propiedades::where('ap', '=', $token)->get();
  294.  
  295. foreach ($cancelacion as $key) {
  296. $id = $key->id;
  297. $nn = $key->titulo;
  298. $id_cliente = $key->id_cliente;
  299.  
  300. }
  301.  
  302. $infos = User::where('id', '=', $id_cliente)->first();
  303. $em = $infos->name;
  304.  
  305.  
  306. define('TO', 'dmas@bpmtech.com');
  307. define('SUBJECT', 'Propiedad Cancelada');
  308.  
  309. $body = "";
  310. $body .= "Un contrato de propiedad no se completo correctamente, fue cancelada por el usuario <br />";
  311. $body .= "<br />";
  312. $body .= "Los Datos son: <br />";
  313. $body .= "Cliente: ".$em."<br />";
  314. $body .= "Titulo: ".$nn."<br />";
  315.  
  316.  
  317. $sCabeceras = "From:judijemaui@gmail.com\n";
  318. $sCabeceras .= "CC:yalahice@hotmail.com\n";
  319.  
  320. //mail(TO, SUBJECT, $body, $sCabeceras);
  321.  
  322. $publicidad = Propiedades::find($id);
  323. $publicidad->delete();
  324.  
  325.  
  326. require 'mailer/PHPMailer-master/PHPMailerAutoload.php';
  327.  
  328.  
  329. $mail = new PHPMailer;
  330.  
  331. $mail->Host = "smtpout.secureserver.net"; // SMTP server
  332. $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  333. $mail->SMTPAuth = true; // enable SMTP authentication
  334. // sets the SMTP server
  335. $mail->Port = 80; // set the SMTP port for the server
  336. $mail->Username = "yalahice.qroo@gmail.com"; // SMTP account username
  337. $mail->Password = "50p0r73@CZM"; // SMTP account password
  338. //$mail->AddAddress($email);
  339. $mail->AddAddress('webmaster@yalahice.com');
  340. $mail->AddAddress('autorizaciones@yalahice.com');
  341. $mail->AddAddress('alejandrovazquez@yalahice.com');
  342. $mail->Subject="Yalahice - Propiedad Cancelada.";
  343. // $mail->AddCC("dmas@bpmtech.com", "Bpmtechide");
  344.  
  345. $mail->SetFrom('yalahice.qroo@gmail.com', 'Yalahice');
  346.  
  347. $mail->MsgHTML($body);
  348.  
  349. if (!$mail->send()) {
  350. echo "Mailer Error: " . $mail->ErrorInfo;
  351. } else {
  352.  
  353. Session::flash('message', 'La Cancelacion de la contratación se realizo correctamente.');
  354. return Redirect::to("/propiedades-client");
  355. }
  356.  
  357.  
  358.  
  359. }
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367. }
  368.  
  369.  
  370. public function aPaypal(){
  371. return View::make('admin_cliente.pagar_es');
  372. }
  373.  
  374.  
  375.  
  376. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement