Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. public function retorno_pagamento(){
  2.  
  3. $raw_post_data = file_get_contents('php://input');
  4.  
  5. //file_put_contents(FCPATH . 'pagamento.txt', $raw_post_data, FILE_APPEND);
  6.  
  7. $raw_post_response = 'cmd=_notify-validate&' . $raw_post_data;
  8.  
  9. if(!empty($raw_post_data)) {
  10. $ch = curl_init();
  11. curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
  12. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  13. curl_setopt($ch, CURLOPT_POST, 1);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, $raw_post_response);
  16. curl_setopt($ch, CURLOPT_SSLVERSION, 6);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  19. $response = curl_exec($ch);
  20. curl_close($ch);
  21. }
  22.  
  23. //file_put_contents(FCPATH . 'pagamento.txt', $response, FILE_APPEND);
  24.  
  25. if ($response == "VERIFIED" && $_POST['receiver_email'] == "XXXX") {
  26.  
  27. if ($_POST['payment_status'] == "Completed") {
  28.  
  29. $code = $_POST['txn_id'];
  30. $status = '3';
  31. $valor = $_POST['mc_gross'];
  32. $clienteNome = $_POST['first_name'] . " " . $_POST['last_name'];
  33. $clienteEmail = $_POST['payer_email'];
  34. $clientePhone = '';
  35. $pagamentoTipo = '1';
  36. $itemID = $_POST['item_number'];
  37.  
  38. $pedidos = $this->vendas->getAll(array(
  39. 'vendaTransacaoID' => $code
  40. ));
  41.  
  42. if ($pedidos->num_rows() == 0) {
  43. $id = self::_gravaRetorno($code, $itemID, $clienteNome, $clienteEmail, $clientePhone, $pagamentoTipo);
  44. self::_atualizaStatus($id, $status);
  45. }
  46. }
  47.  
  48. if($_POST['payment_status'] == "Denied") {
  49.  
  50. $code = $_POST['txn_id'];
  51. $status = '7';
  52. $valor = $_POST['mc_gross'];
  53. $clienteNome = $_POST['first_name'] . " " . $_POST['last_name'];
  54. $clienteEmail = $_POST['payer_email'];
  55. $clientePhone = '';
  56. $pagamentoTipo = '1';
  57. $itemID = $_POST['item_number'];
  58.  
  59. $pedidos = $this->vendas->getAll(array(
  60. 'vendaTransacaoID' => $code
  61. ));
  62.  
  63. $id = self::_gravaRetorno($code, $itemID, $clienteNome, $clienteEmail, $clientePhone, $pagamentoTipo);
  64. self::_atualizaStatus($id, $status);
  65. }
  66.  
  67.  
  68. } else {
  69. redirect();
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement