/** * Listens for and stores PayPal IPN requests. * * @throws InvalidIpnException * * @return IpnOrder */ public function getOrder() { $ipnMessage = null; $listenerBuilder = new ListenerBuilder(); if ($this->getEnvironment() == 'sandbox') { $listenerBuilder->useSandbox(); // use PayPal sandbox } $listener = $listenerBuilder->build(); $listener->onVerified(function (MessageVerifiedEvent $event) { $ipnMessage = $event->getMessage(); Log::info('IPN message verified - ' . $ipnMessage); $this->order = $this->store($ipnMessage); }); $listener->onInvalid(function (MessageInvalidEvent $event) { $report = $event->getMessage(); Log::warning('Paypal returned invalid for ' . $report); }); $listener->onVerificationFailure(function (MessageVerificationFailureEvent $event) { $error = $event->getError(); // Something bad happend when trying to communicate with PayPal! Log::error('Paypal verification error - ' . $error); }); $listener->listen(); return $this->order; }
<?php include __DIR__ . '/../../loader.php'; use Mdb\PayPal\Ipn\Event\MessageInvalidEvent; use Mdb\PayPal\Ipn\Event\MessageVerificationFailureEvent; use Mdb\PayPal\Ipn\Event\MessageVerifiedEvent; use Mdb\PayPal\Ipn\ListenerBuilder\Guzzle\InputStreamListenerBuilder as ListenerBuilder; $listenerBuilder = new ListenerBuilder(); if (config('paypal', 'sandbox.enabled')) { $listenerBuilder->useSandbox(); } $listener = $listenerBuilder->build(); $listener->onVerified(function (MessageVerifiedEvent $event) { $ipnMessage = $event->getMessage(); $error = false; $txn_id = $_POST['txn_id']; $payment_status = $_POST['payment_status']; $receiver_email = $_POST['receiver_email']; $mc_gross = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; // check that txn_id has not been previously processed $txn_res = app('capsule')->table('__cornexaac_paypal_history')->where('txn_id', $txn_id); if ($txn_res->exists()) { $error = true; } // check whether the payment_status is Completed if ($payment_status != "Completed") { $error = true; } // check that receiver_email is your PayPal email if ($receiver_email != app('paypal')->email()) {