Exemplo n.º 1
0
 /**
  * @return void
  * @throws \Exception
  */
 public function receiveAction()
 {
     #$_SERVER['REQUEST_METHOD'] = 'POST';
     #$_POST = (array)json_decode('{"mc_gross":"5.00","protection_eligibility":"Eligible","address_status":"unconfirmed","item_number1":"","payer_id":"JJX73SL2BPE5N","tax":"0.00","address_street":"ESpachstr. 1","payment_date":"02:31:58 Feb 19, 2014 PST","payment_status":"Completed","charset":"windows-1252","address_zip":"79111","mc_shipping":"0.00","mc_handling":"0.00","first_name":"Firstname","mc_fee":"0.45","address_country_code":"DE","address_name":"Firstname Lastname","notify_version":"3.7","custom":"f2ff2b33043f13db295fd621049710b2ba738f4c","payer_status":"unverified","business":"*****@*****.**","address_country":"Germany","num_cart_items":"1","mc_handling1":"0.00","address_city":"Freiburg","verify_sign":"AhgfD0syzV.maHmOZIBk-C.VWKzrAfXjOAMzKUJoaj54LK4.Y9d5aMjI","payer_email":"*****@*****.**","mc_shipping1":"0.00","tax1":"0.00","txn_id":"5WA532952T182543A","payment_type":"instant","last_name":"Lastname","address_state":"Empty","item_name1":"EFX - Uploader","receiver_email":"*****@*****.**","payment_fee":"","quantity1":"1","receiver_id":"94SC9AKRREUUY","txn_type":"cart","mc_gross_1":"5.00","mc_currency":"EUR","residence_country":"DE","test_ipn":"1","transaction_subject":"f2ff2b33043f13db295fd621049710b2ba738f4c","payment_gross":"","ipn_track_id":"5c737c81db99f"}');
     \Aijko\SharepointConnector\Utility\Logger::info('Paypal.Raw.Response', array($_POST));
     $this->timeIdentifier = date('YmdHis');
     $this->txnIdentifier = $_POST['txn_id'];
     $this->orderRepository = $this->objectManager->get('Aijko\\Paypal\\Domain\\Repository\\OrderRepository');
     $this->ipnListener = $this->objectManager->get('IpnListener');
     $this->persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
     if ($this->settings['context']['sandbox']) {
         $this->ipnListener->use_sandbox = TRUE;
     }
     try {
         $this->ipnListener->requirePostMethod();
         $verified = $this->ipnListener->processIpn($_POST);
         if ($verified) {
             // The processIpn() method returned true if the IPN was "VERIFIED" and false if it was "INVALID".
             #if (1) {
             if ('Completed' == $_POST['payment_status']) {
                 if (!$this->orderRepository->findOneByTxnid($this->txnIdentifier)) {
                     // Check that $_POST['txn_id'] has not been previously processed
                     if ($this->settings['seller']['email'] == $_POST['receiver_email']) {
                         // Check that $_POST['receiver_email'] is your Primary PayPal email
                         $order = $this->storeAndGetOrder();
                         $subject = 'IPN OK [' . $this->timeIdentifier . '_' . $this->txnIdentifier . ']';
                         $this->sendNotificationAndLog($subject, $subject);
                         $this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'StoreOrderAfter', array($order, $_POST));
                     } else {
                         throw new \Aijko\Paypal\Exception('receiver_email is not equals ' . $this->settings['seller']['email'] . ' [' . $this->timeIdentifier . '_' . $this->txnIdentifier . ']', 1392387854);
                     }
                 } else {
                     throw new \Aijko\Paypal\Exception('IPN txn_id has been previously processed [' . $this->timeIdentifier . '_' . $this->txnIdentifier . ']', 1392387855);
                 }
             } else {
                 throw new \Aijko\Paypal\Exception('IPN payment_status is not completed [' . $this->timeIdentifier . '_' . $this->txnIdentifier . ']', 1392387856);
             }
         } else {
             $content = 'An Invalid IPN *may* be caused by a fraudulent transaction attempt. Its a good idea to have a developer or sys admin manually investigate any invalid IPN.';
             throw new \Aijko\Paypal\Exception('Invalid IPN [' . $this->timeIdentifier . '_' . $this->txnIdentifier . ']', 1392387857);
         }
     } catch (\Aijko\Paypal\Exception $e) {
         if (!$content) {
             $content = $e->getMessage();
         }
         $this->sendNotificationAndLog($e->getMessage(), $content, 'error');
         die($e->getMessage());
     } catch (\Exception $e) {
         $this->sendNotificationAndLog('IPN Exception [' . $this->timeIdentifier . '_' . $this->txnIdentifier . ']', $e->getMessage(), 'error');
         die($e->getMessage());
     }
     return '';
 }
Exemplo n.º 2
0
 public static function isValid()
 {
     $verified = 0;
     require 'ipnlistener.php';
     $listener = new IpnListener();
     $is_paypal_sandbox = Yii::app()->params['is_paypal_sandbox'];
     if ($is_paypal_sandbox) {
         $listener->use_sandbox = true;
     } else {
         $listener->use_sandbox = false;
     }
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         echo $e->getMessage();
         exit(0);
     }
     if ($verified) {
         $verified = 1;
         //            echo $listener->getTextReport();
     } else {
         $verified = 0;
         //            echo $listener->getTextReport();
     }
     return $verified;
 }
Exemplo n.º 3
0
 public function post_process()
 {
     Log::write('PayPal', 'Trying to process IPN');
     Bundle::start('paypal-ipn');
     $listener = new IpnListener();
     //        $listener->use_sandbox = true;
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         Log::info($e->getMessage());
     }
     if ($verified) {
         Log::write('PayPal', 'IPN payment looks verified');
         $data = Input::get();
         $settings = IniHandle::readini();
         if (!in_array($data['payment_status'], array('Completed', 'COMPLETED', 'completed'))) {
             Log::write('PayPal', 'payment not completed');
             return View::make('msg.error')->with('error', 'PayPal: payment not completed');
         }
         if (strtolower($data['receiver_email']) != strtolower($settings['ppemail'])) {
             Log::write('PayPal', 'receive email not same as set in settings. Settings: ' . $settings['ppemail'] . ' ||| PayPal email: ' . $data['receiver_email']);
             return View::make('msg.error')->with('error', 'PayPal: receive email not same as set in settings');
         }
         if (Payment::where('transaction_id', '=', $data['txn_id'])->count() != 0) {
             Log::write('PayPal', 'transaction ID already exists');
             return View::make('msg.error')->with('error', 'PayPal: transaction ID already exists');
         }
         if (strtolower($data['mc_currency']) != strtolower($settings['ppcurrency'])) {
             Log::write('PayPal', 'Currencies do not match');
             return View::make('msg.error')->with('error', 'PayPal: currencies do not match');
         }
         Log::write('PayPal', 'Got past all PLAN controller checks now going into CUSTOM');
         if (strtolower($data['custom']) == 'plan') {
             $result = Payment::verifyPlan($data);
             if (!$result) {
                 return $result;
             }
         } elseif (strtolower($data['custom']) == 'blacklist_skype' || strtolower($data['custom']) == 'blacklist_ip') {
             $result = Payment::verifyBlacklist($data);
             if (!$result) {
                 return $result;
             }
         } else {
             Log::write('PayPal', 'Custom not found, can\'t verify anything');
             return View::make('msg.error')->with('error', 'Fraudulent payment?');
         }
         Log::write('PayPal', 'Now trying to add Payment info to DB');
         $payment = Payment::create(array('user_id' => $data['option_selection1'], 'token' => $data['ipn_track_id'], 'date' => date('Y-m-d H:i:s', time()), 'ack' => $data['payment_status'], 'transaction_id' => $data['txn_id'], 'amount' => $data['mc_gross'], 'paypal_fee' => $data['mc_fee'], 'status' => $data['payment_status'], 'description' => $data['custom']));
         Log::write('PayPal', 'Successful payment, DB id: ' . $payment->id);
     } else {
         Log::write('PayPal', 'IPN listener returns false on check');
     }
     return 'handled';
 }
function inc_ipnlistener_recuperer_post_https($datas = '')
{
    /**
     *  PHP-PayPal-IPN Example
     *
     *  This shows a basic example of how to use the IpnListener() PHP class to
     *  implement a PayPal Instant Payment Notification (IPN) listener script.
     *
     *  For a more in depth tutorial, see my blog post:
     *  http://www.micahcarrick.com/paypal-ipn-with-php.html
     *
     *  This code is available at github:
     *  https://github.com/Quixotix/PHP-PayPal-IPN
     *
     *  @package    PHP-PayPal-IPN
     *  @author     Micah Carrick
     *  @copyright  (c) 2011 - Micah Carrick
     *  @license    http://opensource.org/licenses/gpl-3.0.html
     */
    // instantiate the IpnListener class
    include_spip('lib/ipnlistener');
    $erreur = false;
    $listener = new IpnListener();
    /*
    When you are testing your IPN script you should be using a PayPal "Sandbox"
    account: https://developer.paypal.com
    When you are ready to go live change use_sandbox to false.
    */
    $listener->use_sandbox = false;
    try {
        $listener->requirePostMethod();
        $verified = $listener->processIpn($datas);
    } catch (Exception $e) {
        $erreur = true;
        $erreur_msg = $e->getMessage();
        spip_log("erreur exception " . $erreur_message, "paypal");
    }
    spip_log("valeur verifie " . $verified, "paypal");
    if ($verified) {
        $response = 'VERIFIED';
    } else {
        $response = 'INVALID';
    }
    return array($response, $erreur, $erreur ? $erreur_msg : '');
}
Exemplo n.º 5
0
 function makelog()
 {
     $listener = new IpnListener();
     // tell the IPN listener to use the PayPal test sandbox
     $listener->use_sandbox = true;
     // try to process the IPN POST
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         error_log($e->getMessage());
         exit(0);
     }
     if ($verified) {
         $this->log($listener->getTextReport());
         mail('*****@*****.**', 'Valid IPN', $listener->getTextReport());
         return $listener->getTextReport();
     } else {
         return $listener->getTextReport();
     }
 }
Exemplo n.º 6
0
 function subtest()
 {
     require_once "application/libraries/ipnlistener.php";
     $listener = new IpnListener();
     file_put_contents('text.txt', $_POST['custom'] . ' - subtest - = ' . json_encode($_POST) . "\r\n---\r\n" . json_encode($_GET) . "\r\n-----------\r\n", FILE_APPEND);
     //$_POST = $_REQUEST = json_decode('{"amount1":"0.00","amount3":"9.99","address_status":"confirmed","subscr_date":"10:17:00 Jun 05, 2015 PDT","payer_id":"MJG88EHUTHY5L","address_street":"5003 Ritchie Highway","mc_amount1":"0.00","mc_amount3":"9.99","charset":"windows-1252","address_zip":"21225","first_name":"Ajay","reattempt":"1","address_country_code":"US","address_name":"Ajay Khanna","notify_version":"3.8","subscr_id":"I-XGM0L72MHP9T","custom":"30","payer_status":"verified","business":"*****@*****.**","address_country":"United States","address_city":"Brooklyn","verify_sign":"A2UvLyyTiDSSYReNtyr0qyDet6JRAqXVObnLGzMd3VldD5dfiZbg4cnr","payer_email":"*****@*****.**","btn_id":"96274524","last_name":"Khanna","address_state":"MD","receiver_email":"*****@*****.**","recurring":"1","txn_type":"subscr_signup","item_name":"FREE Trial for 90 Days Then $9.99 a month","mc_currency":"USD","item_number":"Free90Monthly","residence_country":"US","period1":"3 M","period3":"1 M","ipn_track_id":"90f4f2bdc1315"}', true);
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         error_log($e->getMessage());
         // //echo $e->getMessage();
         exit(0);
     }
     //echo $listener->getResponse();
     //var_dump($verified);
     // echo $_POST['custom']." = ". $_POST['subscr_id']." ".$type;
     if ($verified) {
         //file_put_contents('text.txt', "Verified\r\n====\r\n", FILE_APPEND);
         if ($_POST['txn_type'] == 'subscr_signup') {
             if (@$_POST['amount3'] == '99.99') {
                 $type = 1;
             } else {
                 $type = 2;
             }
             $this->userM->subscribe($_POST['custom'], $_POST['subscr_id'], $type);
         }
         if ($_POST['txn_type'] == 'subscr_cancel') {
             $this->userM->unsubscribe($_POST['subscr_id']);
         }
     }
     /*
     else
         file_put_contents('text.txt', "Failed\r\n====\r\n", FILE_APPEND);
     */
 }
 /**
  * Process PayPal IPN
  *
  * @since 2.1
  */
 public function process_webhooks()
 {
     if (!isset($_GET['listener']) || strtoupper($_GET['listener']) != 'IPN') {
         return;
     }
     global $rcp_options;
     nocache_headers();
     if (!class_exists('IpnListener')) {
         // instantiate the IpnListener class
         include RCP_PLUGIN_DIR . 'includes/gateways/paypal/paypal-ipnlistener.php';
     }
     $listener = new IpnListener();
     $verified = false;
     if ($this->test_mode) {
         $listener->use_sandbox = true;
     }
     /*
     if( isset( $rcp_options['ssl'] ) ) {
     	$listener->use_ssl = true;
     } else {
     	$listener->use_ssl = false;
     }
     */
     //To post using the fsockopen() function rather than cURL, use:
     if (isset($rcp_options['disable_curl'])) {
         $listener->use_curl = false;
     }
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         status_header(402);
         //die( 'IPN exception: ' . $e->getMessage() );
     }
     /*
     The processIpn() method returned true if the IPN was "VERIFIED" and false if it
     was "INVALID".
     */
     if ($verified || isset($_POST['verification_override']) || ($this->test_mode || isset($rcp_options['disable_ipn_verify']))) {
         status_header(200);
         $user_id = 0;
         $posted = apply_filters('rcp_ipn_post', $_POST);
         // allow $_POST to be modified
         if (!empty($posted['custom']) && is_numeric($posted['custom'])) {
             $user_id = absint($posted['custom']);
         } else {
             if (!empty($posted['subscr_id'])) {
                 $user_id = rcp_get_member_id_from_profile_id($posted['subscr_id']);
             } else {
                 if (!empty($posted['payer_email'])) {
                     $user = get_user_by('email', $posted['payer_email']);
                     $user_id = $user ? $user->ID : false;
                 }
             }
         }
         $member = new RCP_Member($user_id);
         if (!$member || !$member->get_subscription_id()) {
             die('no member found');
         }
         if (!rcp_get_subscription_details($member->get_subscription_id())) {
             die('no subscription level found');
         }
         $subscription_name = $posted['item_name'];
         $subscription_key = $posted['item_number'];
         $amount = number_format((double) $posted['mc_gross'], 2);
         $amount2 = number_format((double) $posted['mc_amount3'], 2);
         $payment_status = $posted['payment_status'];
         $currency_code = $posted['mc_currency'];
         $subscription_price = number_format((double) rcp_get_subscription_price($member->get_subscription_id()), 2);
         // setup the payment info in an array for storage
         $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'], current_time('timestamp'))), 'subscription' => $posted['item_name'], 'payment_type' => $posted['txn_type'], 'subscription_key' => $subscription_key, 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']);
         do_action('rcp_valid_ipn', $payment_data, $user_id, $posted);
         if ($posted['txn_type'] == 'web_accept' || $posted['txn_type'] == 'subscr_payment') {
             // only check for an existing payment if this is a payment IPD request
             if (rcp_check_for_existing_payment($posted['txn_type'], $posted['payment_date'], $subscription_key)) {
                 $log_data = array('post_title' => __('Duplicate Payment', 'rcp'), 'post_content' => __('A duplicate payment was detected. The new payment was still recorded, so you may want to check into both payments.', 'rcp'), 'post_parent' => 0, 'log_type' => 'gateway_error');
                 $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
                 $log_entry = WP_Logging::insert_log($log_data, $log_meta);
                 die('duplicate IPN detected');
             }
             if (strtolower($currency_code) != strtolower($rcp_options['currency'])) {
                 // the currency code is invalid
                 $log_data = array('post_title' => __('Invalid Currency Code', 'rcp'), 'post_content' => sprintf(__('The currency code in an IPN request did not match the site currency code. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error');
                 $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
                 $log_entry = WP_Logging::insert_log($log_data, $log_meta);
                 die('invalid currency code');
             }
         }
         if (isset($rcp_options['email_ipn_reports'])) {
             wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport());
         }
         /* now process the kind of subscription/payment */
         $rcp_payments = new RCP_Payments();
         // Subscriptions
         switch ($posted['txn_type']) {
             case "subscr_signup":
                 // when a new user signs up
                 // store the recurring payment ID
                 update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                 $member->set_payment_profile_id($posted['subscr_id']);
                 do_action('rcp_ipn_subscr_signup', $user_id);
                 die('successful subscr_signup');
                 break;
             case "subscr_payment":
                 // when a user makes a recurring payment
                 update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                 $member->set_payment_profile_id($posted['subscr_id']);
                 $member->renew(true);
                 // record this payment in the database
                 $rcp_payments->insert($payment_data);
                 do_action('rcp_ipn_subscr_payment', $user_id);
                 die('successful subscr_payment');
                 break;
             case "subscr_cancel":
                 // user is marked as cancelled but retains access until end of term
                 $member->set_status('cancelled');
                 // set the use to no longer be recurring
                 delete_user_meta($user_id, 'rcp_paypal_subscriber');
                 do_action('rcp_ipn_subscr_cancel', $user_id);
                 die('successful subscr_cancel');
                 break;
             case "subscr_failed":
                 do_action('rcp_ipn_subscr_failed');
                 die('successful subscr_failed');
                 break;
             case "subscr_eot":
                 // user's subscription has reached the end of its term
                 if ('cancelled' !== $member->get_status($user_id)) {
                     $member->set_status('expired');
                 }
                 do_action('rcp_ipn_subscr_eot', $user_id);
                 die('successful subscr_eot');
                 break;
             case "web_accept":
                 switch (strtolower($payment_status)) {
                     case 'completed':
                         // set this user to active
                         $member->renew();
                         $rcp_payments->insert($payment_data);
                         break;
                     case 'denied':
                     case 'expired':
                     case 'failed':
                     case 'voided':
                         $member->set_status('cancelled');
                         break;
                 }
                 die('successful web_accept');
                 break;
             case "cart":
             case "express_checkout":
             default:
                 break;
         }
     } else {
         if (isset($rcp_options['email_ipn_reports'])) {
             // an invalid IPN attempt was made. Send an email to the admin account to investigate
             wp_mail(get_bloginfo('admin_email'), __('Invalid IPN', 'rcp'), $listener->getTextReport());
         }
         status_header(400);
         die('invalid IPN');
     }
 }
Exemplo n.º 8
0
 /**
  * Check Paypal notification
  */
 protected function checkNotificationPaypal()
 {
     // load JInput
     $jinput = JFactory::getApplication()->input;
     // check ipn vars
     $payment_status = $jinput->post->get('payment_status');
     if (!$payment_status) {
         return [0, false];
     }
     // require helper
     require_once JPATH_COMPONENT . '/vendor/PHP-PayPal-IPN/ipnlistener.php';
     $listener = new IpnListener();
     // process IPN
     try {
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         CHLib::log(json_encode(['CHClientModelNotify::checkNotificationPaypal - processIpn Exception', CHLib::input()->get->getArray(), CHLib::input()->post->getArray(), $e], JSON_PRETTY_PRINT), 'warning', 'com_chclient');
         return [0, false];
     }
     if (!$verified) {
         CHLib::log(json_encode(['CHClientModelNotify::checkNotificationPaypal - processIpn not verified', CHLib::input()->get->getArray(), CHLib::input()->post->getArray()], JSON_PRETTY_PRINT), 'warning', 'com_chclient');
         return [0, false];
     }
     // check status
     if ($payment_status != 'Completed') {
         CHLib::log(json_encode(['CHClientModelNotify::checkNotificationPaypal - payment_status not Completed', CHLib::input()->get->getArray(), CHLib::input()->post->getArray()], JSON_PRETTY_PRINT), 'warning', 'com_chclient');
         return [0, false];
     }
     // retrieve custom field
     $custom = explode(';', $jinput->post->get('custom', '', 'post'));
     if (count($custom) != 2) {
         CHLib::log(json_encode(['CHClientModelNotify::checkNotificationPaypal - custom field invalid', CHLib::input()->get->getArray(), CHLib::input()->post->getArray()], JSON_PRETTY_PRINT), 'warning', 'com_chclient');
         return [0, false];
     }
     // check sign
     $booking_id = (int) $custom[0];
     $notification_sign = $custom[1];
     $sign = hash('sha256', $this->config->data_source_app_secret . $this->config->confirm_paypal_business . $booking_id);
     if ($sign != $notification_sign) {
         CHLib::log(json_encode(['CHClientModelNotify::checkNotificationPaypal - sign does not match', CHLib::input()->get->getArray(), CHLib::input()->post->getArray()], JSON_PRETTY_PRINT), 'warning', 'com_chclient');
         return [0, false];
     }
     // return notification object
     return [$booking_id, CHLib::input()->post->getArray()];
 }
Exemplo n.º 9
0
 function checkAndvalidateIPN()
 {
     if ($this->booLogEvents) {
         ini_set('log_errors', true);
         ini_set('error_log', $this->strLogfile);
     }
     include 'PHP-PayPal-IPN/ipnlistener.php';
     $listener = new IpnListener();
     $listener->use_sandbox = PAYPAL_SANDBOX;
     $listener->use_ssl = true;
     $listener->use_curl = false;
     if (function_exists('curl_init')) {
         $listener->use_curl = true;
     }
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         error_log($e->getMessage());
         exit(0);
     }
     if ($this->booLogEvents) {
         error_log($listener->getTextReport());
     }
     if ($verified) {
         if ($_POST['payment_status'] != 'Completed') {
             if ($this->booLogEvents) {
                 error_log('FAIL - payment_status is not Completed');
             }
             return false;
         }
         if ($_POST['receiver_email'] != $this->strPaypalAccount) {
             if ($this->booLogEvents) {
                 error_log('FAIL - receiver_email is: ' . $_POST['receiver_email'] . ' expected: ' . $this->strPaypalAccount);
             }
             return false;
         }
         if ($_POST['mc_currency'] != PAYPAL_CURRENCY) {
             if ($this->booLogEvents) {
                 error_log('FAIL - currency is: ' . $_POST['mc_currency'] . ' expected: ' . PAYPAL_CURRENCY);
             }
             return false;
         }
         // process payment
         $objPayment = new GSALES2_OBJECT_PAYMENT();
         $objPayment->setPaymentProvider('paypal');
         $objPayment->setAmount($_POST['mc_gross']);
         $objPayment->setInvoiceId($_POST['custom']);
         $objPayment->setTransactionId($_POST['txn_id']);
         if ($this->booLogEvents) {
             error_log('Payment object:' . print_r($objPayment, true));
         }
         // set invoice to paid
         return $objPayment->checkPaidAmountAndSetInvoiceAsPaid();
     } else {
         if ($this->booLogEvents) {
             error_log('!!! Invalid IPN !!! ');
         }
     }
 }
Exemplo n.º 10
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     $siteId = $request['custom'];
     // get reference to site
     $site = Site::GetBySiteId($siteId);
     $use_sandbox = false;
     // set whether to use a sandbox
     if ($site['PayPalUseSandbox'] == '1') {
         $use_sandbox = true;
     }
     $listener = new IpnListener();
     $listener->use_curl = false;
     $listener->use_sandbox = $use_sandbox;
     $listener->use_ssl = true;
     try {
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         // fatal error trying to process IPN.
         exit(0);
     }
     // IPN response was "VERIFIED"
     if ($verified) {
         $processor = 'PayPal';
         if ($use_sandbox == true) {
             $processor .= ' (sandbox)';
         }
         $processorTransactionId = $request['txn_id'];
         $processorStatus = $request['payment_status'];
         $email = $request['payer_email'];
         $payerId = $request['payer_id'];
         $name = $request['first_name'] . ' ' . $request['last_name'];
         $shipping = $request['mc_handling'];
         $fee = $request['mc_fee'];
         $tax = $request['tax'];
         $total = $request['mc_gross'];
         $currency = $request['mc_currency'];
         $num_items = 1000;
         if (isset($request['num_cart_items'])) {
             $num_items = $request['num_cart_items'];
         }
         $items = array();
         // line-items (for receipt)
         $line_items = '';
         // set static URL
         $staticUrl = $site['Domain'];
         if (FILES_ON_S3 == true) {
             $bucket = $site['Bucket'];
             $staticUrl = str_replace('{{bucket}}', $bucket, S3_URL);
             $staticUrl = str_replace('{{site}}', $site['FriendlyId'], $staticUrl);
         }
         // get items
         for ($x = 1; $x <= $num_items; $x++) {
             if (isset($request['item_number' . $x])) {
                 $item_number = $request['item_number' . $x];
                 $item_name = $request['item_name' . $x];
                 $item_number = iconv("ISO-8859-1", "UTF-8", $item_number);
                 $item_name = iconv("ISO-8859-1", "UTF-8", $item_name);
                 $item_quantity = $request['quantity' . $x];
                 $item_total = $request['mc_gross_' . $x];
                 $item_price = floatval($item_total) / intval($item_quantity);
                 $item = array('ProductId' => $item_number, 'Name' => $item_name, 'Quantity' => $item_quantity, 'Price' => $item_price, 'Total' => $item_total);
                 // get product
                 $product = Product::GetByProductId($item_number);
                 // get download link
                 $download_link = '';
                 // check if there is a downloaded file for the product
                 if ($product['Download'] != '' && $product['Download'] != NULL) {
                     $download_link = '<br><a href="' . API_URL . '/transaction/download/{{transactionId}}/' . $item_number . '">Download</a>';
                 }
                 // setup currency for line items
                 $item_total = $item_total . ' ' . $currency;
                 $item_price = $item_price . ' ' . $currency;
                 // add $ for total and price
                 if ($currency == 'USD') {
                     $item_total = '$' . $item_total;
                     $item_price = '$' . $item_price;
                 }
                 $line_items .= '<tr style="border-bottom: 1px solid #f0f0f0;"><td>' . $item_name . '<br><small>' . $item_number . '</small>' . $download_link . '</td><td align="right">' . $item_price . '</td><td align="right">' . $item_quantity . '</td><td align="right">' . $item_total . '</td></tr>';
                 array_push($items, $item);
             }
         }
         $items_json = json_encode($items);
         $data_json = json_encode($_POST);
         // create receipt
         $receipt = $line_items;
         // add a transaction
         $transaction = Transaction::Add($site['SiteId'], $processor, $processorTransactionId, $processorStatus, $email, $payerId, $name, $shipping, $fee, $tax, $total, $currency, $items_json, $data_json, $receipt);
         // replace {{transactionId}} in line_items
         $line_items = str_replace('{{transactionId}}', $transaction['TransactionId'], $line_items);
         $site_logo = '';
         if ($site['LogoUrl'] != '' && $site['LogoUrl'] != NULL) {
             $site_logo = '<img src="' . $staticUrl . '/files/' . $site['LogoUrl'] . '" style="max-height:50px">';
         }
         // setup currency for line items
         $shipping = $shipping . ' ' . $currency;
         $tax = $tax . ' ' . $currency;
         $total = $total . ' ' . $currency;
         // add $ for total and price
         if ($currency == 'USD') {
             $shipping = '$' . $shipping;
             $tax = '$' . $tax;
             $total = '$' . $total;
         }
         // send email
         $replace = array('{{site}}' => $site['Name'], '{{site-logo}}' => $site_logo, '{{reply-to}}' => $site['PrimaryEmail'], '{{line-items}}' => $line_items, '{{shipping}}' => $shipping, '{{tax}}' => $tax, '{{total}}' => $total);
         $subject = '[' . $site['Name'] . '] Receipt for your purchase from ' . $site['Name'] . ' (Transaction: ' . strtoupper($transaction['TransactionId']) . ') (Triangulate)';
         $file = SITES_LOCATION . '/' . $site['FriendlyId'] . '/emails/receipt.html';
         // send email
         $content = $site['ReceiptEmail'];
         // walk through and replace values in associative array
         foreach ($replace as $key => &$value) {
             $content = str_replace($key, $value, $content);
             $subject = str_replace($key, $value, $subject);
         }
         // send site email
         Utilities::SendSiteEmail($site, $email, $site['PrimaryEmail'], $site['Name'], $subject, $content);
     } else {
         // IPN response was "INVALID"\
     }
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'text/HTML';
     $response->body = 'Yah!!!';
     return $response;
 }
