| Business-PayPal documentation | view source | Contained in the Business-PayPal distribution. |
Business::PayPal - Perl extension for automating PayPal transactions
Business::PayPal makes the automation of PayPal transactions as simple as doing credit card transactions through a regular processor. It includes methods for creating PayPal buttons and for validating the Instant Payment Notification that is sent when PayPal processes a payment.
To generate a PayPal button for use on your site
Include something like the following in your CGI
use Business::PayPal;
my $paypal = Business::PayPal->new;
my $button = $paypal->button(
business => 'dr@dursec.com',
item_name => 'CanSecWest Registration Example',
return => 'http://www.cansecwest.com/return.cgi',
cancel_return => 'http://www.cansecwest.com/cancel.cgi',
amount => '1600.00',
quantity => 1,
notify_url => http://www.cansecwest.com/ipn.cgi
);
my $id = $paypal->id;
#store $id somewhere so we can get it back again later
#store current context with $id
#Apache::Session works well for this
#print button to the browser
#note, button is a CGI form, enclosed in <form></form> tags
To validate the Instant Payment Notification from PayPal for the
button used above include something like the following in your
'notify_url' CGI.
use CGI;
my $query = new CGI;
my %query = $query->Vars;
my $id = $query{custom};
my $paypal = Business::PayPal->new(id => $id);
my ($txnstatus, $reason) = $paypal->ipnvalidate(\%query);
die "PayPal failed: $reason" unless $txnstatus;
my $money = $query{payment_gross};
my $paystatus = $query{payment_status};
#check if paystatus eq 'Completed'
#check if $money is the ammount you expected
#save payment status information to store as $id
To tell the user if their payment succeeded or not, use something like
the following in the CGI pointed to by the 'return' parameter in your
PayPal button.
use CGI;
my $query = new CGI;
my $id = $query{custom};
#get payment status from store for $id
#return payment status to customer
Creates a new Business::PayPal object, it can take the following parameters:
- The Business::PayPal object id, if not specified a new
id will be created using md5_hex(rand())
- The address of PayPal's payment server, currently:
https://www.paypal.com/cgi-bin/webscr
- The x509 certificate for I<address>, see source for default
- The contents of the x509 certificate I<cert>, see source for
default
Returns the id for the Business::PayPal object.
Takes a reference to a hash of name value pairs, such as from a CGI query object, which should contain all the name value pairs which have been posted to the script by PayPal's Instant Payment Notification posts that data back to PayPal, checking if the ssl certificate matches, and returns success or failure, and the reason.
This method should not normally be used unless you need to test, or if you are overriding the behaviour of ipnvalidate. It takes a reference to a hash containing the query, posts to PayPal with the data, and returns success or failure, as well as PayPal's response.
phred, <fred@redhotpenguin.com>
mock, <mock@obscurity.org>
CGI, perl, Apache::Session.
https://www.cansecwest.com/register.cgi is currently using this module to do conference registrations. If you wish to see it working, just fill out the forms until you get to the PayPal button, click on the button, and then cancel before paying (or pay, and come to CanSecWest :-) ).
Copyright (c) 2010, phred <fred@redhotpenguin.com>. All rights reserved.
Copyright (c) 2002, mock <mock@obscurity.org>. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Business-PayPal documentation | view source | Contained in the Business-PayPal distribution. |