|
Cookbook /
PayPalButtons2Summary:A flexible PayPal "Buy Now" button markup
Version:
Prerequisites:PayPal Merchant Account & admin access
Status:Works for contributor's account
Maintainer:zkarj
Categories:
Questions answered by this recipeThe PayPalButtons recipe is great but can it be more flexible? DescriptionI've taken XES's recipe a bit further to cater for a need I have. This version gives you the following two markups (:BuyNow name="Product name" id=ABC001 value="24.95":)
(:BuyNow name="Product name" id=ABC001 value="24.95" options=yes:)
First, generate your button code... (thanks to XES for some of the wording here!)
The example code below is based on my requirements and could easily be customised to yours. What you have to do is look at the code generated from your account and look at the example code and see the differences. I'll try to point them all out. You need to put this code into your local customisation file (typically local/config.php) Example
#Define PayPal Buy Now button markup
Markup('BuyNow', 'inline', '/\\(:BuyNow (.*?):\\)/e', 'PayPalBuyNow("$1")');
function PayPalBuyNow($opts) {
$PayPalBuyNow_Account = 'me@mydomain.com';
$args = ParseArgs($opts);
$output = "<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='business' value='".$PayPalBuyNow_Account."'>
<input type='hidden' name='item_name' value='".$args['name']."'>
<input type='hidden' name='item_number' value='".$args['id']."'>
<input type='hidden' name='amount' value='".$args['value']."'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='return' value='http://www.mydomain.com/pmwiki.php/Main/Paid'>
<input type='hidden' name='cancel_return' value='http://www.mydomain.com/pmwiki.php/Main/NotPaid'>
<input type='hidden' name='no_note' value='1'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='bn' value='PP-BuyNowBF'>";
if ($args['options'] == 'yes') {
$output .="<table><tr><td><input type='hidden' name='on0' value='First issue'>First issue</td><td>
<select name='os0'><option value='Current issue'>Current issue<option value='Next issue'>Next issue
</select></td></tr></table>"; }
$output .= "<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click-butcc.gif'
border='0' name='submit' alt='Make payments with PayPal - it's fast, free and secure!'>
<img alt='' border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'>
</form>";
return Keep($output);
}
First, the markup itself is defined. You shouldn't need to change this. Next we define a special function which will process the markup. The first line inside this function specifies a variable which holds your PayPal account name (usually an email address). I've done this for easy editing and you could similarly factor out other information if so desired. Following are a few lines of no concern, then the line that defines 'business' - using our variable previously defined. Next comes 'item name', 'item number' and 'amount'. These are all specified by the values you include in the markup as name=, id= and value= respectively. Now comes some stuff you'll likely want to edit. 'no_shipping' specifies, in this case, that I don't want to include shipping details in the transaction. 'return', 'cancel_return' and 'currency' should be fairly self explanatory if you've got your own button code to hand. Substitute values as required. Make sure any edits leave everything single quoted. PayPal generates HTML with double quotes. 'bn' I'm not sure about. Copy from your own generated code as necessary. The next section is only included if the markup contains options=yes and I am using this to include 'additional options' on the transaction - in this case, which issue a new subscription should start with, giving the buyer the choice. If you don't want this kind of capability, delete the entire if, or just never use the options=yes markup value. Finally, we close off the code with a submit button. Here you'll want to make sure you have the correct reference to the button image you want. This is specified after <input type='image' src=' And that's it. Not necessarily as straightforward as some would like, but it is a start! Notes
Release NotesMarc 27th, 2006 Recipe added. This is my first cut. The only change I think I need to make for my own purposes would be the URL conversion from page names. Anybody else feel free to improve on this. CommentsComment: PayPal Donate ButtonI have created an update for PayPal Donate buttons which use only the encrypted data. Put this in your #Define PayPal Donate button
Markup('Donate', 'inline', '/\\(:Donate (.*?):\\)/e', 'PayPalDonate("$1")');
function PayPalDonate($opts) {
$args = ParseArgs($opts);
$but = $args['but'];
if (empty($but)) : $but = 21; endif;
$output = "<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_US/i/btn/x-click-but".$but.".gif' name='submit'
alt='Make payments with PayPal - it's fast, free and secure!'>
<img alt='' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'>
<input type='hidden' name='encrypted' value='-----BEGIN PKCS7-----".$args['details']."-----END PKCS7-----'></form>";
return Keep($output);
}
Use it inside your content as: See AlsoContributors |