Exemplo n.º 11
0
 /**
  * Method used to handle notification from paypal server
  *
  * @return void
  * @since 1.0
  * @author Antonio La Rocca <*****@*****.**>
  */
 public function handle_notification()
 {
     if (empty($_GET['paypal_ipn_response'])) {
         return;
     }
     // include required libraries
     require dirname(dirname(__FILE__)) . '/third-party/IPNListener/ipnlistener.php';
     // retrieve saved options from panel
     $stored_options = $this->get_gateway_options();
     $listener = new IpnListener();
     $listener->use_sandbox = !($stored_options['sandbox'] == 'no');
     try {
         // process IPN request, require validation to PayPal server
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         // fatal error trying to process IPN.
         die;
     }
     // if PayPal says IPN is valid, process content
     if ($verified) {
         $request_data = $_POST;
         if (!isset($request_data['payment_status'])) {
             die;
         }
         // format payment data
         $payment_data = array();
         for ($i = 1; array_key_exists('status_' . $i, $request_data); $i++) {
             $data_index = array_keys($request_data);
             foreach ($data_index as $index) {
                 if (strpos($index, '_' . $i) !== false) {
                     $payment_data[$i][str_replace('_' . $i, '', $index)] = $request_data[$index];
                     unset($request_data[$index]);
                 }
             }
         }
         $request_data['payment_data'] = $payment_data;
         if (!empty($payment_data)) {
             foreach ($payment_data as $payment) {
                 if (!isset($payment['unique_id'])) {
                     continue;
                 }
                 $args = array();
                 $args['unique_id'] = $payment['unique_id'];
                 $args['gross'] = $payment['mc_gross'];
                 $args['status'] = $payment['status'];
                 $args['receiver_email'] = $payment['receiver_email'];
                 $args['currency'] = $payment['mc_currency'];
                 $args['txn_id'] = $payment['masspay_txn_id'];
                 // call action to update request status
                 do_action('yith_vendors_gateway_notification', $args);
             }
         }
     }
     die;
 }
Exemplo n.º 12
0
function rcp_check_ipn()
{
    global $rcp_options;
    if (!class_exists('IpnListener')) {
        // instantiate the IpnListener class
        include RCP_PLUGIN_DIR . 'includes/gateways/paypal/ipnlistener.php';
    }
    $listener = new IpnListener();
    if (isset($rcp_options['sandbox'])) {
        $listener->use_sandbox = true;
    }
    if (isset($rcp_options['ssl'])) {
        $listener->use_ssl = true;
    } else {
        $listener->use_ssl = false;
    }
    //To post using the fsockopen() function rather than cURL, use:
    if (isset($rcp_options['disable_curl'])) {
        $listener->use_curl = false;
    }
    try {
        $listener->requirePostMethod();
        $verified = $listener->processIpn();
    } catch (Exception $e) {
        //exit(0);
    }
    /*
    The processIpn() method returned true if the IPN was "VERIFIED" and false if it
    was "INVALID".
    */
    if ($verified || isset($_POST['verification_override']) || (isset($rcp_options['sandbox']) || isset($rcp_options['disable_ipn_verify']))) {
        $posted = apply_filters('rcp_ipn_post', $_POST);
        // allow $_POST to be modified
        $user_id = $posted['custom'];
        $subscription_name = $posted['item_name'];
        $subscription_key = $posted['item_number'];
        $amount = number_format((double) $posted['mc_gross'], 2);
        $amount2 = number_format((double) $posted['mc_amount3'], 2);
        $payment_status = $posted['payment_status'];
        $currency_code = $posted['mc_currency'];
        $subscription_id = rcp_get_subscription_id($user_id);
        $subscription_price = number_format((double) rcp_get_subscription_price(rcp_get_subscription_id($user_id)), 2);
        $user_data = get_userdata($user_id);
        if (!$user_data || !$subscription_id) {
            return;
        }
        if (!rcp_get_subscription_details($subscription_id)) {
            return;
        }
        // setup the payment info in an array for storage
        $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'])), 'subscription' => $posted['item_name'], 'payment_type' => $posted['txn_type'], 'subscription_key' => $subscription_key, 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']);
        do_action('rcp_valid_ipn', $payment_data, $user_id, $posted);
        if ($posted['txn_type'] == 'web_accept' || $posted['txn_type'] == 'subscr_payment') {
            // only check for an existing payment if this is a payment IPD request
            if (rcp_check_for_existing_payment($posted['txn_type'], $posted['payment_date'], $subscription_key)) {
                $log_data = array('post_title' => __('Duplicate Payment', 'rcp'), 'post_content' => __('A duplicate payment was detected. The new payment was still recorded, so you may want to check into both payments.', 'rcp'), 'post_parent' => 0, 'log_type' => 'gateway_error');
                $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
                $log_entry = WP_Logging::insert_log($log_data, $log_meta);
                return;
                // this IPN request has already been processed
            }
            /* do some quick checks to make sure all necessary data validates */
            if ($amount < $subscription_price && $amount2 < $subscription_price) {
                /*
                				// the subscription price doesn't match, so lets check to see if it matches with a discount code
                				if( ! rcp_check_paypal_return_price_after_discount( $subscription_price, $amount, $amount2, $user_id ) ) {
                	$log_data = array(
                					    'post_title'    => __( 'Price Mismatch', 'rcp' ),
                					    'post_content'  =>  sprintf( __( 'The price in an IPN request did not match the subscription price. Payment data: %s', 'rcp' ), json_encode( $payment_data ) ),
                					    'post_parent'   => 0,
                					    'log_type'      => 'gateway_error'
                					);
                	$log_meta = array(
                					    'user_subscription' => $posted['item_name'],
                					    'user_id'           => $user_id
                					);
                					$log_entry = WP_Logging::insert_log( $log_data, $log_meta );
                	//return;
                				}
                */
            }
            if (strtolower($currency_code) != strtolower($rcp_options['currency'])) {
                // the currency code is invalid
                $log_data = array('post_title' => __('Invalid Currency Code', 'rcp'), 'post_content' => sprintf(__('The currency code in an IPN request did not match the site currency code. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error');
                $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
                $log_entry = WP_Logging::insert_log($log_data, $log_meta);
                return;
            }
        }
        if (isset($rcp_options['email_ipn_reports'])) {
            wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport());
        }
        if (rcp_get_subscription_key($user_id) != $subscription_key) {
            // the subscription key is invalid
            $log_data = array('post_title' => __('Subscription Key Mismatch', 'rcp'), 'post_content' => sprintf(__('The subscription key in an IPN request did not match the subscription key recorded for the user. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error');
            $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
            $log_entry = WP_Logging::insert_log($log_data, $log_meta);
            return;
        }
        /* now process the kind of subscription/payment */
        $rcp_payments = new RCP_Payments();
        // Subscriptions
        switch ($posted['txn_type']) {
            case "subscr_signup":
                // when a new user signs up
                // store the recurring payment ID
                update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                // set the user's status to active
                rcp_set_status($user_id, 'active');
                if (!isset($rcp_options['disable_new_user_notices'])) {
                    wp_new_user_notification($user_id);
                }
                // send welcome email
                rcp_email_subscription_status($user_id, 'active');
                update_user_meta($user_id, 'rcp_recurring', 'yes');
                do_action('rcp_ipn_subscr_signup', $user_id);
                break;
            case "subscr_payment":
                // when a user makes a recurring payment
                // record this payment in the database
                $rcp_payments->insert($payment_data);
                $subscription = rcp_get_subscription_details(rcp_get_subscription_id($user_id));
                // update the user's expiration to correspond with the new payment
                $member_new_expiration = date('Y-m-d H:i:s', strtotime('+' . $subscription->duration . ' ' . $subscription->duration_unit . ' 23:59:59'));
                rcp_set_expiration_date($user_id, $member_new_expiration);
                update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                // make sure the user's status is active
                rcp_set_status($user_id, 'active');
                update_user_meta($user_id, 'rcp_recurring', 'yes');
                delete_user_meta($user_id, '_rcp_expired_email_sent');
                do_action('rcp_ipn_subscr_payment', $user_id);
                break;
            case "subscr_cancel":
                // user is marked as cancelled but retains access until end of term
                rcp_set_status($user_id, 'cancelled');
                // set the use to no longer be recurring
                delete_user_meta($user_id, 'rcp_recurring');
                delete_user_meta($user_id, 'rcp_paypal_subscriber');
                // send sub cancelled email
                rcp_email_subscription_status($user_id, 'cancelled');
                do_action('rcp_ipn_subscr_cancel', $user_id);
                break;
            case "subscr_failed":
                do_action('rcp_ipn_subscr_failed');
                break;
            case "subscr_eot":
                // user's subscription has reach the end of its term
                // set the use to no longer be recurring
                delete_user_meta($user_id, 'rcp_recurring');
                if ('cancelled' !== rcp_get_status($user_id)) {
                    rcp_set_status($user_id, 'expired');
                    // send expired email
                    rcp_email_subscription_status($user_id, 'expired');
                }
                do_action('rcp_ipn_subscr_eot', $user_id);
                break;
            case "cart":
                return;
                // get out of here
            // get out of here
            case "express_checkout":
                return;
                // get out of here
            // get out of here
            case "web_accept":
                switch (strtolower($payment_status)) {
                    case 'completed':
                        if (isset($_POST['verification_override'])) {
                            // this is a method for providing a new expiration if it doesn't exist
                            $subscription = rcp_get_subscription_details_by_name($payment_data['subscription']);
                            // update the user's expiration to correspond with the new payment
                            $member_new_expiration = date('Y-m-d H:i:s', strtotime('+' . $subscription->duration . ' ' . $subscription->duration_unit . ' 23:59:59'));
                            rcp_set_expiration_date($user_id, $member_new_expiration);
                        }
                        // set this user to active
                        rcp_set_status($user_id, 'active');
                        $rcp_payments->insert($payment_data);
                        rcp_email_subscription_status($user_id, 'active');
                        if (!isset($rcp_options['disable_new_user_notices'])) {
                            // send welcome email here
                            wp_new_user_notification($user_id);
                        }
                        delete_user_meta($user_id, '_rcp_expired_email_sent');
                        break;
                    case 'denied':
                    case 'expired':
                    case 'failed':
                    case 'voided':
                        rcp_set_status($user_id, 'cancelled');
                        // send cancelled email here
                        break;
                }
                break;
            default:
                break;
        }
    } else {
        if (isset($rcp_options['email_ipn_reports'])) {
            // an invalid IPN attempt was made. Send an email to the admin account to investigate
            wp_mail(get_bloginfo('admin_email'), __('Invalid IPN', 'rcp'), $listener->getTextReport());
        }
    }
}
Exemplo n.º 13
0
 /**
  * Validate IPN Message
  * PayPal provides a simple solution for notifying us when a payment has been processed;
  * they call it Instant Payment Notifications (IPN). In order to take advantage of IPN,
  * we create an IPN listener for our application (see https://github.com/Quixotix/PHP-PayPal-IPN).
  * See also https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/
  * @return boolean whether ipn was validates
  */
 public function validateIPN()
 {
     $listener = new IpnListener();
     $listener->use_sandbox = !$this->apiLive;
     if ($listener->processIpn()) {
         if (Yii::app()->request->getPost('receiver_email') != $this->receiverEmail) {
             $this->errorCode = self::ERROR_PROCESS_IPN;
             $this->errorMessage = 'PayPal recurring payment receiver email mismatch';
             return false;
         } else {
             return true;
         }
     } else {
         $this->errorCode = self::ERROR_VERIFY_IPN;
         $this->errorMessage = var_export($listener->getErrors(), true);
         return false;
     }
 }
Exemplo n.º 14
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     $siteUniqId = $request['custom'];
     // get reference to site
     $site = Site::GetBySiteUniqId($siteUniqId);
     $use_sandbox = false;
     // set whether to use a sandbox
     if ($site['PayPalUseSandbox'] == '1') {
         $use_sandbox = true;
     }
     $listener = new IpnListener();
     $listener->use_curl = false;
     $listener->use_sandbox = $use_sandbox;
     $listener->use_ssl = true;
     try {
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         // fatal error trying to process IPN.
         exit(0);
     }
     // IPN response was "VERIFIED"
     if ($verified) {
         $processor = 'PayPal';
         if ($use_sandbox == true) {
             $processor .= ' (sandbox)';
         }
         $processorTransactionId = $request['txn_id'];
         $processorStatus = $request['payment_status'];
         $email = $request['payer_email'];
         $payerId = $request['payer_id'];
         $name = $request['first_name'] . ' ' . $request['last_name'];
         $shipping = $request['mc_handling'];
         $fee = $request['mc_fee'];
         $tax = $request['tax'];
         $total = $request['mc_gross'];
         $currency = $request['mc_currency'];
         $num_items = 1000;
         if (isset($request['num_cart_items'])) {
             $num_items = $request['num_cart_items'];
         }
         $items = array();
         // line-items (for receipt)
         $line_items = '';
         // get items
         for ($x = 1; $x <= $num_items; $x++) {
             if (isset($request['item_number' . $x])) {
                 $arr_temp = explode('-', $request['item_number' . $x]);
                 // shipping type is the last item of the array
                 $item_shipping_type = $arr_temp[count($arr_temp) - 1];
                 // the sku is the last item less the type
                 $item_sku = str_replace('-' . $item_shipping_type, '', $request['item_number' . $x]);
                 $item_name = $request['item_name' . $x];
                 $item_sku = iconv("ISO-8859-1", "UTF-8", $item_name);
                 $item_name = iconv("ISO-8859-1", "UTF-8", $item_name);
                 $item_quantity = $request['quantity' . $x];
                 $item_total = $request['mc_gross_' . $x];
                 $item_price = floatval($item_total) / intval($item_quantity);
                 $item = array('SKU' => $item_sku, 'Name' => $item_name, 'ShippingType' => $item_shipping_type, 'Quantity' => $item_quantity, 'Price' => $item_price, 'Total' => $item_total);
                 $download_link = '';
                 if ($item_shipping_type == 'DOWNLOAD') {
                     $download_link = '<br><a href="http://' . $site['Domain'] . '/api/transaction/download/{{transactionUniqId}}/' . $item_sku . '">Download</a>';
                 }
                 // setup currency for line items
                 $item_total = $item_total . ' ' . $currency;
                 $item_price = $item_price . ' ' . $currency;
                 // add $ for total and price
                 if ($currency == 'USD') {
                     $item_total = '$' . $item_total;
                     $item_price = '$' . $item_price;
                 }
                 $line_items .= '<tr style="border-bottom: 1px solid #f0f0f0;"><td>' . $item_name . '<br><small>' . $item_sku . '</small>' . $download_link . '</td><td align="right">' . $item_price . '</td><td align="right">' . $item_quantity . '</td><td align="right">' . $item_total . '</td></tr>';
                 array_push($items, $item);
             }
         }
         $items_json = json_encode($items);
         $data_json = json_encode($_POST);
         // add a transaction
         $transaction = Transaction::Add($site['SiteId'], $processor, $processorTransactionId, $processorStatus, $email, $payerId, $name, $shipping, $fee, $tax, $total, $currency, $items_json, $data_json);
         // replace {{transactionUniqId}} in line_items
         $line_items = str_replace('{{transactionUniqId}}', $transaction['TransactionUniqId'], $line_items);
         $site_logo = '';
         if ($site['LogoUrl'] != '' && $site['LogoUrl'] != NULL) {
             $site_logo = '<img src="http://' . $site['Domain'] . '/files/' . $site['LogoUrl'] . '" style="max-height:50px">';
         }
         // setup currency for line items
         $shipping = $shipping . ' ' . $currency;
         $tax = $tax . ' ' . $currency;
         $total = $total . ' ' . $currency;
         // add $ for total and price
         if ($currency == 'USD') {
             $shipping = '$' . $shipping;
             $tax = '$' . $tax;
             $total = '$' . $total;
         }
         // send email
         $replace = array('{{site}}' => $site['Name'], '{{site-logo}}' => $site_logo, '{{reply-to}}' => $site['PrimaryEmail'], '{{line-items}}' => $line_items, '{{shipping}}' => $shipping, '{{tax}}' => $tax, '{{total}}' => $total);
         $subject = '[' . $site['Name'] . '] Receipt for your purchase from ' . $site['Name'] . ' (ID: ' . strtoupper($transaction['TransactionUniqId']) . ')';
         //$file = 'sites/'.$site['FriendlyId'].'/emails/receipt.html';
         $file = '/emails/receipt.html';
         // send email from file
         Utilities::SendEmailFromFile($email, $site['PrimaryEmail'], $site['Name'], $subject, $replace, $file);
     } else {
         // IPN response was "INVALID"\
     }
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'text/HTML';
     $response->body = 'Yah!!!';
     return $response;
 }
