Skip to content

Instantly share code, notes, and snippets.

@ggwebdev
Last active October 29, 2020 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggwebdev/b2dec8bbd5635043d675 to your computer and use it in GitHub Desktop.
Save ggwebdev/b2dec8bbd5635043d675 to your computer and use it in GitHub Desktop.
Simple listener INP Paypal using laravel 4.2
<?php
class IpnListnerController extends \BaseController {
private $sandbox = true;
private $notify_email = true;
private $receiver_email = 'seller@paypalsandbox.com';
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('sender@yoursitedomain.com', 'Notification Paypal');
$message->to('your_email@yourdomain.com', '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