PayPalCart

Summary: Provides markup for PayPal shopping cart buttons.
Version: 2016-03-13
Prerequisites: a PayPal account, PmWiki version UNK (compatible with PHP 5.5)
Status: in active use
Maintainer: Ben Stallings, MichaelPaulukonis
Users: +1 (view / edit)
Discussion: PayPalCart-Talk

Questions answered by this recipe

How can I integrate PayPal shopping cart into my site without having to code all those form fields?

Description

Enter your recipe's description here.

  1. Download this file into your cookbook: paypalcart.phpΔ
  2. Add the following lines to your config.php:
    $PayPal_Account = 'email@example.com';
    include("$FarmD/cookbook/paypalcart.php");
  3. Use the following markup in your pages:
    (:AddToCart name="item name" id="item number" amount="5.00":)
    (:ViewCart:)

Additional customization is possible by editing the forms in the recipe file. This is just a quick and dirty solution, based closely on PayPalButtons2.

Notes

GitHub repo

Release Notes

2016-06-13 - PHP 5.5 compatibility, RecipeInfo inlined

2007-01-10 - original version (non-PHP5.5 compatible)

Comments

See Discussion at PayPalCart-Talk

You can add a quick-and-dirty Donate button option by adding this code to the recipe:

#Define PayPal Donate button markup
Markup('DonateButton', 'inline',  '/\\(:DonateButton (.*?):\\)/e', 'PayPalDonate("$1")');

function PayPalDonate($opts) {
	global $PayPal_Account;
  $args = ParseArgs($opts);
  $output = "<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>\n"
	. "<input type='hidden' name='add' value='1'>\n"
	. "<input type='hidden' name='cmd' value='_xclick'>\n"
	. "<input type='hidden' name='business' value='$PayPal_Account' />\n"
	. "<input type='hidden' name='item_name' value='".$args['name']."' />\n"
	. "<input type='hidden' name='item_number' value='".$args['id']."' />\n"
	. ($args['amount'] ? "<input type='hidden' name='amount' value='".$args['amount']."' />" : "$<input type='text' size='3' name='amount' />") ."\n"
	. "<input type='hidden' name='no_note' value='1' />\n"
	. "<input type='hidden' name='currency_code' value='USD' />\n"
	. "<input type='hidden' name='lc' value='US'>";
	$output .= "<input type='image' src='https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif'\n"
	. "border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>\n"
	. "<img alt='' border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'>\n"
	. "</form>";
	return Keep($output);
}
The markup is then
(:DonateButton name="Name of the charity or fund here" amount="optional amount to donate":)

If you don't specify the amount, a small form field will appear to the left of the button so users can specify the amount before leaving your site.

BenStallings December 08, 2010, at 10:06 AM

See Also

Cookbook /
PayPalButtons  Creating neat markup for otherwise sloppy PayPal button forms (stable)
PayPalButtons2  A flexible PayPal "Buy Now" button markup (Works for contributor's account)
PPDonate  Create links to accept donations via PayPal (Beta)

Contributors

Ben Stallings January 10, 2007, at 03:01 PMMichaelPaulukonis 2013.06.13 upgrated for PHP 5.5 compatibility

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.