CodeIgniter 合作paypal

<?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'

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值