public function paymentApiCallback($aParams) { Phpfox::log('Module callback recieved: ' . var_export($aParams, true)); Phpfox::log('Attempting to retrieve purchase from the database'); if (!($aPurchase = Phpfox::getService('subscribe.purchase')->getPurchase($aParams['item_number']))) { Phpfox::log('Purchase is not valid'); return false; } Phpfox::log('Purchase is valid: ' . var_export($aPurchase, true)); if ($aParams['status'] == 'completed') { if ($aParams['total_paid'] == $aPurchase['price']) { Phpfox::log('Paid correct price'); } else { Phpfox::log('Paid incorrect price'); return false; } } else { if ($aParams['status'] == 'cancel') { Phpfox::log('Cancel subscription.'); } else { Phpfox::log('Payment is not marked as "completed".'); return false; } } Phpfox::log('Handling purchase'); Phpfox::getService('subscribe.purchase.process')->update($aPurchase['purchase_id'], $aPurchase['package_id'], $aParams['status'], $aPurchase['user_id'], $aPurchase['user_group_id'], $aPurchase['fail_user_group']); Phpfox::log('Handling complete'); }
function younetcore_license() { $sTable = Phpfox::getT('younetcore_license'); Phpfox::log("Start create table {$sTable}"); $sql = "CREATE TABLE IF NOT EXISTS `{$sTable}` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(100) NOT NULL,\n `title` text NOT NULL,\n `descriptions` text,\n `type` varchar(50) NOT NULL,\n `current_version` varchar(50) NOT NULL,\n `lasted_version` varchar(50) NOT NULL,\n `is_active` int(1) DEFAULT '0',\n `date_active` int(11) DEFAULT NULL,\n `params` text,\n `download_link` varchar(500) DEFAULT NULL,\n `demo_link` varchar(500) DEFAULT NULL,\n PRIMARY KEY (`id`)\n\t) ENGINE=InnoDB AUTO_INCREMENT=1;"; Phpfox::getLib('phpfox.database')->query($sql); Phpfox::log("End create table {$sTable}"); }
/** * Handles API callback for payment gateways. * * @param array $aParams ARRAY of params passed from the payment gateway after a payment has been made. * @return bool|null FALSE if payment is not valid|Nothing returned if everything went well. */ public function paymentApiCallback($aParams) { Phpfox::log('Module callback recieved: ' . var_export($aParams, true)); Phpfox::log('Attempting to retrieve purchase from the database'); define('PHPFOX_API_CALLBACK', true); // used to override security checks in the processes if (preg_match('/sponsor/i', $aParams['item_number'])) { // we get the sponsored ad $iId = preg_replace("/[^0-9]/", '', $aParams['item_number']); Phpfox::log('Ad is sponsored'); $aInvoice = $this->database()->select('*')->from(Phpfox::getT('ad_invoice'))->where('invoice_id = ' . $iId . ' AND is_sponsor = 1')->execute('getSlaveRow'); $aAd = Phpfox::getService('ad')->getSponsor($aInvoice['ad_id']); } else { $aAd = Phpfox::getService('ad')->getForEdit($aParams['item_number']); $aInvoice = Phpfox::getService('ad')->getInvoice($aAd['ad_id']); } if (empty($aAd) || $aAd === false) { Phpfox::log('Purchase is not valid'); return false; } if (empty($aInvoice) || $aInvoice === false) { Phpfox::log('Not a valid invoice'); return false; } Phpfox::log('Purchase is valid: ' . var_export($aInvoice, true)); if ($aParams['status'] == 'completed') { if ($aParams['total_paid'] == $aInvoice['price']) { Phpfox::log('Paid correct price'); } else { Phpfox::log('Paid incorrect price'); return false; } } else { Phpfox::log('Payment is not marked as "completed".'); return false; } Phpfox::log('Handling purchase'); $this->database()->update(Phpfox::getT('ad_invoice'), array('status' => $aParams['status'], 'time_stamp_paid' => PHPFOX_TIME), 'invoice_id = ' . $aInvoice['invoice_id']); if (isset($aAd['auto_publish'])) { // its a sponsor ad $this->database()->update(Phpfox::getT('ad_sponsor'), array('is_custom' => $aAd['auto_publish'] == 1 ? '3' : '2', 'is_active' => $aAd['auto_publish'] == 1 ? '1' : '0'), 'sponsor_id = ' . $aAd['sponsor_id']); if ($aAd['auto_publish'] == 1) { $sModule = $aAd['module_id']; $sSection = ''; if (strpos($sModule, '-') !== false) { $aModule = explode('-', $sModule); $sModule = $aModule[0]; $sSection = $aModule[1]; } Phpfox::callback($sModule . '.enableSponsor', array('item_id' => $aAd['item_id'], 'section' => $sSection)); } } else { $this->database()->update(Phpfox::getT('ad'), array('is_custom' => '2'), 'ad_id = ' . $aAd['ad_id']); } $this->cache()->remove('ad', 'substr'); Phpfox::log('Handling complete'); }
public function paymentApiCallback($aParams) { Phpfox::log('Module callback recieved: ' . var_export($aParams, true)); $aRow = $this->database()->select('pp.*, ua.activity_points')->from(Phpfox::getT('point_purchase'), 'pp')->join(Phpfox::getT('user_activity'), 'ua', 'ua.user_id = pp.user_id')->where('pp.purchase_id = ' . (int) $aParams['item_number'])->execute('getSlaveRow'); if (!isset($aRow['purchase_id'])) { Phpfox::log('Unable to find this purchase.'); return false; } if ($aParams['status'] == 'completed') { $iNewTotal = (int) ($aRow['activity_points'] + $aRow['total_point']); $this->database()->update(Phpfox::getT('point_purchase'), array('status' => '1'), 'purchase_id = ' . (int) $aRow['purchase_id']); $this->database()->update(Phpfox::getT('user_activity'), array('activity_points ' => $iNewTotal), 'user_id = ' . (int) $aRow['user_id']); Phpfox::log('Purchase completed. Giving the user #' . $aRow['user_id'] . ' ' . $iNewTotal . ' points.'); return true; } Phpfox::log('Purchase was not paid.'); return false; }
/** * Handles API callback for payment gateways. * * @param array $aParams ARRAY of params passed from the payment gateway after a payment has been made. * @return bool|null FALSE if payment is not valid|Nothing returned if everything went well. */ public function paymentApiCallback($aParams) { Phpfox::log('Module callback recieved: ' . var_export($aParams, true)); Phpfox::log('Attempting to retrieve purchase from the database'); define('PHPFOX_API_CALLBACK', true); // used to override security checks in the processes // we get the sponsored ad $iId = preg_replace("/[^0-9]/", '', $aParams['item_number']); $aInvoice = Phpfox::getService('egift')->getEgiftInvoice((int) $iId); if (empty($aInvoice)) { Phpfox::log('egift not found.'); return false; } Phpfox::log('Found the invoice.'); Phpfox::log('Purchase seems valid: ' . var_export($aInvoice, true)); if ($aParams['status'] == 'completed') { if ($aParams['total_paid'] == $aInvoice['price']) { Phpfox::log('Paid correct price'); } else { Phpfox::log('Paid incorrect price'); return false; } } else { Phpfox::log('Payment is not marked as "completed".'); return false; } Phpfox::log('Handling purchase'); $this->database()->update(Phpfox::getT('egift_invoice'), array('status' => $aParams['status'], 'time_stamp_paid' => PHPFOX_TIME), 'invoice_id = ' . $aInvoice['invoice_id']); $this->database()->update(Phpfox::getT('friend_birthday'), array('status_id' => '1'), 'birthday_id = ' . $aInvoice['birthday_id']); if (Phpfox::isModule('notification')) { Phpfox::getService('notification.process')->add('friend_birthday', $aInvoice['birthday_id'], $aInvoice['user_to'], $aInvoice['user_from']); } $sLink = Phpfox::getLib('url')->makeUrl('friend.mybirthday', array('id' => $aInvoice['birthday_id'])); $sFullName = $this->database()->select('full_name')->from(Phpfox::getT('user'))->where('user_id = ' . (int) $aInvoice['user_from'])->execute('getSlaveField'); Phpfox::getLib('mail')->to($aInvoice['user_to'])->subject(array('friend.full_name_wishes_you_a_happy_birthday_on_site_title', array('full_name' => $sFullName, 'site_title' => Phpfox::getParam('core.site_title'))))->message(array('friend.full_name_wrote_to_congratulate_you_on_your_birthday_on_site_title', array('full_name' => $sFullName, 'site_title' => Phpfox::getParam('core.site_title'), 'link' => $sLink)))->notification('friend.receive_new_birthday')->send(); Phpfox::log('Handling complete'); }
public function update($iPurchaseId, $iPackageId, $sStatus, $iUserId, $iUserGroupId, $iFailUserGroupId) { $sLink = Phpfox::getLib('url')->makeUrl('subscribe.view', array('id' => $iPurchaseId)); switch ($sStatus) { case 'completed': Phpfox::getService('user.process')->updateUserGroup($iUserId, $iUserGroupId); Phpfox::log('Moving user "' . $iUserId . '" to user group "' . $iUserGroupId . '"'); $sSubject = array('subscribe.membership_successfully_updated_site_title', array('site_title' => Phpfox::getParam('core.site_title'))); $sMessage = array('subscribe.your_membership_on_site_title_has_successfully_been_updated', array('site_title' => Phpfox::getParam('core.site_title'), 'link' => $sLink)); $this->database()->updateCounter('subscribe_package', 'total_active', 'package_id', $iPackageId); $this->database()->update(Phpfox::getT('user_field'), array('subscribe_id' => '0'), 'user_id = ' . (int) $iUserId); break; case 'pending': $sSubject = array('subscribe.membership_pending_site_title', array('site_title' => Phpfox::getParam('core.site_title'))); $sMessage = array('subscribe.your_membership_subscription_on_site_title_is_currently_pending', array('site_title' => Phpfox::getParam('core.site_title'), 'link' => $sLink)); $this->database()->update(Phpfox::getT('user_field'), array('subscribe_id' => $iPurchaseId), 'user_id = ' . (int) $iUserId); break; case 'cancel': // User is cancelling a subscription but he has remaining days for that subscription. // Phpfox::getService('user.process')->updateUserGroup($iUserId, $iFailUserGroupId); // Store in the log that this user cancelled the subscription. $this->database()->insert(Phpfox::getT('api_gateway_log'), array('log_data' => 'cancelled_subscription user_' . (int) $iUserId . ' purchaseid_' . (int) $iPurchaseId . ' packageid_' . (int) $iPackageId, 'time_stamp' => PHPFOX_TIME)); // Phpfox::log('Moving user "' . $iUserId . '" to user group "' . $iFailUserGroupId . '"'); // $this->database()->updateCounter('subscribe_package', 'total_active', 'package_id', $iPackageId, true); // break; } if ($sPlugin = Phpfox_Plugin::get('subscribe.service_purchase_process_update_pre_log')) { eval($sPlugin); } Phpfox::log('Updating status of purchase order'); $this->database()->update($this->_sTable, array('status' => $sStatus), 'purchase_id = ' . (int) $iPurchaseId); Phpfox::log('Sending user an email'); Phpfox::getLib('mail')->to($iUserId)->subject($sSubject)->message($sMessage)->notification('subscribe.payment_update')->send(); Phpfox::log('Email sent'); }
public function callback($sGateway) { Phpfox::startLog('Callback started.'); Phpfox::log('Request: ' . var_export($_REQUEST, true)); if (empty($sGateway)) { Phpfox::log('Gateway is empty.'); Phpfox::getService('api.gateway.process')->addLog(null, Phpfox::endLog()); return false; } $aGateway = $this->database()->select('ag.*')->from($this->_sTable, 'ag')->where('ag.gateway_id = \'' . $this->database()->escape($sGateway) . '\' AND ag.is_active = 1')->execute('getRow'); // http://www.phpfox.com/tracker/view/15424/ if ($sGateway == 'activitypoints' && Phpfox::getParam('user.can_purchase_with_points') && Phpfox::getUserParam('user.can_purchase_with_points')) { Phpfox::log('Gateway successfully loaded.'); Phpfox::log('Callback complete'); Phpfox::getService('api.gateway.process')->addLog($aGateway['gateway_id'], Phpfox::endLog()); return true; } if (!isset($aGateway['gateway_id'])) { Phpfox::log('"' . $sGateway . '" is not a valid gateway.'); Phpfox::getService('api.gateway.process')->addLog(null, Phpfox::endLog()); return false; } Phpfox::log('Attempting to load gateway: ' . $aGateway['gateway_id']); if (!($oGateway = Phpfox::getLib('gateway')->load($aGateway['gateway_id'], array_merge($_REQUEST, $aGateway)))) { Phpfox::log('Unable to load gateway.'); Phpfox::getService('api.gateway.process')->addLog($aGateway['gateway_id'], Phpfox::endLog()); return false; } Phpfox::log('Gateway successfully loaded.'); $mReturn = $oGateway->callback(); Phpfox::log('Callback complete'); Phpfox::getService('api.gateway.process')->addLog($aGateway['gateway_id'], Phpfox::endLog()); if ($mReturn == 'redirect') { Phpfox_Url::instance()->send(''); } }
/** * Performs the callback routine when the 3rd party payment gateway sends back a request to the server, * which we must then back and verify that it is a valid request. This then connects to a specific module * based on the information passed when posting the form to the server. * */ public function callback() { Phpfox::log('Starting PayPal callback'); // Read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; // Loop through each of the variables posted by PayPal foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } Phpfox::log('Attempting callback'); // Post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen(($this->_aParam['is_test'] ? 'www.sandbox.paypal.com' : 'www.paypal.com'), 80, $error_no, $error_msg, 30); fputs($fp, $header . $req); $bVerified = false; while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, 'VERIFIED') == 0) { $bVerified = true; break; } } fclose($fp); if ($bVerified === true) { Phpfox::log('Callback OK'); $aParts = explode('|', $this->_aParam['item_number']); Phpfox::log('Attempting to load module: ' . $aParts[0]); if (Phpfox::isModule($aParts[0])) { Phpfox::log('Module is valid.'); Phpfox::log('Checking module callback for method: paymentApiCallback'); if (Phpfox::hasCallback($aParts[0], 'paymentApiCallback')) { Phpfox::log('Module callback is valid.'); Phpfox::log('Building payment status: ' . (isset($this->_aParam['payment_status']) ? $this->_aParam['payment_status'] : '') . ' (' . (isset($this->_aParam['txn_type']) ? $this->_aParam['txn_type'] : '') . ')'); $sStatus = null; if (isset($this->_aParam['payment_status'])) { switch ($this->_aParam['payment_status']) { case 'Completed': $sStatus = 'completed'; break; case 'Pending': $sStatus = 'pending'; break; case 'Refunded': case 'Reversed': $sStatus = 'cancel'; break; } } if (isset($this->_aParam['txn_type'])) { switch ($this->_aParam['txn_type']) { case 'subscr_cancel': $sStatus = 'cancel'; break; } } Phpfox::log('Status built: ' . $sStatus); if ($sStatus !== null) { Phpfox::log('Executing module callback'); Phpfox::callback($aParts[0] . '.paymentApiCallback', array( 'gateway' => 'paypal', 'ref' => $this->_aParam['txn_id'], 'status' => $sStatus, 'item_number' => $aParts[1], 'total_paid' => (isset($this->_aParam['mc_gross']) ? $this->_aParam['mc_gross'] : null) ) ); header('HTTP/1.1 200 OK'); } else { Phpfox::log('Status is NULL. Nothing to do'); } } else { Phpfox::log('Module callback is not valid.'); } } else { Phpfox::log('Module is not valid.'); } } else { Phpfox::log('Callback FAILED'); } }
public function paymentApiCallback($aParams) { Phpfox::log('Module callback recieved: ' . var_export($aParams, true)); Phpfox::log('Attempting to retrieve purchase from the database'); $aInvoice = Phpfox::getService('marketplace')->getInvoice($aParams['item_number']); if ($aInvoice === false) { Phpfox::log('Not a valid invoice'); return false; } $aListing = Phpfox::getService('marketplace')->getForEdit($aInvoice['listing_id'], true); if ($aListing === false) { Phpfox::log('Not a valid listing.'); return false; } Phpfox::log('Purchase is valid: ' . var_export($aInvoice, true)); if ($aParams['status'] == 'completed') { if ($aParams['total_paid'] == $aInvoice['price']) { Phpfox::log('Paid correct price'); } else { Phpfox::log('Paid incorrect price'); return false; } } else { Phpfox::log('Payment is not marked as "completed".'); return false; } Phpfox::log('Handling purchase'); $this->database()->update(Phpfox::getT('marketplace_invoice'), array('status' => $aParams['status'], 'time_stamp_paid' => PHPFOX_TIME), 'invoice_id = ' . $aInvoice['invoice_id']); if ($aListing['auto_sell']) { $this->database()->update(Phpfox::getT('marketplace'), array('view_id' => '2'), 'listing_id = ' . $aListing['listing_id']); } Phpfox::getLib('mail')->to($aListing['user_id'])->subject(array('marketplace.item_sold_title', array('title' => Phpfox::getLib('parse.input')->clean($aListing['title'], 255))))->fromName($aInvoice['full_name'])->message(array('marketplace.full_name_has_purchased_an_item_of_yours_on_site_name', array('full_name' => $aInvoice['full_name'], 'site_name' => Phpfox::getParam('core.site_title'), 'title' => $aListing['title'], 'link' => Phpfox_Url::instance()->makeUrl('marketplace.view', $aListing['title_url']), 'user_link' => Phpfox_Url::instance()->makeUrl($aInvoice['user_name']), 'price' => Phpfox::getService('core.currency')->getCurrency($aInvoice['price'], $aInvoice['currency_id']))))->send(); Phpfox::log('Handling complete'); }
public function log($log) { \Phpfox::log($log); }
/** * Performs the callback routine when the 3rd party payment gateway sends back a request to the server, * which we must then back and verify that it is a valid request. This then connects to a specific module * based on the information passed when posting the form to the server. * */ public function callback() { Phpfox::log('Starting 2checkout callback'); Phpfox::log('Creating MD5 hash'); $bIsRefund = false; if (isset($this->_aParam['is_test']) && $this->_aParam['is_test']) { $sHash = $this->_aParam['md5_hash']; Phpfox::log('Test hash.'); } else { if (isset($this->_aParam['message_type']) && isset($this->_aParam['md5_hash'])) { if (isset($this->_aParam['item_type_1']) && $this->_aParam['item_type_1'] == 'refund') { $bIsRefund = true; } // sale_id + vendor_id + invoice_id + secret word $sHash = strtoupper(md5($this->_aParam['sale_id'] . $this->_aParam['setting']['2co_id'] . $this->_aParam['invoice_id'] . $this->_aParam['setting']['2co_secret'])); Phpfox::log('Refund hash.'); } else { $sHash = strtoupper(md5($this->_aParam['setting']['2co_secret'] . $this->_aParam['setting']['2co_id'] . $this->_aParam['order_number'] . $this->_aParam['total'])); Phpfox::log('Purchase hash.'); } } Phpfox::log('Hash created: ' . $sHash); if ($bIsRefund && $sHash == $this->_aParam['md5_hash'] || !$bIsRefund && $sHash == $this->_aParam['md5_hash']) { Phpfox::log('Hash is valid'); $aParts = explode('|', $this->_aParam['vendor_order_id']); Phpfox::log('Attempting to load module: ' . $aParts[0]); if (Phpfox::isModule($aParts[0])) { Phpfox::log('Module is valid.'); Phpfox::log('Checking module callback for method: paymentApiCallback'); if (Phpfox::hasCallback($aParts[0], 'paymentApiCallback')) { Phpfox::log('Module callback is valid.'); Phpfox::log('Building payment status: ' . $this->_aParam['message_description']); $sStatus = null; if ($bIsRefund) { $sStatus = 'cancel'; } else { switch (strtolower($this->_aParam['payment_type'])) { case 'credit card': $sStatus = 'completed'; break; default: $sStatus = 'pending'; break; } } Phpfox::log('Status built: ' . $sStatus); if ($sStatus !== null) { Phpfox::log('Executing module callback'); Phpfox::callback($aParts[0] . '.paymentApiCallback', array('gateway' => '2checkout', 'ref' => $bIsRefund ? $this->_aParam['sale_id'] : $this->_aParam['order_number'], 'status' => $sStatus, 'item_number' => $aParts[1], 'total_paid' => $bIsRefund ? '0' : $this->_aParam['item_list_amount_1'])); } else { Phpfox::log('Status is NULL. Nothing to do'); } } else { Phpfox::log('Module callback is not valid.'); } } else { Phpfox::log('Module is not valid.'); } } else { Phpfox::log('Hash is invalid'); } return 'redirect'; }
public function callback($sGateway) { Phpfox::startLog('Callback started.'); Phpfox::log('Request: ' . var_export($_REQUEST, true)); if (empty($sGateway)) { Phpfox::log('Gateway is empty.'); Phpfox::getService('api.gateway.process')->addLog(null, Phpfox::endLog()); return false; } $aGateway = $this->database()->select('ag.*') ->from($this->_sTable, 'ag') ->where('ag.gateway_id = \'' . $this->database()->escape($sGateway) . '\' AND ag.is_active = 1') ->execute('getRow'); if (!isset($aGateway['gateway_id'])) { Phpfox::log('"' . $sGateway . '" is not a valid gateway.'); Phpfox::getService('api.gateway.process')->addLog(null, Phpfox::endLog()); return false; } Phpfox::log('Attempting to load gateway: ' . $aGateway['gateway_id']); if (!($oGateway = Phpfox::getLib('gateway')->load($aGateway['gateway_id'], array_merge($_REQUEST, $aGateway)))) { Phpfox::log('Unable to load gateway.'); Phpfox::getService('api.gateway.process')->addLog($aGateway['gateway_id'], Phpfox::endLog()); return false; } Phpfox::log('Gateway successfully loaded.'); $mReturn = $oGateway->callback(); Phpfox::log('Callback complete'); Phpfox::getService('api.gateway.process')->addLog($aGateway['gateway_id'], Phpfox::endLog()); if ($mReturn == 'redirect') { Phpfox::getLib('url')->send(''); } }