Difference between revisions of "Extension talk:PayPal.php"

From Organic Design wiki
(IPN Database Table)
(Installation)
Line 8: Line 8:
 
$wgUseAjax      = true; # Enable the Ajax updater to dynamically update the form totals after IPN post received
 
$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
 
$wgPayPalTest  = 'aran@zenovia.net'; # <--------------- THIS IS YOUR TEST BUYER ACCOUNT
 +
 +
# First form (paypal item_number = 1)
 
$ipbwiki_paypal[1] = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
 
$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="cmd" value="_xclick">
Line 20: Line 22:
 
alt="Make payments with PayPal - it\'s fast, free and secure!">
 
alt="Make payments with PayPal - it\'s fast, free and secure!">
 
</form>';
 
</form>';
 +
 +
# Second form (paypal item_number = 2)
 
$ipbwiki_paypal[2] = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
 
$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="cmd" value="_xclick">

Revision as of 02:07, 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:

{{{1}}}

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>
  • The $$1 is just to put a dollar symbol before the total amount donated

IPN Database Table

The transactions are stored in a database table called templatePayPalIPN. This was originally planned to just contain an entry for each item_number holding the totals for its corresponding form, but a record of every transaction had to be maintained because there can be many indistinguishable IPN posts for a single transaction. The new table structure is 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  | 
+-------------------+---------------------------+----------+-------------------------------+------------+------------+

AJAX Updater

After a transaction has been made from one of the forms, and the payer returns to the wiki after clicking the "return to merchant" link, the page will include a JS function to keep polling the server to check the status of the transaction that was just made. It will keep polling until the returned status is "Completed". The totals will not be updated until the transaction is completed - but note that the instant transactions are usually completed before the "return to merchant" link is clicked, but slower payments such as e-checks will remain in "pending" state for a few days.