Last active
October 29, 2020 00:18
-
-
Save ggwebdev/b2dec8bbd5635043d675 to your computer and use it in GitHub Desktop.
Simple listener INP Paypal using laravel 4.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class IpnListnerController extends \BaseController { | |
private $sandbox = true; | |
private $notify_email = true; | |
private $receiver_email = '[email protected]'; | |
protected function listener(){ | |
$endpoint = ($this->sandbox) ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; | |
$endpoint .= '/cgi-bin/webscr?cmd=_notify-validate'; | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $endpoint); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($_POST)); | |
$response = curl_exec($curl); | |
$error = curl_error($curl); | |
$errno = curl_errno($curl); | |
curl_close($curl); | |
if (empty($error) && $errno == 0) { | |
if ($response == 'VERIFIED') { | |
if (Input::get('receiver_email') == $this->receiver_email) { | |
// Update your database or whatever... | |
} | |
}else{ | |
// handle error... | |
} | |
} | |
if ($this->notify_email) { | |
Mail::send('emails.notify.paypal', array( 'data' => $data ), function($message) | |
{ | |
try { | |
$message->from('[email protected]', 'Notification Paypal'); | |
$message->to('[email protected]', 'Your Name')->subject('Notification Paypal'); | |
} catch (Exception $e) { | |
// Throws exception | |
} | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment