$payment_status = $_POST['payment_status']; $payment_gross = $_POST['mc_gross']; $txn_id = $_POST['txn_id']; $payer_email = $_POST['payer_email']; $payer_id = $_POST['custom']; // PayPal will send the information through a POST $paypal_info = $_POST; $paypal_ipn = new paypal_ipn($paypal_info); // where to contact us if something goes wrong $paypal_ipn->error_email = $now["siteemail"]; // We send an identical response back to PayPal for verification $paypal_ipn->send_response(); // PayPal will tell us whether or not this order is valid. // This will prevent people from simply running your order script // manually if (!$paypal_ipn->is_verified()) { // bad order, someone must have tried to run this script manually $paypal_ipn->error_out("Bad order (PayPal says it's invalid)"); } // payment status switch ($paypal_ipn->get_payment_status()) { case 'Completed': // order is good break; case 'Pending': // money isn't in yet, just quit. // paypal will contact this script again when it's ready $paypal_ipn->error_out("Pending Payment"); break; case 'Failed': // whoops, not enough money
function _notify_url() { $db = JFactory::getDBO(); $par =& JComponentHelper::getParams('com_djclassifieds'); $account_type = $this->params["testmode"]; $user = JFactory::getUser(); $id = JRequest::getInt('id', '0'); $paypal_info = $_POST; /*$fil = fopen('ppraport/pp_raport.txt', 'a'); fwrite($fil, "\n\n--------------------post_first-----------------\n"); $post = $_POST; foreach ($post as $key => $value) { fwrite($fil, $key.' - '.$value."\n"); } fclose($fil);*/ $paypal_ipn = new paypal_ipn($paypal_info); foreach ($paypal_ipn->paypal_post_vars as $key => $value) { if (getType($key) == "string") { eval("\${$key}=\$value;"); } } $paypal_ipn->send_response($account_type); if (!$paypal_ipn->is_verified()) { die; } $paymentstatus = 0; $status = $paypal_ipn->get_payment_status(); $txn_id = $paypal_ipn->paypal_post_vars['txn_id']; if ($status == 'Completed' || $status == 'Pending' && $account_type == 1) { $query = "SELECT p.* FROM #__djcf_payments p " . "WHERE p.id='" . $id . "' "; $db->setQuery($query); $payment = $db->loadObject(); if ($payment) { $query = "UPDATE #__djcf_payments SET status='Completed',transaction_id='" . $txn_id . "' " . "WHERE id=" . $id . " AND method='djcfPaypal'"; $db->setQuery($query); $db->query(); if ($payment->type == 2) { $date_sort = date("Y-m-d H:i:s"); $query = "UPDATE #__djcf_items SET date_sort='" . $date_sort . "' " . "WHERE id=" . $payment->item_id . " "; $db->setQuery($query); $db->query(); } else { if ($payment->type == 1) { $query = "SELECT p.points FROM #__djcf_points p WHERE p.id='" . $payment->item_id . "' "; $db->setQuery($query); $points = $db->loadResult(); $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $payment->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " PayPal <br />" . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . ' ' . $payment->id . "')"; $db->setQuery($query); $db->query(); } else { $query = "SELECT c.* FROM #__djcf_items i, #__djcf_categories c " . "WHERE i.cat_id=c.id AND i.id='" . $payment->item_id . "' "; $db->setQuery($query); $cat = $db->loadObject(); $pub = 0; if ($cat->autopublish == '1' || $cat->autopublish == '0' && $par->get('autopublish') == '1') { $pub = 1; } $query = "UPDATE #__djcf_items SET payed=1, pay_type='', published='" . $pub . "' " . "WHERE id=" . $payment->item_id . " "; $db->setQuery($query); $db->query(); } } } } else { $query = "UPDATE #__djcf_payments SET status='" . $status . "',transaction_id='" . $txn_id . "' " . "WHERE id=" . $id . " AND method='djcfPaypal'"; $db->setQuery($query); $db->query(); } }
function _notify_url() { $db = JFactory::getDBO(); $par =& JComponentHelper::getParams('com_djclassifieds'); $account_type = $this->params["testmode"]; $user = JFactory::getUser(); $id = JRequest::getInt('id', '0'); $paypal_info = $_POST; /*$fil = fopen('ppraport/pp_raport.txt', 'a'); fwrite($fil, "\n\n--------------------post_first-----------------\n"); $post = $_POST; foreach ($post as $key => $value) { fwrite($fil, $key.' - '.$value."\n"); } fclose($fil);*/ $paypal_ipn = new paypal_ipn($paypal_info); foreach ($paypal_ipn->paypal_post_vars as $key => $value) { if (getType($key) == "string") { eval("\${$key}=\$value;"); } } $paypal_ipn->send_response($account_type); if (!$paypal_ipn->is_verified()) { die; } $paymentstatus = 0; $status = $paypal_ipn->get_payment_status(); $txn_id = $paypal_ipn->paypal_post_vars['txn_id']; if ($status == 'Completed' || $status == 'Pending' && $account_type == 1) { $query = "SELECT p.* FROM #__djcf_payments p " . "WHERE p.id='" . $id . "' "; $db->setQuery($query); $payment = $db->loadObject(); if ($payment) { if (JRequest::getVar('mc_gross') != $payment->price) { die('Wrong amount'); } $query = "UPDATE #__djcf_payments SET status='Completed',transaction_id='" . $txn_id . "' " . "WHERE id=" . $id . " AND method='djcfPaypal'"; $db->setQuery($query); $db->query(); if ($row->type == 3) { //subscription plans $query = "SELECT p.* FROM #__djcf_plans p WHERE p.id='" . $row->item_id . "' "; $db->setQuery($query); $plan = $db->loadObject(); $registry = new JRegistry(); $registry->loadString($plan->params); $plan_params = $registry->toObject(); //echo '<pre>';print_r($plan_params);die(); $date_start = date("Y-m-d H:i:s"); $date_exp = ''; if ($plan_params->days_limit) { $date_exp_time = time() + $plan_params->days_limit * 24 * 60 * 60; $date_exp = date("Y-m-d H:i:s", $date_exp_time); } $query = "INSERT INTO #__djcf_plans_subscr (`user_id`,`plan_id`,`adverts_limit`,`adverts_available`,`date_start`,`date_exp`,`plan_params`) " . "VALUES ('" . $row->user_id . "','" . $plan->id . "','" . $plan_params->ad_limit . "','" . $plan_params->ad_limit . "','" . $date_start . "','" . $date_exp . "','" . addslashes($plan->params) . "')"; $db->setQuery($query); $db->query(); $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_SUBSCRIPTION_PLAN_ADDED'); } else { if ($payment->type == 2) { $date_sort = date("Y-m-d H:i:s"); $query = "UPDATE #__djcf_items SET date_sort='" . $date_sort . "' " . "WHERE id=" . $payment->item_id . " "; $db->setQuery($query); $db->query(); } else { if ($payment->type == 1) { $query = "SELECT p.points FROM #__djcf_points p WHERE p.id='" . $payment->item_id . "' "; $db->setQuery($query); $points = $db->loadResult(); $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $payment->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " PayPal <br />" . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . ' ' . $payment->id . "')"; $db->setQuery($query); $db->query(); } else { $query = "SELECT c.* FROM #__djcf_items i, #__djcf_categories c " . "WHERE i.cat_id=c.id AND i.id='" . $payment->item_id . "' "; $db->setQuery($query); $cat = $db->loadObject(); $pub = 0; if ($cat->autopublish == '1' || $cat->autopublish == '0' && $par->get('autopublish') == '1') { $pub = 1; } $query = "UPDATE #__djcf_items SET payed=1, pay_type='',extra_images_to_pay='0',extra_chars_to_pay='0', published='" . $pub . "' " . "WHERE id=" . $payment->item_id . " "; $db->setQuery($query); $db->query(); if ($pub) { DJClassifiedsNotify::notifyUserPublication($payment->item_id, '1'); } } } } $payment->status = 'Completed'; $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterPaymentStatusChange', array($payment)); } } else { $query = "UPDATE #__djcf_payments SET status='" . $status . "',transaction_id='" . $txn_id . "' " . "WHERE id=" . $id . " AND method='djcfPaypal'"; $db->setQuery($query); $db->query(); } }