Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.63 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\DB;
  7. use App\User;
  8. use App\Logs;
  9. use App\Config;
  10.  
  11. class Pagseguro extends Model
  12. {
  13.  
  14.     private $credentials;
  15.  
  16.     public function __construct(){
  17.         $this->credentials = $this->getCredentials();
  18.     }
  19.  
  20.     public function getCredentials(){
  21.         $config = new Config();
  22.         /*  */
  23.         $dados = json_decode($config->getPagseguro());
  24.  
  25.         if($dados->metodo == "sandbox"){
  26.             return json_decode(json_encode(array(
  27.                 "type" => "sandbox",
  28.                 "token" => "77DBB23D06434213A8E9A57C8D30C2C4",
  29.                 "usuario" => "pagseguro@clubedetiroliberdade.com.br",
  30.                 "session" => "https://ws.sandbox.pagseguro.uol.com.br/v2/sessions",
  31.                 "transaction" => "https://ws.sandbox.pagseguro.uol.com.br/v2/transactions",
  32.                 "email" => "c22731539627466576438@sandbox.pagseguro.com.br", // para usar o sandbox como cliente
  33.                 "notification" => "https://ws.sandbox.pagseguro.uol.com.br/v3/transactions/notifications/",
  34.             )));
  35.         }elseif($dados->metodo == "production"){
  36.             return json_decode(json_encode(array(
  37.                 "type" => "production",
  38.                 "usuario" => $dados->usuario, // pagseguro@clubedetiroliberdade.com.br
  39.                 "token" => $dados->token,// C56284A69898CACAA4EC1F829C122A41
  40.                 "session" => "https://ws.pagseguro.uol.com.br/v2/sessions",
  41.                 "transaction" => "https://ws.pagseguro.uol.com.br/v2/transactions",
  42.                 "notification" => "https://ws.pagseguro.uol.com.br/v3/transactions/notifications/",
  43.             )));
  44.         }  
  45.     }
  46.  
  47.     public function convertCPF($cpf)
  48.     {
  49.         $ex1 = str_replace(".", "", $cpf);
  50.         $ex2 = str_replace("-", "", $ex1);
  51.         return $ex2;
  52.     }
  53.  
  54.     public function getAreaCode($cel)
  55.     {
  56.         $ex1 = explode("(", $cel); // (81) 99999-9999
  57.         $ex2 = explode(") ", $ex1[1]);
  58.         return $ex2[0];
  59.     }
  60.  
  61.     public function getOnlyCelNumber($cel)
  62.     {
  63.         $ex1 = explode("(", $cel);
  64.         $ex2 = explode(") ", $ex1[1]);
  65.         return str_replace("-", "", $ex2[1]);
  66.     }
  67.  
  68.     public function getOnlyCepNumber($cep)
  69.     {
  70.         $ex1 = str_replace(".", "", $cep);
  71.         $ex2 = str_replace("-", "", $ex1);
  72.         return $ex2;
  73.     }
  74.    
  75.     public function createSession()
  76.     {
  77.         $acesso = $this->getCredentials();
  78.  
  79.         $credentials = array(
  80.             "token" => $acesso->token,
  81.             "email" => $acesso->usuario
  82.         );
  83.         $data = http_build_query($credentials);
  84.  
  85.         $curl = curl_init();
  86.  
  87.         $headers = array('Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1'
  88.             );
  89.  
  90.         //$url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/sessions';
  91.         $url = $acesso->session;
  92.  
  93.         curl_setopt($curl, CURLOPT_URL, $url);
  94.         curl_setopt($curl, CURLOPT_POST, true);
  95.         curl_setopt( $curl,CURLOPT_HTTPHEADER, $headers );
  96.         curl_setopt( $curl,CURLOPT_RETURNTRANSFER, true );
  97.         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  98.         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  99.         //curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  100.         curl_setopt($curl, CURLOPT_HEADER, false);
  101.         $xml = curl_exec($curl);
  102.  
  103.         $err = curl_error($curl);
  104.  
  105.         curl_close($curl);
  106.  
  107.         if ($err) {
  108.                 return false;
  109.         } else {
  110.             if($xml == "Unauthorized"):
  111.  
  112.                 return false;
  113.  
  114.             else:
  115.  
  116.                 $xml= simplexml_load_string($xml);
  117.                 return $xml->id;
  118.  
  119.             endif;
  120.         }
  121.     }
  122.     /*
  123.         Formas de pagamento:
  124.         1 - crédito
  125.         2 - boleto
  126.         3 - débito
  127.  
  128.         Status do pagamento
  129.         1 - Aguardando pagamento
  130.         2 - Em análise
  131.         3 - Paga
  132.         4 - Disponível
  133.         5 - Em disputa
  134.         6 - Devolvida
  135.         7 - Cancelada
  136.     */
  137.     public function createPaymentBoleto($valor, $valor_inicial, $user, $senderHash)
  138.     {
  139.         $acesso = $this->getCredentials();
  140.         $info = [
  141.             'filiado' => auth()->user()->id,
  142.             'valor' => $valor,
  143.             'valor_inicial' => $valor_inicial,
  144.             'forma' => 2,
  145.             'parcelas' => 1,
  146.             'token' => hash('md5', "Transaction_".date("YmdHis").auth()->user()->private_key),
  147.             'transaction_type' => 2, // igual a forma, rever isso
  148.             'created_at' => date("Y-m-d H:i:s"),
  149.             'updated_at' => date("Y-m-d H:i:s"),
  150.             'status' => 1
  151.         ];
  152.  
  153.  
  154.         DB::beginTransaction();
  155.  
  156.         if(DB::table('anuidades')->insert($info)){
  157.  
  158.             if($acesso->type == "sandbox"){
  159.                 $email_sender = $acesso->email;
  160.             }else{
  161.                 $email_sender = auth()->user()->email;
  162.             }
  163.  
  164.             $credentials = array(
  165.                 // config
  166.                 "token" => $acesso->token,
  167.                 "email" => $acesso->usuario,
  168.                 "paymentMode" => "default",
  169.                 "paymentMethod" => "boleto", /* ver aqui */
  170.                 "receiverEmail" => $acesso->usuario,
  171.                 "currency" => "BRL",
  172.                 "extraAmount" => "0.00",
  173.                 // Anuidade em si
  174.                 "itemId1" => "0001",
  175.                 "itemDescription1" => "Anuidade Clube de Tiro Liberdade",
  176.                 "itemAmount1" => number_format($valor, 2, '.', ''),
  177.                 "itemQuantity1" => 1,
  178.                 // sobre o sistema
  179.                 "notificationURL" => "https://clubedetiroliberdade.com.br/pagseguro/notification",
  180.                 "reference" => $info["token"], // Gerar um token único
  181.                 // Dados Filiado
  182.                 "senderName" => auth()->user()->name,
  183.                 "senderCPF" => $this->convertCPF(auth()->user()->cpf),
  184.                 "senderAreaCode" => $this->getAreaCode(auth()->user()->cel),
  185.                 "senderPhone" => $this->getOnlyCelNumber(auth()->user()->cel),
  186.                 "senderEmail" => $email_sender,
  187.                 "senderHash" => $senderHash,
  188.                 "shippingAddressStreet" => auth()->user()->logradouro,
  189.                 "shippingAddressNumber" => auth()->user()->num,
  190.                 "shippingAddressComplement" => auth()->user()->comp,
  191.                 "shippingAddressDistrict" => auth()->user()->bairro,
  192.                 "shippingAddressPostalCode" => $this->getOnlyCepNumber(auth()->user()->cep),
  193.                 "shippingAddressCity" => auth()->user()->cidade,
  194.                 "shippingAddressState" => strtoupper(auth()->user()->uf),
  195.                 "shippingAddressCountry" => "ATA",
  196.                 "shippingType" => 3,
  197.                 "shippingCost" => "0.00",
  198.             );
  199.            
  200.             $transaction =  $this->createTransaction($credentials);
  201.             if($transaction):
  202.                 $logs = new Logs;
  203.                 if($logs->registerLog("Realizou um pagamento")){
  204.                     DB::commit();
  205.                     return $transaction;
  206.                 }else{
  207.                     DB::rollBack();
  208.                     return redirect()
  209.                             ->back()
  210.                             ->with('error', 'Falha ao realizar pagamento.');
  211.                 }
  212.             else:
  213.                 DB::rollBack();
  214.                 return redirect()
  215.                         ->back()
  216.                         ->with('error', 'Falha ao realizar pagamento.');
  217.             endif;            
  218.         }else{
  219.             DB::rollBack();
  220.             return redirect()
  221.                         ->back()
  222.                         ->with('error', 'Falha ao realizar pagamento.');
  223.         }
  224.     }
  225.  
  226.     public function createPaymentCreditCard($dados)
  227.     {
  228.         $acesso = $this->getCredentials();
  229.         $info = [
  230.             'filiado' => auth()->user()->id,
  231.             'valor' => $dados["valor"],
  232.             'valor_inicial' => $dados["valor_inicial"],
  233.             'forma' => 1,
  234.             'parcelas' => $dados["parcelas"],
  235.             'token' => hash('md5', "Transaction_".date("YmdHis").auth()->user()->private_key),
  236.             'transaction_type' => 2, // igual a forma, rever isso
  237.             'created_at' => date("Y-m-d H:i:s"),
  238.             'updated_at' => date("Y-m-d H:i:s"),
  239.             'status' => 1
  240.         ];
  241.         DB::beginTransaction();
  242.         if(DB::table('anuidades')->insert($info)){
  243.             if($dados["valor"] > 500){
  244.                 $maxp = 5;
  245.             }else{
  246.                 $maxp = 3;
  247.             }
  248.             if($acesso->type == "sandbox"){
  249.                 $email_sender = $acesso->email;
  250.             }else{
  251.                 $email_sender = auth()->user()->email;
  252.             }
  253.             $credentials = array(
  254.                 "token" => $acesso->token,
  255.                 "email" => $acesso->usuario,
  256.                 "paymentMode" => "default",
  257.                 "paymentMethod" => "creditCard", /* ver aqui */
  258.                 "receiverEmail" => $acesso->usuario,
  259.                 "currency" => "BRL",
  260.                 "extraAmount" => "0.00",
  261.                 // Anuidade em si
  262.                 "itemId1" => "0001",
  263.                 "itemDescription1" => "Anuidade Clube de Tiro Liberdade",
  264.                 "itemAmount1" => number_format($dados["valor"], 2, '.', ''),
  265.                 "itemQuantity1" => 1,
  266.                 "installmentQuantity" => $dados["parcelas"],
  267.                 "installmentValue" => $dados["parcelavalor"],
  268.                 "noInterestInstallmentQuantity" => $maxp,
  269.                 // sobre o sistema
  270.                 "notificationURL" => "https://clubedetiroliberdade.com.br/pagseguro/notification",
  271.                 "reference" => $info["token"], // Gerar um token único
  272.                 // Dados Filiado
  273.                 "senderName" => auth()->user()->name,
  274.                 "senderCPF" => $this->convertCPF(auth()->user()->cpf),
  275.                 "senderAreaCode" => $this->getAreaCode(auth()->user()->cel),
  276.                 "senderPhone" => $this->getOnlyCelNumber(auth()->user()->cel),
  277.                 "senderEmail" => $email_sender,
  278.                 "senderHash" => $dados["senderHash"],
  279.                 "creditCardToken" => $dados["cardToken"],
  280.                 "creditCardHolderName" => $dados["titular"],
  281.                 "creditCardHolderCPF" => $dados["tcpf"],
  282.                 "creditCardHolderBirthDate" => $dados["tnasc"],
  283.                 "creditCardHolderAreaCode" => $this->getAreaCode(auth()->user()->cel),
  284.                 "creditCardHolderPhone" => $this->getOnlyCelNumber(auth()->user()->cel),
  285.  
  286.                 "billingAddressStreet" => auth()->user()->logradouro,
  287.                 "billingAddressNumber" => auth()->user()->num,
  288.                 "billingAddressComplement" => auth()->user()->comp,
  289.                 "billingAddressDistrict" => auth()->user()->bairro,
  290.                 "billingAddressPostalCode" => $this->getOnlyCepNumber(auth()->user()->cep),
  291.                 "billingAddressCity" => auth()->user()->cidade,
  292.                 "billingAddressState" => strtoupper(auth()->user()->uf),
  293.                 "billingAddressCountry" => "ATA",
  294.  
  295.                 "shippingAddressStreet" => auth()->user()->logradouro,
  296.                 "shippingAddressNumber" => auth()->user()->num,
  297.                 "shippingAddressComplement" => auth()->user()->comp,
  298.                 "shippingAddressDistrict" => auth()->user()->bairro,
  299.                 "shippingAddressPostalCode" => $this->getOnlyCepNumber(auth()->user()->cep),
  300.                 "shippingAddressCity" => auth()->user()->cidade,
  301.                 "shippingAddressState" => strtoupper(auth()->user()->uf),
  302.                 "shippingAddressCountry" => "ATA",
  303.                 "shippingType" => 3,
  304.                 "shippingCost" => "0.00",
  305.             );
  306.  
  307.             $transaction =  $this->createTransaction($credentials);
  308.             if($transaction):
  309.                 $logs = new Logs;
  310.                 if($logs->registerLog("Realizou um pagamento")){
  311.                     DB::commit();
  312.                     return $transaction;
  313.                 }else{
  314.                     DB::rollBack();
  315.                     return redirect()
  316.                             ->back()
  317.                             ->with('error', 'Falha ao realizar pagamento.');
  318.                 }
  319.  
  320.             else:
  321.  
  322.                 DB::rollBack();
  323.                 return redirect()
  324.                         ->back()
  325.                         ->with('error', 'Falha ao criar Fatura.');
  326.             endif;      
  327.  
  328.         }else{
  329.             DB::rollBack();
  330.             return false;
  331.         }        
  332.     }
  333.  
  334.     public function createPaymentDebit($dados)
  335.     {
  336.  
  337.         $acesso = $this->getCredentials();
  338.         $info = [
  339.             'filiado' => auth()->user()->id,
  340.             'valor' => $dados["valor"],
  341.             'valor_inicial' => $dados["valor_inicial"],
  342.             'forma' => 3,
  343.             'parcelas' => 1,
  344.             'token' => hash('md5', "Transaction_".date("YmdHis").auth()->user()->private_key),
  345.             'transaction_type' => 3, // igual a forma, rever isso
  346.             'created_at' => date("Y-m-d H:i:s"),
  347.             'updated_at' => date("Y-m-d H:i:s"),
  348.             'status' => 1
  349.         ];
  350.         if(DB::table('anuidades')->insert($info)){
  351.  
  352.             if($acesso->type == "sandbox"){
  353.                 $email_sender = $acesso->email;
  354.             }else{
  355.                 $email_sender = auth()->user()->email;
  356.             }
  357.             $credentials = array(
  358.                 "token" => $acesso->token,
  359.                 "email" => $acesso->usuario,
  360.                 "paymentMode" => "default",
  361.                 "paymentMethod" => "eft", /* ver aqui */
  362.                 "bankName" => $dados["bankName"],// só no débito
  363.                 "receiverEmail" => $acesso->usuario,
  364.                 "currency" => "BRL",
  365.                 "extraAmount" => "0.00",
  366.                 // Anuidade em si
  367.                 "itemId1" => "0001",
  368.                 "itemDescription1" => "Anuidade Clube de Tiro Liberdade",
  369.                 "itemAmount1" => number_format($dados["valor"], 2, '.', ''),
  370.                 "itemQuantity1" => 1,
  371.                 "notificationURL" => "https://clubedetiroliberdade.com.br/pagseguro/notification",
  372.                 "reference" => $info["token"], // Gerar um token único
  373.                 // Dados Filiado
  374.                 "senderName" => auth()->user()->name,
  375.                 "senderCPF" => $this->convertCPF(auth()->user()->cpf),
  376.                 "senderAreaCode" => $this->getAreaCode(auth()->user()->cel),
  377.                 "senderPhone" => $this->getOnlyCelNumber(auth()->user()->cel),
  378.                 "senderEmail" => $email_sender,
  379.                 "shippingAddressStreet" => auth()->user()->logradouro,
  380.                 "shippingAddressNumber" => auth()->user()->num,
  381.                 "shippingAddressComplement" => auth()->user()->comp,
  382.                 "shippingAddressDistrict" => auth()->user()->bairro,
  383.                 "shippingAddressPostalCode" => $this->getOnlyCepNumber(auth()->user()->cep),
  384.                 "shippingAddressCity" => auth()->user()->cidade,
  385.                 "shippingAddressState" => strtoupper(auth()->user()->uf),
  386.                 "shippingAddressCountry" => "ATA",
  387.                 "shippingType" => 3,
  388.                 "shippingCost" => "0.00",
  389.             );
  390.  
  391.             $transaction =  $this->createTransaction($credentials);
  392.             if($transaction):
  393.                 $logs = new Logs;
  394.                 if($logs->registerLog("Realizou um pagamento")){
  395.                     DB::commit();
  396.                     return $transaction;
  397.                 }else{
  398.                     DB::rollBack();
  399.                     return redirect()
  400.                             ->back()
  401.                             ->with('error', 'Falha ao realizar pagamento.');
  402.                 }
  403.             else:
  404.                 DB::rollBack();
  405.                 return redirect()
  406.                         ->back()
  407.                         ->with('error', 'Falha ao criar Fatura.');
  408.             endif;      
  409.  
  410.         }else{
  411.             DB::rollBack();
  412.             return false;
  413.         }    
  414.     }
  415.  
  416.     public function createAnuidade($array)
  417.     {
  418.     }
  419.  
  420.     public function createTransaction($dados)
  421.     {
  422.         $acesso = $this->getCredentials();
  423.         $data = http_build_query($dados);
  424.  
  425.         $curl = curl_init();
  426.  
  427.         $headers = array('Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1');
  428.  
  429.         //$url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions';
  430.         $url = $acesso->transaction;
  431.  
  432.         curl_setopt($curl, CURLOPT_URL, $url);
  433.         curl_setopt($curl, CURLOPT_POST, true);
  434.         curl_setopt( $curl,CURLOPT_HTTPHEADER, $headers );
  435.         curl_setopt( $curl,CURLOPT_RETURNTRANSFER, true );
  436.         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  437.         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  438.         //curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  439.         curl_setopt($curl, CURLOPT_HEADER, false);
  440.         $xml = curl_exec($curl);
  441.  
  442.         $err = curl_error($curl);
  443.  
  444.         curl_close($curl);
  445.  
  446.         if ($err) {
  447.             return false;
  448.         } else {
  449.             if($xml == "Unauthorized"):
  450.                 return "Unauthorized";
  451.             else:
  452.                 $xml= simplexml_load_string($xml);             
  453.                 return $xml;
  454.             endif;
  455.         }
  456.     }
  457.  
  458.     public function processNotification($notificationCode = null)
  459.     {
  460.         header("access-control-allow-origin: https://sandbox.pagseguro.uol.com.br");
  461.         $acesso = $this->getCredentials();
  462.         /*if($acesso->type == "sandbox"){
  463.             header("access-control-allow-origin: https://sandbox.pagseguro.uol.com.br");
  464.         }else{
  465.             header("access-control-allow-origin: https://pagseguro.uol.com.br");
  466.         }*/
  467.  
  468.         if($notificationCode == null){
  469.             return false; // c0VgKQpcc_s
  470.         }else{
  471.             $credentials = array(
  472.                 "notificationType" => "transaction",
  473.                 "token" => $acesso->token,
  474.                 "email" => $acesso->usuario,
  475.             );
  476.             // token=77DBB23D06434213A8E9A57C8D30C2C4&email=pagseguro%40clubedetiroliberdade.com.br¬ificationType=transaction
  477.             $data = http_build_query($credentials);
  478.             $headers = array('Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1');
  479.  
  480.             $url = $acesso->notification.$notificationCode.'?'.$data;
  481.            
  482.             $curl = curl_init();
  483.             curl_setopt( $curl , CURLOPT_FOLLOWLOCATION , true );
  484.             curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true );
  485.             curl_setopt( $curl , CURLOPT_HTTPHEADER , $headers );
  486.             curl_setopt( $curl , CURLOPT_URL, $url );      
  487.  
  488.             $xml = curl_exec($curl);
  489.  
  490.             $err = curl_error($curl);
  491.  
  492.             curl_close($curl);
  493.  
  494.             if ($err) {
  495.                 return $err;
  496.             } else {
  497.                 if($xml == "Unauthorized"):
  498.                     throw new Exception("Não autorizado", 1);
  499.                 else:
  500.                     header('Content-Type: application/json');
  501.                     return simplexml_load_string($xml);
  502.                 endif;
  503.             }
  504.         }
  505.     }
  506.  
  507.     public function changeStatus($reference, $status)
  508.     {
  509.         $db = DB::table('anuidades')->where('token', $reference);
  510.         if(count($db->get()) > 0){
  511.             if(DB::table('anuidades')
  512.                 ->where('token', $reference)
  513.                 ->update([
  514.                     "updated_at" => date("Y-m-d H:i:s"),
  515.                     "status" => intval($status)
  516.                 ]) ) {
  517.                
  518.                 return true;
  519.  
  520.             }else{
  521.                 return false;
  522.             }
  523.         }else{
  524.             echo "Não existe";
  525.         }
  526.     }
  527.  
  528.     public function consultar($reference = null)
  529.     {
  530.         if($reference != null):
  531.             $acesso = $this->getCredentials();
  532.  
  533.             $credentials =  array(
  534.                 "email" => $acesso->usuario,
  535.                 "token" => $acesso->token,
  536.                 "reference" => $reference
  537.             );
  538.             $data = http_build_query($credentials);
  539.  
  540.             $url = $acesso->transaction."?".$data;
  541.             $headers = array('Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1');
  542.             $curl = curl_init();
  543.             curl_setopt( $curl , CURLOPT_FOLLOWLOCATION , true );
  544.             curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true );
  545.             curl_setopt( $curl , CURLOPT_HTTPHEADER , $headers );
  546.             curl_setopt( $curl , CURLOPT_URL, $url );      
  547.  
  548.             $xml = curl_exec($curl);
  549.  
  550.             $err = curl_error($curl);
  551.  
  552.             curl_close($curl);
  553.  
  554.             if ($err) {
  555.                 return $err;
  556.             } else {
  557.                 if($xml == "Unauthorized"):
  558.                     throw new Exception("Não autorizado", 1);
  559.                 else:
  560.                     header('Content-Type: application/json');
  561.                     return simplexml_load_string($xml);
  562.                 endif;
  563.             }
  564.  
  565.         endif;
  566.     }
  567.  
  568.     public function pegaLinkBoleto($reference = null)
  569.     {
  570.         if($reference != null):
  571.  
  572.             $consultar = $this->consultar($reference);
  573.  
  574.             if($consultar){
  575.  
  576.                 if($consultar->transactions->transaction->paymentMethod->type == 2){
  577.  
  578.                     $acesso = $this->getCredentials();
  579.  
  580.                     $credentials =  array(
  581.                         "email" => $acesso->usuario,
  582.                         "token" => $acesso->token,
  583.                     );
  584.                     $data = http_build_query($credentials);
  585.  
  586.                     $url = $acesso->transaction."/".$consultar->transactions->transaction->code."?".$data;
  587.                     $headers = array('Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1');
  588.                     $curl = curl_init();
  589.                     curl_setopt( $curl , CURLOPT_FOLLOWLOCATION , true );
  590.                     curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true );
  591.                     curl_setopt( $curl , CURLOPT_HTTPHEADER , $headers );
  592.                     curl_setopt( $curl , CURLOPT_URL, $url );      
  593.  
  594.                     $xml = curl_exec($curl);
  595.  
  596.                     $err = curl_error($curl);
  597.  
  598.                     curl_close($curl);
  599.  
  600.                     if ($err) {
  601.                         return $err;
  602.                     } else {
  603.                         if($xml == "Unauthorized"):
  604.                             throw new Exception("Não autorizado", 1);
  605.                         else:
  606.                             header('Content-Type: application/json');
  607.                             return simplexml_load_string($xml);
  608.                         endif;
  609.                     }
  610.  
  611.                     return $consultar->transactions->transaction->code[0];
  612.  
  613.                 }
  614.             }
  615.         endif;
  616.     }
  617.  
  618. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement