paypal notify_url时的路线问题

时间:2012-11-28 17:17:40

标签: codeigniter paypal

我在施工中称之为。

function __construct()
{
    parent::__construct();

    if( !$this->authentication->authenticate( $this->router->class ) ) {
        redirect('clients/');
    }

    $this->load->model('client_model', 'client');
    $this->layout = 'layout/web/client';
}

当paypal NOTIFY_URL点击url时,我遇到问题,它不保存凭证,如果我从构造函数中删除它,它就可以工作。

function payment_notification()
{
    if( $this->input->post(NULL, TRUE) ) 
    {
        $this->saveintodb( $this->input->post() );          
    } else {
        show_error('Post data not found in request', 500);
    }
}

1 个答案:

答案 0 :(得分:0)

这里提供的信息不够......!

  • 确保将适当的notify_url发送至paypal
  • 如果启用了CSRF,Codeigniter将不允许该操作!
  • 您应该检查$ _POST数组而不是$ this-> input-> post()

<强> CONFIG.PHP

$config['uri_protocol'] = 'REQUEST_URI';
/*
|--------------------------------------------------------------------------
| Check to see if the request uri contains paypal
|--------------------------------------------------------------------------
*/
if( stripos($_SERVER["REQUEST_URI"],'/paypal') )
{
    $config['csrf_protection'] = FALSE;
}

- 的 routes.php文件

$route['paypal/notify'] = 'paypal/recieve_notification'; // www.mysite.com/paypal/notify

- 的控制器/ Paypal.php

class Paypal extends CI_Controller{

    public function __construct(){ parent::__construct(); }

    public function recieve_notification() //simplified function
    {
        try(
            if( !$_POST )
                throw new Exception('No POST data recieved from Paypal');

            if( $_POST['verified'] !== 'VERIFIED') //im guessing here
                throw new Exception('User not verified by paypal');


        )catch(Exception $e){
            //debugging: show_error($e->getMessage());
            log_message('error', $e->getMessage());
            redirect('/');
            exit;
        }

            //Save to DB
            $this->saveintodb( $_POST ); //expecting Exception thrown from DB ?

        $this->session->flashdata('success', 'Data Saved!');
        redirect('/');
    }


}