Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function retorno_pagamento(){
- $raw_post_data = file_get_contents('php://input');
- //file_put_contents(FCPATH . 'pagamento.txt', $raw_post_data, FILE_APPEND);
- $raw_post_response = 'cmd=_notify-validate&' . $raw_post_data;
- if(!empty($raw_post_data)) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $raw_post_response);
- curl_setopt($ch, CURLOPT_SSLVERSION, 6);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- $response = curl_exec($ch);
- curl_close($ch);
- }
- //file_put_contents(FCPATH . 'pagamento.txt', $response, FILE_APPEND);
- if ($response == "VERIFIED" && $_POST['receiver_email'] == "XXXX") {
- if ($_POST['payment_status'] == "Completed") {
- $code = $_POST['txn_id'];
- $status = '3';
- $valor = $_POST['mc_gross'];
- $clienteNome = $_POST['first_name'] . " " . $_POST['last_name'];
- $clienteEmail = $_POST['payer_email'];
- $clientePhone = '';
- $pagamentoTipo = '1';
- $itemID = $_POST['item_number'];
- $pedidos = $this->vendas->getAll(array(
- 'vendaTransacaoID' => $code
- ));
- if ($pedidos->num_rows() == 0) {
- $id = self::_gravaRetorno($code, $itemID, $clienteNome, $clienteEmail, $clientePhone, $pagamentoTipo);
- self::_atualizaStatus($id, $status);
- }
- }
- if($_POST['payment_status'] == "Denied") {
- $code = $_POST['txn_id'];
- $status = '7';
- $valor = $_POST['mc_gross'];
- $clienteNome = $_POST['first_name'] . " " . $_POST['last_name'];
- $clienteEmail = $_POST['payer_email'];
- $clientePhone = '';
- $pagamentoTipo = '1';
- $itemID = $_POST['item_number'];
- $pedidos = $this->vendas->getAll(array(
- 'vendaTransacaoID' => $code
- ));
- $id = self::_gravaRetorno($code, $itemID, $clienteNome, $clienteEmail, $clientePhone, $pagamentoTipo);
- self::_atualizaStatus($id, $status);
- }
- } else {
- redirect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement