[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PayPal Integration



On Wed, 23 Feb 2011, Luke wrote:

I need to track down the PayPal link/button generation code.

Which I have now done. In its seemingly most basic form, it goes something like this:

https://www.paypal.com/cgi-bin/..hidden..&cmd=_xclick&currency_code=USD&amount=12.34&item_name=url%20encoded%20item%20name%20or%20description

I tossed together a script to generate links based on commandline input, which is below. The command is:

paypallink price description of product

E.G.

paypallink 12.34 this is a test product

If anyone actually uses this, fix the "$email" variable to your registered PayPal email address.

There's probably a better way to handle URL encoding. In fact, I'm sure there is, as this only handles spaces, and only if they are used naked on the command line. It's a test program, nothing more, and I disclaim all responsibility for its (mis)use.


#!/usr/bin/perl

die("USAGE: $0 AMOUNT PRODUCT DESCRIPTION    Ex:\n$0 1.00 a one dollar product\n")
if (($#ARGV + 1) < 2);

my $email = '..hidden..';

my $amount = shift(@ARGV);
my $currency = 'USD';
my $link, $description, $descword;
my $count = 0;

while (my $descword = shift(@ARGV)) {
      $description .= '%20' if ($count > 0);
      $description .= $descword;
      $count++;
     }

$link = 'https://www.paypal.com/cgi-bin/webscr?business=' . $email;
$link .= '&cmd=_xclick&currency_code=' . $currency;
$link .= '&amount=' . $amount;
$link .= '&item_name=' . $description;

print '<a href="' . $link . '" target="_BLANK">Pay Via PayPal</a>' . "\n";