Exemplo n.º 15
0
    return $res;
}
Route::post('/datasrpc/gt/pp/payment/ipn', function () {
    define("_VALID_PHP", true);
    define("_PIPN", true);
    ini_set('log_errors', true);
    ini_set('error_log', dirname(__FILE__) . '/ipn_errors.log');
    if (isset($_POST['payment_status'])) {
        require_once "/opt/nginx/html/vendor/class_pp.php";
        $listener = new IpnListener();
        $listener->use_live = true;
        $listener->use_ssl = true;
        $listener->use_curl = false;
        try {
            $listener->requirePostMethod();
            $ppver = $listener->processIpn();
        } catch (exception $e) {
            error_log($e->getMessage());
            exit(0);
        }
        $payment_status = $_POST['payment_status'];
        $receiver_email = $_POST['receiver_email'];
        list($membership_id, $user_id) = explode("_", $_POST['item_number']);
        $mc_gross = $_POST['mc_gross'];
        $txn_id = $_POST['txn_id'];
        $getxn_id = true;
        $cat = Category::where('order', '=', $membership_id)->first();
        if (isset($cat->id)) {
            $price = $cat->amount;
        }
        $pp_email = '*****@*****.**';
Exemplo n.º 16
0
function bizz_check_ipn_response()
{
    if (isset($_GET['paypalListener']) && $_GET['paypalListener'] == 'paypal_standard_IPN') {
        // variables
        $listener = new IpnListener();
        $listener->use_sandbox = TEST_MODE;
        $listener->use_ssl = true;
        $listener->use_curl = false;
        try {
            $listener->requirePostMethod();
            $verified = $listener->processIpn();
        } catch (Exception $e) {
            error_log($e->getMessage(), 3, 'error_log');
            exit(0);
        }
        if ($verified) {
            // Get transaction details
            $posted = $listener->getPostData();
            // Post ID
            $order_id = $posted['custom'];
            $order_key = $posted['invoice'];
            // Save details
            $r = '';
            foreach ($posted as $key => $value) {
                $r .= str_pad($key, 25) . "{$value}<br/>";
            }
            $transaction_details = get_post_meta($order_id, 'bizzthemes_booking_paypal_details', 1);
            $transaction_details = !empty($transaction_details) ? $transaction_details . '<br/><hr/><br/>' . $r : $r;
            update_post_meta($order_id, 'bizzthemes_booking_paypal_details', $transaction_details);
            // get booking meta
            $booking_custom = get_post_custom($order_id);
            foreach ($booking_custom as $key => $value) {
                $bookopts[$key] = $value[0];
            }
            // Lowercase
            $posted['payment_status'] = strtolower($posted['payment_status']);
            $posted['txn_type'] = strtolower($posted['txn_type']);
            // Sandbox fix
            if ($posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending') {
                $posted['payment_status'] = 'completed';
            }
            // We are here so lets check status and do actions
            switch ($posted['payment_status']) {
                case 'completed':
                    // Check valid txn_type
                    $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money');
                    if (!in_array($posted['txn_type'], $accepted_types)) {
                        if (DEBUG_MODE) {
                            error_log('Invalid type:' . $posted['txn_type'], 3, 'error_log');
                        }
                        exit;
                    }
                    // Saved booking
                    $deposit_amount = get_post_meta($order_id, 'bizzthemes_car_pay_deposit', 1);
                    $total_amount = get_post_meta($order_id, 'bizzthemes_car_pay_total', 1);
                    // Validate Amount
                    if (round($deposit_amount, 2) != $posted['mc_gross']) {
                        if (DEBUG_MODE) {
                            error_log('Payment error: Amounts do not match (gross ' . $posted['mc_gross'] . ', saved ' . round($deposit_amount, 2) . ')', 3, 'error_log');
                        }
                        exit;
                    }
                    // Store PP Details
                    if (!empty($posted['payer_email'])) {
                        update_post_meta($order_id, 'bizzthemes_bookings_email', $posted['payer_email']);
                    }
                    if (!empty($posted['txn_id'])) {
                        update_post_meta($order_id, 'bizzthemes_car_transaction_id', $posted['txn_id']);
                    }
                    if (!empty($posted['first_name'])) {
                        update_post_meta($order_id, 'bizzthemes_bookings_fname', $posted['first_name']);
                    }
                    if (!empty($posted['last_name'])) {
                        update_post_meta($order_id, 'bizzthemes_bookings_lname', $posted['last_name']);
                    }
                    // Paid
                    update_post_meta($order_id, 'bizzthemes_car_pay_paid', round($posted['mc_gross'], 2));
                    // Completed?
                    if (round($total_amount, 2) == $posted['mc_gross']) {
                        update_post_meta($order_id, 'bizzthemes_bookings_status', 'approved');
                    }
                    break;
                case 'denied':
                case 'expired':
                case 'failed':
                case 'voided':
                    // Only handle full refunds, not partial
                    update_post_meta($order_id, 'bizzthemes_bookings_status', 'cancelled');
                    break;
                case "refunded":
                    // Only handle full refunds, not partial
                    update_post_meta($order_id, 'bizzthemes_bookings_status', 'refunded');
                    update_post_meta($order_id, 'bizzthemes_car_pay_paid', '0');
                    booking_send_notification('refunded', $bookopts);
                    break;
                case "reversed":
                case "chargeback":
                    // Mark order as refunded
                    update_post_meta($order_id, 'bizzthemes_bookings_status', 'refunded');
                    update_post_meta($order_id, 'bizzthemes_car_pay_paid', '0');
                    break;
                default:
                    // No action
                    break;
            }
            exit;
            // error_log('getPaymentData: '.$r, 3, 'error_log');
            //error_log('getTextReport: '.$listener->getTextReport(), 3, 'error_log');
            // mail('*****@*****.**', 'Verified IPN', $listener->getTextReport());
        } else {
            /* zapis v bazo o napačni transakciji */
            // mail('*****@*****.**', 'Invalid IPN', $listener->getTextReport());
            error_log('getTextReport: ' . $listener->getTextReport(), 3, 'error_log');
        }
    }
}
Exemplo n.º 17
0
$listener->use_curl = false;
*/
/*
The processIpn() method will encode the POST variables sent by PayPal and then
POST them back to the PayPal server. An exception will be thrown if there is
a fatal error (cannot connect, your server is not configured properly, etc.).
Use a try/catch block to catch these fatal errors and log to the ipn_errors.log
file we setup at the top of this file.

The processIpn() method will send the raw data on 'php://input' to PayPal. You
can optionally pass the data to processIpn() yourself:
$verified = $listener->processIpn($my_post_data);
*/
try {
    $listener->requirePostMethod();
    $verified = $listener->processIpn();
} catch (Exception $e) {
    //error_log($e->getMessage());
    JLog::add("Error IPN. UserId=" . $user->id . "  Username="******"   Remote IP=" . JTrinityCoreUtilities::getRemoteIP() . "  Message=" . $e->getMessage(), JLog::CRITICAL, 'ipn.php');
    exit(0);
}
$params = JComponentHelper::getParams('com_jtrinitycore');
$mail = $params->get('notificationmail');
/*
The processIpn() method returned true if the IPN was "VERIFIED" and false if it
was "INVALID".
*/
if ($verified) {
    /*
    Once you have a verified IPN you need to do a few more checks on the POST
    fields--typically against data you stored in your database during when the
Exemplo n.º 18
0
/**
 * Process PayPal IPN
 *
 * @access      private
 * @since       1.0 
 * @return      void
*/
function edd_process_paypal_ipn()
{
    global $edd_options;
    // instantiate the IpnListener class
    if (!class_exists('IpnListener')) {
        include_once EDD_PLUGIN_DIR . 'includes/gateways/libraries/paypal/ipnlistener.php';
    }
    $listener = new IpnListener();
    if (edd_is_test_mode()) {
        $listener->use_sandbox = true;
    }
    if (isset($edd_options['ssl'])) {
        $listener->use_ssl = false;
    }
    // to post using the fsockopen() function rather than cURL, use:
    if (isset($edd_options['paypal_disable_curl'])) {
        $listener->use_curl = false;
    }
    try {
        $listener->requirePostMethod();
        $verified = $listener->processIpn();
    } catch (Exception $e) {
        wp_mail(get_bloginfo('admin_email'), 'IPN Error', $e->getMessage());
        exit(0);
    }
    if ($verified) {
        $payment_id = $_POST['custom'];
        $purchase_key = $_POST['item_number'];
        $paypal_amount = $_POST['mc_gross'];
        $payment_status = $_POST['payment_status'];
        $currency_code = strtolower($_POST['mc_currency']);
        // retrieve the meta info for this payment
        $payment_meta = get_post_meta($payment_id, '_edd_payment_meta', true);
        $payment_amount = edd_format_amount($payment_meta['amount']);
        if ($currency_code != strtolower($edd_options['currency'])) {
            return;
            // the currency code is invalid
        }
        if ($paypal_amount != $payment_amount) {
            return;
            // the prices don't match
        }
        if ($purchase_key != $payment_meta['key']) {
            return;
            // purchase keys don't match
        }
        if (isset($_POST['txn_type']) && $_POST['txn_type'] == 'web_accept') {
            $status = strtolower($payment_status);
            if ($status == 'completed' || edd_is_test_mode()) {
                // set the payment to complete. This also sends the emails
                edd_update_payment_status($payment_id, 'publish');
            } else {
                if ($status == 'refunded') {
                    // this refund process doesn't work yet
                    $payment_data = get_post_meta($payment_id, '_edd_payment_meta', true);
                    $downloads = maybe_unserialize($payment_data['downloads']);
                    if (is_array($downloads)) {
                        foreach ($downloads as $download) {
                            edd_undo_purchase($download['id'], $payment_id);
                        }
                    }
                    wp_update_post(array('ID' => $payment_id, 'post_status' => 'refunded'));
                }
            }
        }
    } else {
        wp_mail(get_bloginfo('admin_email'), __('Invalid IPN', 'edd'), $listener->getTextReport());
    }
}