<?php

class Paypal extends Controller {

	function Paypal()
	{
		parent::Controller();
		$this->load->library('paypal_lib');
	}

	function index()
	{
		$this->form();
	}
        
        /* 手动提交和自动提交 只选其一即可 */

        // 手动提交 
	function form()
	{

	    $this->paypal_lib->add_field('business', 'gideon@****.com');
	    $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')); // <-- IPN url
	    $this->paypal_lib->add_field('custom', '1234567890'); // <-- Verify return

	    $this->paypal_lib->add_field('item_name', 'Paypal Transaction');
	    $this->paypal_lib->add_field('item_number', '6941');
	    $this->paypal_lib->add_field('amount', '197');

	    $this->paypal_lib->image('button_03.gif');

            $this->paypal_lib->sand_box(TRUE);   // 是否打开测试,默认为关闭
	    $data['paypal_form'] = $this->paypal_lib->paypal_form();

	    $this->load->view('paypal/form', $data);

	}

        // 自动提交
	function auto_form()
	{
	    $this->paypal_lib->add_field('business', 'gideon@****.com');
	    $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')); // <-- IPN url
	    $this->paypal_lib->add_field('custom', '1234567890'); // <-- Verify return

	    $this->paypal_lib->add_field('item_name', 'Paypal Transaction');
	    $this->paypal_lib->add_field('item_number', '6941');
	    $this->paypal_lib->add_field('amount', '197');

            $this->paypal_lib->sand_box(TRUE);   // 是否打开测试,默认为关闭
	    $this->paypal_lib->paypal_auto_form();
	}

        function cancel()
	{
		$this->load->view('paypal/cancel');
	}

	function success()
	{
		$data['pp_info'] = $_POST;
		$this->load->view('paypal/success', $data);
	}

	function ipn()
	{
		$to    = 'gideon@****.com';    //  your email

		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') . "\n\n";
			$body .= " Details:\n";

			foreach ($this->paypal_lib->ipn_data as $key=>$value)
				$body .= "\n$key: $value";

			// load email lib and email results
			$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('CI paypal_lib IPN (Received Payment)');
			$this->email->message($body);
			$this->email->send();
		}
	}
}
?>

 

 

附paypal library 包,(看了很多外网的建议,此版本为自己最终修改版)

 

官方文档:

http://aroussi.com/ci/paypal_lib/

 

 

 

PayPal is reporting: The seller accepts encrypted website payments only

This error is coming up because the PayPal profile is set to only accept payments from encrypted buttons.

 

To turn off this option:

  1. Log in to your account at https://www.paypal.com/ by entering your email address and password in the Member Login box
  2. Click the 'Profile' subtab
  3. Click on the 'Website Payment Preferences' link in the 'Selling Preferences' column
  4. In the section titled 'Encrypted Website Payments' select 'Off'
  5. Click 'Save'