-
Notifications
You must be signed in to change notification settings - Fork 0
PayPal Lib
This library provides a neat and simple method to interface with PayPal and the PayPal Instant Payment Notification (IPN) interface. It requires the developer (that should be you) to understand the PayPal process and know the variables you want/need to pass to PayPal to achieve what you want.
This library needs the following configuration items to be present:
If (and where) to log IPN to file:
$config['paypal_lib_ipn_log_file'] = BASEPATH . 'logs/paypal_ipn.log';
$config['paypal_lib_ipn_log'] = TRUE;
Where are the buttons located at:
$config['paypal_lib_button_path'] = 'buttons';
What is the default currency?
$config['paypal_lib_currency_code'] = 'USD';
This library is loaded using the following code:
$this->load->library('paypal_lib');
PayPal_Lib requires the url and form helpers to be loaded.
The following functions are available:
Builds the hidden form values that will be sent to PayPal as POST variables. If the value is already in the array, it will be overwritten.
$this->paypal_lib->add_field('business', 'YOUR_PAYPAL_EMAIL_HERE');
$this->paypal_lib->add_field('return', site_url('paypal/success'));
$this->paypal_lib->add_field('cancel_return', site_url('paypal/cancel'));
$this->paypal_lib->add_field('notify_url', site_url('paypal/ipn'));
$this->paypal_lib->add_field('item_name', 'Paypal Test Transaction');<br />
$this->paypal_lib->add_field('item_number', '123');<br />
$this->paypal_lib->add_field('amount', '39.85');
Generates the PayPal form, based on the fields specified using add_field(). By default, the form name is "paypal_form" and the submit button's caption is "Pay now!".
$this->paypal_lib->paypal_form();
Optionally, you can specify the form name:
$this->paypal_lib->paypal_form('your_form_name');
This function actually generates an entire HTML page consisting of a form with hidden elements which is submitted to PayPal via the BODY element's onLoad attribute.
$this->paypal_lib->paypal_auto_form();
Changes the default caption of the submit button.
$this->paypal_lib->button('Click here to pay now (please)!');
Display a specified image button instead of regular submit button, based on the path specified in the config file.
$this->paypal_lib->image('button_01.gif');
Validates the data received from PayPal's IPN system and sends an confirmation of receipt back to PayPal This is where you update your database to activate or process the order, or setup the database with the user's order details, email an administrator, etc.
Access to the data sent is done via the ipn_data() array.
if ($this->paypal_lib->validate_ipn())
{
// Do something with the data
print_r($this->paypal_lib->ipn_data);
}
* Check the PayPal documentation for specifics on what information is available in the IPN POST variables. Basically, all the POST vars which PayPal sends, which we send back for validation, are now stored in the ipn_data() array.
Used for debugging, this function will output all the field/value pairs that are currently defined in the instance of the class using the add_field() function.
$this->paypal_lib->dump();
<!-- END CONTENT -->
Distributed under LGPL by Ran Aroussi (based on the Paypal PHP class by Micah Carrick).