Donation MOD with Multiple Payment Options and IPN

Area dedicata al phpBB 3.1.X
Rispondi
Avatar utente
TakeOVer
Nuovo Utente
Nuovo Utente
Messaggi: 28
Iscritto il: 20/02/2013, 12:05
Link del Forum:
Località: Firenze
Contatta:

Donation MOD with Multiple Payment Options and IPN

Messaggio da TakeOVer »

Buonasera a tutti,
come da titolo ultimamente ho riscontrato un problema con tale MOD. Di seguito il link della MOD sul com https://www.phpbb.com/community/viewtop ... 2&start=60
Purtroppo dato che è stata segnalata come [ABD] = Abbandonata, e lo stesso autore della MOD è passato ad altre piattaforme con la decisa intenzione di non supportare più il phpbb, ho deciso di rivolgermi a voi! La MOD funziona bene per quanto riguarda le donazioni, ma purtroppo il file IPN.php presenta dei problemi! In pratica il file ipn dovrebbe riportare l'importo della donazione, il nick di chi ha donato e la valuta. Se tale utente non è già un Donatore, dovrebbe inserirlo in automatico tra i Donatori. Poi dovrebbe inviare un pvt sia a chi ha donato (per ringraziarlo) e agli Admin (per informarli della donazione)... ma, purtroppo tutto questo non avviene!
Allego il file ipn.php nel caso qualche anima pia riesca a risolvere là dove io già da una settimana continuo a fallire :arrendo: !!

Codice: Seleziona tutto

