GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Business::PayPal(3) User Contributed Perl Documentation Business::PayPal(3)

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.

Print button to the browser.

Note, button is an HTML form, already 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 = CGI->new;
  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 amount 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 = CGI->new;
  my $id = $query{custom};

  #get payment status from store for $id
  #return payment status to customer

In order to use the sandbox provided by PayPal, you can provide the address of the sandbox in the constructor:

  my $pp = Business::PayPal->new( address  => 'https://www.sandbox.paypal.com/cgi-bin/webscr' );

Creates a new Business::PayPal object, it can take the following parameters:
id
The Business::PayPal object id, if not specified a new id will be created using md5_hex(rand())
address
The address of PayPal's payment server, currently: https://www.paypal.com/cgi-bin/webscr
cert
The x509 certificate for address, see source for default.
certcontent
The contents of the x509 certificate cert, see source for default.
addcert
The x509 certificate for address. This is added to the default values.
addcertcontent
The contents of the x509 certificate cert, This is added to the default values.

Returns the id for the Business::PayPal object.

Returns the HTML for a PayPal button. It takes a large number of parameters, which control the look and function of the button, some of which are required and some of which have defaults. They are as follows:
cmd
required, defaults to '_ext-enter'

This allows the user information to be pre-filled in. You should never need to specify this, as the default should work fine.

redirect_cmd
required, defaults to '_xclick'

This allows the user information to be pre-filled in. You should never need to specify this, as the default should work fine.

button_image
required, defaults to:

    CGI::image_button(-name => 'submit',
                      -src  => 'http://images.paypal.com/x-click-but01.gif'
                      -alt  => 'Make payments with PayPal',
                     )
    

You may wish to change this if the button is on an https page so as to avoid the browser warnings about insecure content on a secure page.

for example use a Bootstrap style button:

  button_image  => '<button type="button" class="btn btn-success">9 USD per month</button>',
    
form_id
  form_id => 'some_id',
    

Adding id="some_id" to the form created. Adding and id will make it easier to locate the form on the page by some JavaScript code.

business
required, no default

This is the name of your PayPal account.

item_name
This is the name of the item you are selling.
item_number
This is a numerical id of the item you are selling.
image_url
A URL pointing to a 150 x 50 image which will be displayed instead of the name of your PayPal account.
no_shipping
defaults to 1

If set to 1, does not ask customer for shipping info, if set to 0 the customer will be prompted for shipping information.

return
This is the URL to which the customer will return to after they have finished paying.
cancel_return
This is the URL to which the customer will be sent if they cancel before paying.
no_note
defaults to 1

If set to 1, does not ask customer for a note with the payment, if set to 0, the customer will be asked to include a note.

currency_code
Currency the payment should be taken in, e.g. EUR, GBP. If not specified payments default to USD.
address1
undefined_quantity
defaults to 0

If set to 0 the quantity defaults to 1, if set to 1 the user can edit the quantity.

notify_url
The URL to which PayPal Instant Payment Notification is sent.
first_name
First name of customer, used to pre-fill PayPal forms.
last_name
Last name of customer, used to pre-fill PayPal forms.
shipping
I don't know, something to do with shipping, please tell me if you find out.
shipping2
I don't know, something to do with shipping, please tell me if you find out.
quantity
defaults to 1

Number of items being sold.

amount
Price of the item being sold.
address1
Address of customer, used to pre-fill PayPal forms.
address2
Address of customer, used to pre-fill PayPal forms.
city
City of customer, used to pre-fill PayPal forms.
state
State of customer, used to pre-fill PayPal forms.
zip
Zip of customer, used to pre-fill PayPal forms.
night_phone_a
Phone
night_phone_b
Phone
night_phone_c
Phone
day_phone_a
Phone
day_phone_b
Phone
day_phone_c
Phone
receiver_email
Email address of customer - I think
invoice
Invoice number - I think
custom
defaults to the Business::PayPal id

Used by Business::PayPal to track which button is associated with which Instant Payment Notification.

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.

Gabor Szabo, <http://szabgab.com/>, <http://perlmaven.com/>

phred, <fred@redhotpenguin.com>

mock, <mock@obscurity.org>

CGI, perl, Apache::Session.

Explanation of the fields: <http://www.paypalobjects.com/en_US/ebook/subscriptions/html.html> See also in the pdf here: <https://www.paypal.com/cgi-bin/webscr?cmd=p/xcl/rec/subscr-manual-outside>

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.

2020-03-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.