Difference between revisions of "Extension talk:PayPal.php"
(code notes) |
(Info) |
||
Line 1: | Line 1: | ||
− | + | == Installation == | |
− | + | To install the extension, just save the code into your extensions directory as usual and include it from your LocalSettings.php file. You should also create a file of the same name as the extension but with the .log file-extension instead of .php (e.g. PayPal.log) and make it writable by the web server to allow IPN responses or debugging information to be logged there. | |
− | // | + | To test IPN, see [[PayPal]] for how to set up a paypal test environment, and then enable the IPN functionality and create your forms as in the following LocalSettings.php example: |
− | $ | + | {{code|<php> |
+ | include('extensions/PayPal.php'); | ||
+ | $wgPayPalIPN = true; # Enable handling of IPN posts from PayPal | ||
+ | $wgUseAjax = true; # Enable the Ajax updater to dynamically update the form totals after IPN post received | ||
+ | $wgPayPalTest = 'aran@zenovia.net'; # <--------------- THIS IS YOUR TEST BUYER ACCOUNT | ||
+ | $ipbwiki_paypal[1] = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> | ||
+ | <input type="hidden" name="cmd" value="_xclick"> | ||
+ | <input type="hidden" name="business" value="aran@organicdesign.co.nz"> | ||
+ | <input type="hidden" name="item_name" value="Donation"> | ||
+ | <input type="hidden" name="no_shipping" value="1"> | ||
+ | <input type="hidden" name="cn" value="Optional Comments"> | ||
+ | <input type="hidden" name="currency_code" value="USD"> | ||
+ | <input type="hidden" name="tax" value="0"> | ||
+ | <input type="hidden" name="bn" value="PP-DonationsBF"> | ||
+ | <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"> | ||
+ | </form>'; | ||
+ | $ipbwiki_paypal[2] = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> | ||
+ | <input type="hidden" name="cmd" value="_xclick"> | ||
+ | <input type="hidden" name="business" value="aran@organicdesign.co.nz"> | ||
+ | <input type="hidden" name="item_name" value="Other thing"> | ||
+ | <input type="hidden" name="no_shipping" value="1"> | ||
+ | <input type="hidden" name="cn" value="Optional Comments"> | ||
+ | <input type="hidden" name="currency_code" value="USD"> | ||
+ | <input type="hidden" name="tax" value="0"> | ||
+ | <input type="hidden" name="bn" value="PP-DonationsBF"> | ||
+ | <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"> | ||
+ | </form>'; | ||
+ | </php>}} | ||
− | + | == Creating a form == | |
− | $ | + | The following couple of lines of wikitext will render the two forms defined in LocalSettings above. The parameter supplied is the text which will be rendered along with the form (if the first characters of the text are a number followed by a space, then the number is treated as the number of the form which should be rendered). If IPN is enabled then this text should contain tokens $1, $2 and $3 which will be replaced respectively by total amount donated, total number of donations made and the current state of the transaction (if returning from paypal after purchase - empty otherwise). |
− | $ | + | <pre> |
− | + | <paypal>There have been $2 donations totalling $$1. $3</paypal> | |
− | + | <paypal>2 There have been $2 donations totalling $$1. $3</paypal> | |
− | $ | + | </pre> |
− | $ | ||
− | |||
− | |||
− | + | == IPN Database Table == | |
− | + | The transactions are stored in a database table called ''templatePayPalIPN'' which is structured as follows: | |
− | + | <pre> | |
− | + | +------------+---------------+------+-----+---------+-------+ | |
− | + | | Field | Type | Null | Key | Default | Extra | | |
− | + | +------------+---------------+------+-----+---------+-------+ | |
− | + | | ipn_id | varchar(32) | NO | PRI | | | | |
− | + | | ipn_date | tinytext | YES | | NULL | | | |
− | + | | ipn_item | int(11) | NO | | | | | |
− | / | + | | ipn_from | tinytext | YES | | NULL | | |
− | + | | ipn_amount | decimal(10,0) | YES | | NULL | | | |
− | + | | ipn_status | tinytext | YES | | NULL | | | |
− | + | +------------+---------------+------+-----+---------+-------+ | |
− | + | </pre> | |
− | + | Here is an example of the tables content after it has been populated with some paypal sandbox transactions made from the form examples shown above: | |
− | + | <pre> | |
− | + | +-------------------+---------------------------+----------+-------------------------------+------------+------------+ | |
− | + | | ipn_id | ipn_date | ipn_item | ipn_from | ipn_amount | ipn_status | | |
− | + | +-------------------+---------------------------+----------+-------------------------------+------------+------------+ | |
− | + | | 6C047440J05621040 | 15:11:38 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 22 | Completed | | |
− | + | | 23M49673DB6083320 | 17:00:51 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 8 | Completed | | |
− | + | | 18183268SP9363925 | 17:03:16 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 33 | Completed | | |
− | + | | 7U934835WE0858113 | 17:06:54 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 21 | Completed | | |
− | + | | 68W35106NH479463N | 17:16:52 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 12 | Completed | | |
− | + | | 83A03941MM395870F | 17:19:33 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 22 | Completed | | |
− | + | | 44384998LU7025730 | 17:22:12 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 22 | Pending | | |
− | + | | 3Y781051NB0709135 | 17:37:27 Dec 12, 2007 PST | 2 | donations@organicdesign.co.nz | 44 | Completed | | |
− | + | +-------------------+---------------------------+----------+-------------------------------+------------+------------+ | |
− | + | </pre> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </ |
Revision as of 01:57, 13 December 2007
Installation
To install the extension, just save the code into your extensions directory as usual and include it from your LocalSettings.php file. You should also create a file of the same name as the extension but with the .log file-extension instead of .php (e.g. PayPal.log) and make it writable by the web server to allow IPN responses or debugging information to be logged there.
To test IPN, see PayPal for how to set up a paypal test environment, and then enable the IPN functionality and create your forms as in the following LocalSettings.php example:
Creating a form
The following couple of lines of wikitext will render the two forms defined in LocalSettings above. The parameter supplied is the text which will be rendered along with the form (if the first characters of the text are a number followed by a space, then the number is treated as the number of the form which should be rendered). If IPN is enabled then this text should contain tokens $1, $2 and $3 which will be replaced respectively by total amount donated, total number of donations made and the current state of the transaction (if returning from paypal after purchase - empty otherwise).
<paypal>There have been $2 donations totalling $$1. $3</paypal> <paypal>2 There have been $2 donations totalling $$1. $3</paypal>
IPN Database Table
The transactions are stored in a database table called templatePayPalIPN which is structured as follows:
+------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------+------+-----+---------+-------+ | ipn_id | varchar(32) | NO | PRI | | | | ipn_date | tinytext | YES | | NULL | | | ipn_item | int(11) | NO | | | | | ipn_from | tinytext | YES | | NULL | | | ipn_amount | decimal(10,0) | YES | | NULL | | | ipn_status | tinytext | YES | | NULL | | +------------+---------------+------+-----+---------+-------+
Here is an example of the tables content after it has been populated with some paypal sandbox transactions made from the form examples shown above:
+-------------------+---------------------------+----------+-------------------------------+------------+------------+ | ipn_id | ipn_date | ipn_item | ipn_from | ipn_amount | ipn_status | +-------------------+---------------------------+----------+-------------------------------+------------+------------+ | 6C047440J05621040 | 15:11:38 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 22 | Completed | | 23M49673DB6083320 | 17:00:51 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 8 | Completed | | 18183268SP9363925 | 17:03:16 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 33 | Completed | | 7U934835WE0858113 | 17:06:54 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 21 | Completed | | 68W35106NH479463N | 17:16:52 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 12 | Completed | | 83A03941MM395870F | 17:19:33 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 22 | Completed | | 44384998LU7025730 | 17:22:12 Dec 12, 2007 PST | 1 | donations@organicdesign.co.nz | 22 | Pending | | 3Y781051NB0709135 | 17:37:27 Dec 12, 2007 PST | 2 | donations@organicdesign.co.nz | 44 | Completed | +-------------------+---------------------------+----------+-------------------------------+------------+------------+