Paypal Donations page

A perfect place for code snippets to small to be a MOD or a library.
Or for examples on how to use our libraries.
Post Reply
Elglobo
Past Contributor
Past Contributor
Posts: 119
Joined: 15 Jul 2008, 19:42

Paypal Donations page

Post by Elglobo »

This post was originally posted by Kenny at 6 String MODs, I have made some adjustments.

Very simple Paypal Donations page. So simple that it's more effort to document it here than it was to make it :P

paypal.php

Code: Select all

<?php
/**
*
*&nbsp;@package&nbsp;phpBB3
*&nbsp;@version&nbsp;$Id:&nbsp;paypal.php&nbsp;0006&nbsp;13:23&nbsp;08/08/2008&nbsp;kenny&nbsp;$
*&nbsp;@copyright&nbsp;(c)&nbsp;2005&nbsp;phpBB&nbsp;Group
*&nbsp;@license&nbsp;http://opensource.org/licenses/gpl-license.php&nbsp;GNU&nbsp;Public&nbsp;License
*
*/

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

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

$mode&nbsp;=&nbsp;request_var('mode',&nbsp;'');
$sitename&nbsp;=&nbsp;$config['sitename'];

//&nbsp;Load&nbsp;the&nbsp;appropriate&nbsp;paypal&nbsp;file
switch&nbsp;($mode)
{
&
nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'success':
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$l_title&nbsp;=&nbsp;'DONATION_SUCCESSFULL';
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$template->set_filenames(array(
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'body'&nbsp;=>&nbsp;'paypal/success_body.html')
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
&
nbsp;&nbsp;&nbsp;&nbsp;break;

&
nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'cancel':
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$l_title&nbsp;=&nbsp;'DONATION_CANCELLED';
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$template->set_filenames(array(
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'body'&nbsp;=>&nbsp;'paypal/cancel_body.html')
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
&
nbsp;&nbsp;&nbsp;&nbsp;break;

&
nbsp;&nbsp;&nbsp;&nbsp;default:
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$l_title&nbsp;=&nbsp;sprintf($user->lang['DONATION'],&nbsp;$sitename);
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$template->set_filenames(array(
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'body'&nbsp;=>&nbsp;'paypal/paypal_body.html')
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
&
nbsp;&nbsp;&nbsp;&nbsp;break;
}

//&nbsp;Lets&nbsp;build&nbsp;a&nbsp;page&nbsp;...
$template->assign_vars(array(
&
nbsp;&nbsp;&nbsp;&nbsp;'L_DONATION'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>&nbsp;sprintf($user->lang['DONATION'],&nbsp;$sitename),
&
nbsp;&nbsp;&nbsp;&nbsp;'L_FAQ_TITLE'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>&nbsp;$l_title,
&
nbsp;&nbsp;&nbsp;&nbsp;'L_BACK_TO_TOP'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>&nbsp;$user->lang['BACK_TO_TOP'],
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&
nbsp;&nbsp;&nbsp;&nbsp;'L_PAGE_CANCELLED'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>&nbsp;sprintf($user->lang['PAGE_CANCELLED'],&nbsp;$sitename),
&
nbsp;&nbsp;&nbsp;&nbsp;'L_PAGE_DONATION'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>&nbsp;sprintf($user->lang['PAGE_DONATION'],&nbsp;$sitename),
&
nbsp;&nbsp;&nbsp;&nbsp;'L_PAGE_SUCCESSFULL'&nbsp;&nbsp;&nbsp;&nbsp;=>&nbsp;sprintf($user->lang['PAGE_SUCCESSFULL'],&nbsp;$sitename))
);

page_header($l_title);

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();

?>

language/en/paypal.php

Code: Select all

<?php
/**
*
* paypal [English]
*
* @package language
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
    exit;
}

if (empty($lang) || !is_array($lang))
{
    $lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

$lang = array_merge($lang, array(
    'DONATION'                    => 'Donate to %1$s',
    'DONATION_CANCELLED'        => 'Donation Cancelled',
    'DONATION_SUCCESSFULL'        => 'Donation Successfull',
    
    
'PAGE_CANCELLED'            => 'It seems you have decided to cancel your donation to %1$s.<br />Don\'t worry, it\'s ok - but do think about donating in the future - the more donations we get, the better we can make the site.<br />Thanks for checking out the site none the less<br /><br />The Team',
    'PAGE_SUCCESSFULL'            => 'Support %1$s by making a donation using PayPal.<br />Your donations ensure that we can pay our hosting bills and are able to keep this site online for the benefit of our users.<br /><br />If you are able to donate more than $5 it will keep us motiviated to produce Rewards for our Supporters and helps us that much more.',
    'PAGE_DONATION'                => 'Congratulations, you have successfully donated to %1$s!<br /><br />Your donation, no matter how big or small, is very greatly appreciated and will go towards keeping the site online<br />Hopefully in the future, we can set up a rewards system for those who have donated<br />For now though, you have your utmost thanks<br /><br />The team.',
));

?>

Place the following template files inside a "paypal" folder in your templates directory.
paypal/paypal_body.html

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>{L_DONATION}</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
      <fieldset class="fields2">
         <p>{L_PAGE_DONATION}</p><br />
         <dl>
            <dt>
            
    <!-- Replace this code with your own paypal code -->
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="image" src="https://www.paypal.com/en_GB/i/btn/x-click-but21.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
    <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
    <input type="hidden" name="encrypted" value="----- INSERT YOUR CUSTOM PAYPAL CODE HERE || CHECK THE PAYPAL WEBSITE ON HOW TO GENERATE THIS -----
    "></form>
    <!-- Replace this code with your own paypal code -->

            </dt>
         </dl>
      </fieldset>
   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE overall_footer.html -->

paypal/cancel_body.html

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>{L_DONATION_CANCELLED}</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
      <fieldset class="fields2">
         <p>{L_PAGE_CANCELLED}</p>
      </fieldset>
   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE overall_footer.html -->

paypal/success_body.html

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>{L_DONATION_SUCCESSFULL}</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
      <fieldset class="fields2">
      <p>{L_PAGE_SUCCESSFULL</p>
      </fieldset>
   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE overall_footer.html -->

Create a link to the paypal.php file wherever you like - easiest place is next to the FAQ / Members links in the breadcrumbs bar. Have a look at how the are created to see how you do it. Also, remember to add your custom paypal form info into the paypal_body.html file or you page won't work. There's more information on paypals website on how to generate a custom donations button 8-)
ferdri3
New member
New member
Posts: 2
Joined: 22 Jan 2011, 10:19

Re: Paypal Donations page

Post by ferdri3 »

Works great!

1 bugfix:

(in language/en/paypal.php) FIND:

Code: Select all

'PAGE_CANCELLED'            => 'It seems you have decided to cancel your donation to %1$s.<br />Don\'t worry, it\'s ok - but do think about donating in the future - the more donations we get, the better we can make the site.<br />Thanks for checking out the site none the less<br /><br />The Team',
    'PAGE_SUCCESSFULL'            => 'Support %1$s by making a donation using PayPal.<br />Your donations ensure that we can pay our hosting bills and are able to keep this site online for the benefit of our users.<br /><br />If you are able to donate more than $5 it will keep us motiviated to produce Rewards for our Supporters and helps us that much more.',
    'PAGE_DONATION'                => 'Congratulations, you have successfully donated to %1$s!<br /><br />Your donation, no matter how big or small, is very greatly appreciated and will go towards keeping the site online<br />Hopefully in the future, we can set up a rewards system for those who have donated<br />For now though, you have your utmost thanks<br /><br />The team.',
));


REPLACE with:

Code: Select all

    'PAGE_CANCELLED'            => 'It seems you have decided to cancel your donation to [name of your page].<br />Don\'t worry, it\'s ok - but do think about donating in the future - the more donations we get, the better we can make the site.<br />Thanks for checking out the site none the less<br /><br />The Team',
    'PAGE_SUCCESSFULL'            => 'Congratulations, you have successfully donated to [name of your page]!<br /><br />Your donation, no matter how big or small, is very greatly appreciated and will go towards keeping the site online<br />Hopefully in the future, we can set up a rewards system for those who have donated<br />For now though, you have our utmost thanks<br /><br />The team.',
    'PAGE_DONATION'                => 'Support [name of your page] by making a donation using PayPal.<br />Your donations ensure that we can pay our hosting bills and are able to keep this site online for the benefit of our users.<br /><br />If you are able to donate more than $5 it will keep us motiviated to produce Rewards for our Supporters and helps us that much more.',
));


Dont forget to edit "[name of your page]" into the name of your page

__________________________________________________________________________________________

How to get the code which you should put in the "paypal/paypal_body.html" file:

Login your paypal account
Go to the business service tab
Make your own button and you will get the code
Mr Gloeilamp
Nub
Nub
Posts: 4
Joined: 12 Apr 2011, 06:54

Re: Paypal Donations page

Post by Mr Gloeilamp »

Great MOD, but how add the page next to the FAQ?
Elglobo
Past Contributor
Past Contributor
Posts: 119
Joined: 15 Jul 2008, 19:42

Re: Paypal Donations page

Post by Elglobo »

Mr Gloeilamp wrote:Great MOD, but how add the page next to the FAQ?

Take a look at this article: http://www.phpbb.com/kb/article/adding-a-new-link-and-icon-to-your-header/ ;)
phpBB-Services.com: L'hébergement et l'assistance de votre forum phpBB en toute tranquillité.

Myff.fr - My First forum, créer votre forum phpBB3 facilement !
Post Reply