<?php
/**
*
* @package Donation MOD with Multiple Payment Options
* @version $Id$
* @copyright (c) 2012 Siropu, www.siropu.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/donation');

if (!$config['donation_ipn_enable'])
{
    exit;
}

// A function to be executed on successful donation
function donation_received($username, $amount, $currency, $method)
{
    global $db, $user, $config;

	// Grab user & group ID
	$sql = 'SELECT user_id, group_id
		FROM ' . USERS_TABLE . '
		WHERE username_clean = "' . $db->sql_escape(strtolower($username)) . '"
		AND group_id NOT IN (6)';
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);

	$user_id  = $row['user_id'];
    $group_id = $row['group_id'];

	$db->sql_freeresult($result);

	// Check if the user ID exists
	if ($row)
	{
	    // Add donor in the database
		$sql_ary = array(
	        'donor_username'    => $username,
	        'donation_amount'   => $amount,
	        'donation_currency' => $currency,
	        'donation_method'   => $method,
	        'donation_date'     => time(),
        );

	    $db->sql_query('INSERT INTO ' . DONATION_DONORS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));

		// Add donor to the specified group
		if ($config['donors_group_enable'])
		{
			$default = false;

		    if ($config['donors_group_default'] && !in_array($group_id, explode(',', $config['donors_group_exceptions'])))
		    {
		        $default = true;
		    }

		    group_user_add($config['donors_group_id'], false, $username, false, $default, 0, 0, false);
        }

		$admin_user_id = $config['ipn_admin_user_id'];

		// Send a thank you PM to the donor
		if ($config['donation_send_donor_notification_pm'])
		{
            $sql = 'SELECT * 
		        FROM ' . DONATION_CONFIG_TABLE;
            $result = $db->sql_query($sql);

            $donation_config = array();
            while($row = $db->sql_fetchrow($result))
            {
	           $donation_config[$row['config_name']] = $row['config_value'];
            }
            $db->sql_freeresult($result);

            $my_subject = utf8_normalize_nfc($donation_config['donation_pm_subject']);
            $my_text    = utf8_normalize_nfc($donation_config['donation_pm_body']);

            $poll = $uid = $bitfield = $options = ''; 
            generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
            generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);

            $data = array( 
                'address_list'    => array ('u' => array($user_id => 'to')),
                'from_user_id'    => $admin_user_id,
				'from_username'   => $user->lang['DONATION_NOTIFICATION'],
                'icon_id'         => 4,
                'from_user_ip'    => false,

                'enable_bbcode'   => true,
                'enable_smilies'  => true,
                'enable_urls'     => true,
                'enable_sig'      => true,

                'message'         => $my_text,
                'bbcode_bitfield' => $bitfield,
                'bbcode_uid'      => $uid,
            );

            submit_pm('post', $my_subject, $data, false);
		}

		// Send donation notification PM to admin group
		if ($config['donation_send_admin_notification_pm'])
		{
		    $my_subject = utf8_normalize_nfc("{$user->lang['ADMIN_NOTIFICATION_PM_SUBJECT']} {$user->lang['FROM']} {$username}!");
            $my_text    = utf8_normalize_nfc("[b]{$user->lang['DONOR_AMOUNT']}:[/b] {$amount}  {$currency}\n[b]{$user->lang['DONOR_METHOD']}:[/b] {$method}");

            $poll = $uid = $bitfield = $options = ''; 
            generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
            generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);

            $data = array( 
                'address_list'    => array ('u' => array($admin_user_id => 'to'), 'g' => array(5 => 'to')),
                'from_user_id'    => $admin_user_id,
				'from_username'   => $user->lang['DONATION_NOTIFICATION'],
                'icon_id'         => 8,
                'from_user_ip'    => false,

                'enable_bbcode'   => true,
                'enable_smilies'  => true,
                'enable_urls'     => true,
                'enable_sig'      => true,

                'message'         => $my_text,
                'bbcode_bitfield' => $bitfield,
                'bbcode_uid'      => $uid,
            );

            submit_pm('post', $my_subject, $data, false);
		}

		// Update donation goal
		if ($currency == $config['donation_goal_currency'])
		{
		    $donation_goal_amount_received = $config['donation_goal_amount_received'] + $amount;
		    set_config('donation_goal_amount_received', $donation_goal_amount_received);
		}
		else
		{
		    // Thanks dynamicguru.com for this useful function
		    function currency_convert($from_Currency, $to_Currency, $amount) 
            {
                $amount = urlencode($amount);
                $from_Currency = urlencode($from_Currency);
                $to_Currency = urlencode($to_Currency);
                $url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
                $ch = curl_init();
                $timeout = 0;
                curl_setopt ($ch, CURLOPT_URL, $url);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt ($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
                curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                $rawdata = curl_exec($ch);
                curl_close($ch);
                $data = explode('"', $rawdata);
                $data = explode(' ', $data['3']);
                $var = $data['0'];
                return round($var,1);
            }

		    $donation_goal_amount_received = $config['donation_goal_amount_received'] + currency_convert($donation_currency, $config['donation_goal_currency'], $amount);
			set_config('donation_goal_amount_received', $donation_goal_amount_received);
		}
	}
}

// Process the donation
$action = request_var('action', '');

switch ($action)
{
    case 'paypal':
	
	    if (!$config['paypal_enable'])
		{
		    exit;
		}

        // read the post from PayPal system and add 'cmd'
        $req = 'cmd=_notify-validate';

        foreach ($_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.1\r\n";
		$header .="Content-Type: application/x-www-form-urlencoded\r\n";
		$header .="Host: www.paypal.com\r\n"; 
		$header .="Connection: close\r\n\r\n";

        $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

        // assign posted variables to local variables
        $username = $_POST['item_number'];
        $amount   = $_POST['mc_gross'];
        $currency = $_POST['mc_currency'];

        if (!$fp)
		{
            // HTTP ERROR
        }
		else
		{
            fputs ($fp, $header . $req);
            while (!feof($fp))
			{
                $res = fgets ($fp, 1024);
                if (strcmp ($res, "VERIFIED") == 0)
				{
                    if ($_POST['payment_status'] == 'Completed' && !empty($username)
						&& $amount >= $config['paypal_minimum'])
					{
					    donation_received($username, $amount, $currency, 'PayPal');
					}	
                }
                else if (strcmp ($res, "INVALID") == 0)
				{
                    // log for manual investigation
                }
            }
            fclose ($fp);
        }

	break;

	case 'payza':

		if (!$config['payza_enable'])
		{
		    exit;
		}

	    //Setting information about the transaction
	    $username = $_POST['ap_description'];
	    $amount   = $_POST['ap_amount'];
	    $currency = $_POST['ap_currency'];

		//Check if the security code and email address matches
		if ($_POST['ap_securitycode'] == $config['payza_ipn_security_code']
			&& $_POST['ap_merchant'] == $config['payza_email'])
		{
			if ($_POST['ap_status'] == "Success" && !empty($username)
				&&  $amount >= $config['payza_minimum'])
			{
				donation_received($username, $amount, $currency, 'Payza');
			}
			else
			{
			    // Transaction was cancelled or an incorrect status was returned.
			    // Take appropriate action.
			}
		}

	break;

	case 'moneybookers':

        if (!$config['moneybookers_enable'])
		{
		    exit;
		}

		$username = $_POST['username'];
        $amount   = $_POST['mb_amount'];
        $currency = $_POST['mb_currency'];

		// Validate the Moneybookers signature
        $concatFields = $_POST['merchant_id']
           .$_POST['transaction_id']
           .strtoupper(md5($config['ipn_moneybookers_secret_word']))
           .$amount
           .$currency
           .$_POST['status']
		   .$username;

        // Ensure the signature is valid, the status code == 2,
        // and that the money is going to you
        if (strtoupper(md5($concatFields)) == $_POST['md5sig'] && $_POST['status'] == 2
			&& $_POST['pay_to_email'] == $config['moneybookers_email'])
        {
		    if (!empty($username) && $amount >= $config['moneybookers_minimum'])
            {
			    donation_received($username, $amount, $currency, 'Moneybookers');
			}
        }
        else
        {
            // Invalid transaction. Bail out
            exit;
        }

	break;

	case 'webmoney':

	    if (!$config['webmoney_enable'])
		{
		    exit;
		}

		$username = $_POST['USERNAME'];
		$amount   = $_POST['LMI_PAYMENT_AMOUNT'];

		$wm_purses = array(
		    'USD' => $config['webmoney_purse_wmz'],
			'RUB' => $config['webmoney_purse_wmr'],
			'EUR' => $config['webmoney_purse_wme'],
			'UAH' => $config['webmoney_purse_wmu'],
			'BYR' => $config['webmoney_purse_wmb'],
			'GLD' => $config['webmoney_purse_wmg'],
		);

		$currency = '';
		foreach ($wm_purses as $ccy => $purse)
		{
		    if ($_POST['LMI_PAYEE_PURSE'] == $purse)
			{
			   $currency = $ccy;
			}
		}

		if (isset($_POST['LMI_SYS_TRANS_NO']) && in_array($_POST['LMI_PAYEE_PURSE'], $wm_purses))
		{
		    if (!empty($username) &&  $amount >= $config['webmoney_minimum'])
            {
			    donation_received($username, $amount, $currency, 'WebMoney');
			}
		}

	break;
}

?>
Grazie
:birra:
Sono amico di tutti, ma alle condizioni di nessuno!
Avatar utente
TakeOVer
Nuovo Utente
Nuovo Utente
Messaggi: 28
Iscritto il: 20/02/2013, 12:05
Link del Forum:
Località: Firenze
Contatta:

EDIT: Donation MOD with Multiple Payment Options and IPN

Messaggio da TakeOVer »

Buonasera,
allora: finalmente ieri (con quel poco tempo che avevo) sono riuscito a risolvere il problema. Bastava aggiungere la seguente stringa di codice:

Codice: Seleziona tutto

$header .="Content-Length: " . strlen($req) . "\r\n";
Posto di seguito il codice completo del file IPN per chi fosse interessato!

Codice: Seleziona tutto

<?php
/**
*
* @package Donation MOD with Multiple Payment Options
* @version $Id$
* @copyright (c) 2012 Siropu, www.siropu.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

//include($phpbb_root_path . 'donation/log.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/donation');

if (!$config['donation_ipn_enable'])
{
    exit;
}

// A function to be executed on successful donation
function donation_received($username, $amount, $currency, $method)
{
    global $db, $user, $config;

	// Grab user & group ID
	$sql = 'SELECT user_id, group_id
		FROM ' . USERS_TABLE . '
		WHERE username_clean = "' . $db->sql_escape(strtolower($username)) . '"
		AND group_id NOT IN (6)';
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);

	$user_id  = $row['user_id'];
    $group_id = $row['group_id'];

	$db->sql_freeresult($result);

	// Check if the user ID exists
	if ($row)
	{
	    // Add donor in the database
		$sql_ary = array(
	        'donor_username'    => $username,
	        'donation_amount'   => $amount,
	        'donation_currency' => $currency,
	        'donation_method'   => $method,
	        'donation_date'     => time(),
        );

	    $db->sql_query('INSERT INTO ' . DONATION_DONORS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));

		// Add donor to the specified group
		if ($config['donors_group_enable'])
		{
			$default = false;

		    if ($config['donors_group_default'] && !in_array($group_id, explode(',', $config['donors_group_exceptions'])))
		    {
		        $default = true;
		    }

		    group_user_add($config['donors_group_id'], false, $username, false, $default, 0, 0, false);
        }

		$admin_user_id = $config['ipn_admin_user_id'];

		// Send a thank you PM to the donor
		if ($config['donation_send_donor_notification_pm'])
		{
            $sql = 'SELECT * 
		        FROM ' . DONATION_CONFIG_TABLE;
            $result = $db->sql_query($sql);

            $donation_config = array();
            while($row = $db->sql_fetchrow($result))
            {
	           $donation_config[$row['config_name']] = $row['config_value'];
            }
            $db->sql_freeresult($result);

            $my_subject = utf8_normalize_nfc($donation_config['donation_pm_subject']);
            $my_text    = utf8_normalize_nfc($donation_config['donation_pm_body']);

            $poll = $uid = $bitfield = $options = ''; 
            generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
            generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);

            $data = array( 
                'address_list'    => array ('u' => array($user_id => 'to')),
                'from_user_id'    => $admin_user_id,
				'from_username'   => $user->lang['DONATION_NOTIFICATION'],
                'icon_id'         => '169',
                'from_user_ip'    => false,

                'enable_bbcode'   => true,
                'enable_smilies'  => true,
                'enable_urls'     => true,
                'enable_sig'      => true,

                'message'         => $my_text,
                'bbcode_bitfield' => $bitfield,
                'bbcode_uid'      => $uid,
            );

            submit_pm('post', $my_subject, $data, false);
		}

		// Send donation notification PM to admin group
		if ($config['donation_send_admin_notification_pm'])
		{
		    $my_subject = utf8_normalize_nfc("{$user->lang['ADMIN_NOTIFICATION_PM_SUBJECT']} {$user->lang['FROM']} {$username}!");
            $my_text    = utf8_normalize_nfc("[b]{$user->lang['DONOR_AMOUNT']}:[/b] {$amount}  {$currency}\n[b]{$user->lang['DONOR_METHOD']}:[/b] {$method}");

            $poll = $uid = $bitfield = $options = ''; 
            generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
            generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);

            $data = array( 
                'address_list'    => array ('u' => array($admin_user_id => 'to'), 'g' => array(5 => 'to')),
                'from_user_id'    => $admin_user_id,
				'from_username'   => $user->lang['DONATION_NOTIFICATION'],
                'icon_id'         => '23',
                'from_user_ip'    => false,

                'enable_bbcode'   => true,
                'enable_smilies'  => true,
                'enable_urls'     => true,
                'enable_sig'      => true,

                'message'         => $my_text,
                'bbcode_bitfield' => $bitfield,
                'bbcode_uid'      => $uid,
            );

            submit_pm('post', $my_subject, $data, false);
		}

		// Update donation goal
		if ($currency == $config['donation_goal_currency'])
		{
		    $donation_goal_amount_received = $config['donation_goal_amount_received'] + $amount;
		    set_config('donation_goal_amount_received', $donation_goal_amount_received);
		}
		else
		{
		    // Thanks dynamicguru.com for this useful function
		    function currency_convert($from_Currency, $to_Currency, $amount) 
            {
                $amount = urlencode($amount);
                $from_Currency = urlencode($from_Currency);
                $to_Currency = urlencode($to_Currency);
                $url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
                $ch = curl_init();
                $timeout = 0;
                curl_setopt ($ch, CURLOPT_URL, $url);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt ($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
                curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                $rawdata = curl_exec($ch);
                curl_close($ch);
                $data = explode('"', $rawdata);
                $data = explode(' ', $data['3']);
                $var = $data['0'];
                return round($var,1);
            }

		    $donation_goal_amount_received = $config['donation_goal_amount_received'] + currency_convert($donation_currency, $config['donation_goal_currency'], $amount);
			set_config('donation_goal_amount_received', $donation_goal_amount_received);
		}
	}
}

// Process the donation
$action = request_var('action', '');

switch ($action)
{
    case 'paypal':
	
	    if (!$config['paypal_enable'])
		{
			//scrivi_log("PAYPAL SI DISABLED!!!");
		    exit;
		}

        // read the post from PayPal system and add 'cmd'
        $req = 'cmd=_notify-validate';

        foreach ($_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.1\r\n";
		$header .="Content-Type: application/x-www-form-urlencoded\r\n";
		$header .="Content-Length: " . strlen($req) . "\r\n";
		$header .="Host: www.paypal.com\r\n"; 
		$header .="Connection: close\r\n\r\n";

        $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

        //scrivi_log("CONNECT TO ssl://www.paypal.com");
        
        // assign posted variables to local variables
        $username = $_POST['item_number'];
        $amount   = $_POST['mc_gross'];
        $currency = $_POST['mc_currency'];

        if (!$fp)
		{
            // HTTP ERROR
            //scrivi_log("HTTP ERROR!!!");
        }
		else
		{
            fputs ($fp, $header . $req);
            while (!feof($fp))
			{
                $res = fgets ($fp, 1024);
                if (strcmp ($res, "VERIFIED") == 0)
				{
					//scrivi_log("RESPONCE VERIFIED!!");
                    if ($_POST['payment_status'] == 'Completed' && !empty($username)
						&& $amount >= $config['paypal_minimum'])
					{
					    donation_received($username, $amount, $currency, 'PayPal');
					}	
                }
                else if (strcmp ($res, "INVALID") == 0)
				{
                    // log for manual investigation
                    scrivi_log("RESPONCE INVALID!!");
                }
            }
            fclose ($fp);
        }

	break;

	case 'payza':


	break;

	case 'moneybookers':


	break;

	case 'webmoney':


	break;
}

?>
Sono arrivato a tale conclusione, incorporando allo script un gestore di log e richiamandolo dalla SandBox messa a disposizione da PayPal appunto per testarne l'effettiva funzionalità ;-)
Grazie comunque a chiunque ha letto questo thread!
Sono amico di tutti, ma alle condizioni di nessuno!
Avatar utente
RetroLogi
Nuovo Utente
Nuovo Utente
Messaggi: 2
Iscritto il: 23/09/2016, 14:29
Link del Forum: http://www.omega-gaming.it/forum

Re: Donation MOD with Multiple Payment Options and IPN

Messaggio da RetroLogi »

Ciao, purtroppo i link per installare questa mod non esisto più, qualcuno può creare una guida o passare ill ink? Sono interessato alle funzioni di questa mod in particolare. Grazie
Rispondi