Public Member Functions | Data Fields
PayPal Class Reference

Provides a paypal interface wrapper. More...

Public Member Functions

 PayPal ()
 
 createForm ($business, $item_name, $currency_code, $price, $submit=null, $action=null)
 
 formSet ($fields, $value= '')
 
 formAction ($action)
 
 recurringPaymentType ($type, $every=1)
 
 redirectAfter ($seconds)
 
 formIpn ($ipn_url)
 
 formExtend ()
 
 formOutput ()
 
 headersNoCache ()
 
 ipnPaymentData ($key=null)
 
 ipnPostedData ($key=null)
 
 validIpn ($paypalurl=self::PPURL)
 

Data Fields

const SANDBOX = 'https://sandbox.paypal.com/cgi-bin/webscr'
 
const ACTIVE = 'https://www.paypal.com/cgi-bin/websrc'
 
const PPURL = 'www.paypal.com'
 
const PPSBURL = 'sandbox.paypal.com'
 
 $form_fields = array()
 
 $form_submit_image = null
 
 $form_action = ''
 
 $form_redirect = 10
 
 $ipn_posted_data
 
 $ipn_payment_data = array()
 

Detailed Description

Provides a paypal interface wrapper.

Version
1.2
Author
DinuSV

Usage

// Paypal form usage
$paypal = new PayPal();
$paypal->createForm( 'mybusiness', 'itemnumber33', 'USD', 20 );
// if you want a recurring payment type
$paypal->recurringPaymentType('M');
$paypal->redirectAfter( 0 );
$paypal->formIpn('myurl');
$paypal->formOutput();
// Paypal ipn usage
$paypal = new PayPal();
try {
if ( $paypal->validIpn() ){
//get id of the item the payment was made for
$id = $paypal->ipnPostedData( 'item_number' );
} else
//payment not successful
} catch( Exception $e ){
// Invalid IPN
}

Member Function Documentation

PayPal ( )

Construct

createForm (   $business,
  $item_name,
  $currency_code,
  $price,
  $submit = null,
  $action = null 
)

Creates a form based on the required fields

Parameters
string$business: email adress for the paypal account
string$item_name: name of the item or shopping cart( must be 127 characters max )
string$currency_code: defines the currency in which the monetary variables are denoted
string$price: price of the item or the total price of all items in the shopping cart
Tag$submit: [optional] the button for the buyer to press in order to initiate the process. The default will be the paypal button 'x-click-but01.gif' from their website.
string$action: [optional] the location the form will be submited to. The default value is https://www.paypal.com/cgi-bin/websrc
Returns
PayPal : current object
formSet (   $fields,
  $value = '' 
)

Set fields for the form

Parameters
string$fields: field name
array$fields: array of field names and values to set
string$value: [optional]field value
Returns
PayPal : current object
formAction (   $action)

Set form action, PayPal::SANDBOX, PayPal::ACTIVE can be used

Parameters
string$action
Returns
PayPal : current object
recurringPaymentType (   $type,
  $every = 1 
)

Set the payment type : once a day, a month, a year or just one payment

Parameters
string$type: once / day / month / year
integer$every: [optional] enable recurring payment for every number of years/months/days
redirectAfter (   $seconds)

Redirect the form to paypal after a set number of seconds

Parameters
integer$seconds
Returns
PayPal : current object
formIpn (   $ipn_url)

Set paypals instant payment notification

Parameters
string$ipn_url
Returns
PayPal : current object
formExtend ( )

Set the paypal form to the extended version in order to support more arguments

Returns
PayPal : current object
formOutput ( )

Generate the form and output it

headersNoCache ( )

Function call recomended in order to disable caching before outputing the form

ipnPaymentData (   $key = null)

Get ipn payment data after the ipn has been processed

Parameters
string$key: [optional]set to null in order to return all the values as an array
Exceptions
IndexOutOfBoundsException
Returns
array : returns an empty array if the fields haven't been set
string : returns the value if a key is given
ipnPostedData (   $key = null)

Get posted data from paypal after the ipn has been processed

Parameters
string$key: [optional]set to null in order to return all the values as an array
Exceptions
IndexOutOfBoundsException
Returns
array : returns an empty array if the fields haven't been set
string : returns the value if a key is given
validIpn (   $paypalurl = self::PPURL)

Checks is the request is a valid ipn from paypal

Parameters
string$paypalurl: [optional] paypal url to post data to
Exceptions
PageNotFoundException: in case the paypal connection can't be established
IncompleteActionException: in case the ipn verification failed
Returns
boolean : true if it's a valid Ipn, false otherwise

Field Documentation

SANDBOX = 'https://sandbox.paypal.com/cgi-bin/webscr'

string : Paypal sandbox post link

ACTIVE = 'https://www.paypal.com/cgi-bin/websrc'

string : Paypal active post link

PPURL = 'www.paypal.com'

string : Paypal url

PPSBURL = 'sandbox.paypal.com'

string : Paypal developer url

$form_fields = array()

array : Fields that will be posted to paypal

$form_submit_image = null

string : Custom submit button

$form_action = ''

string : Paypal form action, can be either the paypal sandbox url or the original one

$form_redirect = 10

string : Submit the form using javascript after a set number of seconds. Set this to 0 to disable autosubmitting

$ipn_posted_data

string : The posted data received by the ipn request

$ipn_payment_data = array()

string : Payment data processed from the posted data received by ipn