[eluser]fnbhns[/eluser]
Hi Friends,
I am trying to integrate paypal with my site for single item. Its showing message "Error Detected The CART is empty". But whats the steps should i follow i am really not understanding, Need your kind support, if you give me support the steps, i am ready to do it newly.
Some code detail given below
Controller :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Paypal extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->library( 'Paypal_Lib' );
$this->load->library('cart');
}
function index(){
$this->load->view('payment');
}
function pay(){
$item_name = 'Sun Glass';
$price = '50';
$item_id = '001'; //'Product Id'
$quantity = 1;
$this->paypal_lib->add_field('business','[email protected]'); // Business Email
$this->paypal_lib->add_field('return',base_url().'returnpage'); // Return URL
$this->paypal_lib->add_field('cancel_return', base_url().'cancel'); // Cancel URL
$this->paypal_lib->add_field('notify_url', base_url().'ipn'); // <-- IPN url
$this->paypal_lib->add_field('custom', $item_id); // Optional
$this->paypal_lib->add_field('item_name', $item_name); // Product Name
$this->paypal_lib->add_field('quantity', $quantity); // Quantity
$this->paypal_lib->add_field('amount', $price); // Price
$this->paypal_lib->paypal_auto_form();
}
function returnpage(){
if(!$this->input->post('payer_id')){
echo "Success !!";
}else{
echo "Error !!";
}
}
function cancel(){
redirect(base_url().'paypal');
}
function ipn(){
$to = '[email protected]';
if ($this->paypal_lib->validate_ipn()) {
$body = 'An instant payment notification was successfully received from ';
$body .= $this->paypal_lib->ipn_data['payer_email'] .
' on '.date('m/d/Y') . ' at ' . date('g:i A') . "nn";
$body .= " Details:n";
foreach ($this->paypal_lib->ipn_data as $key=>$value)
$body .= "n$key: $value";
$this->load->library('email');
$this->email->to($to);
$this->email->from($this->paypal_lib->ipn_data['payer_email'],
$this->paypal_lib->ipn_data['payer_name']);
$this->email->subject('Received Payment');
$this->email->message($body);
$this->email->send();
}
}
}
The Libraries is Paypal_Lib :
Code:
class Paypal_Lib {
var $last_error;
var $ipn_log;
var $ipn_log_file;
var $ipn_response;
var $ipn_data = array();
var $fields = array();
var $submit_btn = '';
var $button_path = '';
var $CI;
function Paypal_Lib()
{
$this->CI =& get_instance();
$this->CI->load->helper('url');
$this->CI->load->helper('form');
$this->CI->load->config('paypallib_config');
$this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$this->last_error = '';
$this->ipn_response = '';
$this->ipn_log_file = $this->CI->config->item('paypal_lib_ipn_log_file');
$this->ipn_log = $this->CI->config->item('paypal_lib_ipn_log'); $this->button_path = $this->CI->config->item('paypal_lib_button_path');
$this->add_field('rm','2');
$this->multi_items('true');
$this->add_field('currency_code', $this->CI->config->item('paypal_lib_currency_code'));
//$this->add_field('quantity', '1');
$this->button('Pay Now!');
}
function button($value)
{
// changes the default caption of the submit button
$this->submit_btn = form_submit('pp_submit', $value);
}
function image($file)
{
$this->submit_btn = '<input type="image" name="add" src="' . site_url($this->button_path .'/'. $file) . '" border="0" />';
}
function add_field($field, $value)
{
$this->fields[$field] = $value;
//print_r($this->fields);
}
function paypal_auto_form()
{
$this->button('Click here if you\'re not automatically redirected...');
echo '<html>' . "\n";
echo '<head><title>Processing Payment...</title></head>' . "\n";
echo '<body >' . "\n";
echo '<p>Please wait, your order is being processed and you will be redirected to the paypal website.</p>' . "\n";
echo $this->paypal_form('paypal_auto_form');
echo '</body></html>';
}
paypal_form($form_name='paypal_form')
{
$str = '';
$str .= '<form method="post" acti name="'.$form_name.'"/>' . "\n";
foreach ($this->fields as $name => $value)
$str .= form_hidden($name, $value) . "\n";
$str .= '<p>'. $this->submit_btn . '</p>';
$str .= form_close() . "\n";
return $str;
}
...................
....................
Some other code is there
If your require any more information please let me know. Even if you give me support the steps, i am ready to do it newly these paypal.Thanking you in advance for your help. Looking forward.