| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Old Sites/moke/components/com_imageads/classes/ |
Upload File : |
<?php
/**
* @version $Id: paypal.php
* @package ImageAds
* @author Andrey Sokolnikov <aasfalcon@gmail.com>
* @copyright (C) 2011 Emergination, LLC. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
/**
* PayPal button
*
* @package ImageAds
*/
class imageadsPayPalButton
{
/**
* Command (subscription)
*
* @var string
* @access public
*/
var $cmd = '_xclick-subscriptions';
/**
* Seller's email
*
* @var string
* @access public
*/
var $business = '';
/**
* Location
*
* @var string
* @access public
*/
var $lc = 'us';
/**
* Item name
*
* @var string
* @access public
*/
var $item_name = '';
/**
* Item ID
*
* @var int
* @access public
*/
var $item_number = 0;
/**
* Disable note
*
* @var bool
* @access public
*/
var $no_note = true;
/**
* Disable shipping
*
* @var bool
* @access public
*/
var $no_shipping = true;
/**
* Source (?)
*
* @var bool
* @access public
*/
var $src = 1;
/**
* Subscription payment amount
*
* @var string
* @access public
*/
var $a3 = '0.00';
/**
* Subscription period
*
* @var int
* @access public
*/
var $p3 = '1';
/**
* Subscription period type (day, month...)
*
* @var string
* @access public
*/
var $t3 = 'M';
/**
* Currency code
*
* @var string
* @access public
*/
var $currency_code = 'USD';
/**
* Button type
*
* @var string
* @access public
*/
var $bn = 'PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHosted';
/**
* Return method (1 - GET, 2 - POST)
*
* @var int
* @access public
*/
var $rm = 2;
/**
* Cancel return URL
*
* @var string
* @access public
*/
var $cancel_return = null;
/**
* Notify URL
*
* @var string
* @access public
*/
var $notify_url = null;
/**
* Return URL
*
* @var string
* @access public
*/
var $return = null;
/**
* Return URL
*
* @var string
* @access public
*/
var $cbt = null;
/**
* PayPal URL
*
* @var string
* @access private
*/
var $_paypal_url = IA_PAYPAL_URL;
/**
* Constructor
*
* @access public
*/
function __construct()
{
$params = JComponentHelper::getParams(IA_OPTION);
$this->a3 = $params->get('ad_price');
$this->business = $params->get('paypal_email');
$this->site_name = $params->get('site_name');
$this->cbt = sprintf( JText::_('COM_IMAGEADS_RETURNTO_SUCCESS'), $params->get('site_name') );
if ($params->get('paypal_sandbox')) {
$this->_paypal_url = IA_PAYPAL_URL_SANDBOX;
}
}
/**
* Get button HTML
*
* @access public
* @return string
*/
function render()
{
if (!$this->business) {
return JText::_('COM_IMAGEADS_UNCONFIGURED');
}
// begin form
$button = "<form action=\"https://{$this->_paypal_url}/cgi-bin/webscr\" method=\"post\" class=\"ia-paypal-button\">";
$vars = get_object_vars($this);
// add hidden inputs
foreach ($vars as $key => $value) {
if (substr($key, 0, 1) != '_') { // skip private vars
if (isset($value)) {
$button .= "\n<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
}
}
}
// add image, end form
$button .= "\n<input type=\"image\" "
."src=\"https://{$this->_paypal_url}/en_US/i/btn/btn_subscribeCC_LG.gif\" "
."border=\"0\" name=\"submit\" alt=\"".JText::_('COM_IMAGEADS_SUBSCRIPTION_BUTTON_ALT')."\">";
$button .= "\n<img alt=\"\" border=\"0\" src=\"https://{$this->_paypal_url}/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\">";
$button .= "\n</form>";
return $button;
}
}
/**
* PayPal payments helper class
*
* @package ImageAds
*/
class imageadsPayPal
{
/**
* Create PayPal subscribe button
*
* @static
* @access public
* @param string $item_name Item name shown on PayPal site
* @param int $item_id Item id number
* @param string $cancel_url URL to return on payment cancellation
* @param string $notify_url URL to recieve IPN
* @param string $return_url URL to return on successfull payment
* @return string Button HTML
*/
static function getButton($item_name, $item_id, $cancel_url, $notify_url, $return_url)
{
$button = new imageadsPayPalButton();
$button->item_name = sprintf(JText::_('COM_IMAGEADS_SUBSCRIPTION_ITEM_NAME'), $button->site_name, $item_name);
$button->item_number = $item_id;
$button->cancel_return = $cancel_url;
$button->notify_url = $notify_url;
$button->return = $return_url;
return $button->render();
}
/**
* Validate PayPal IPN
*
* @static
* @access public
* @param int &$validate_result Validation result (one of IA_PAYPAL_VALIDATE_IPN_XXX constants)
* @return JRegistry object to store IPN data
*/
static function &validateIPN(&$validate_result)
{
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach (JRequest::get('post') as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// 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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
$validate_result = IA_PAYPAL_VALIDATE_IPN_ERROR;
if ($fp) {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$response = fgets ($fp, 1024);
if ("VERIFIED" == $response) {
$validate_result = IA_PAYPAL_VALIDATE_IPN_VERIFIED;
} elseif ("INVALID" == $response) {
$validate_result = IA_PAYPAL_VALIDATE_IPN_INVALID;
}
}
fclose ($fp);
}
$ipn = new JRegistry();
$ipn->loadArray(JRequest::get('post'));
return $ipn;
}
}