Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带CodeIgniter的PayPal IPN_Php_Codeigniter_Paypal_Paypal Ipn - Fatal编程技术网

Php 带CodeIgniter的PayPal IPN

Php 带CodeIgniter的PayPal IPN,php,codeigniter,paypal,paypal-ipn,Php,Codeigniter,Paypal,Paypal Ipn,我正在尝试在一个内置CodeIgniter的网站上实现会员订阅服务。我希望使用PayPal来管理付款,我在实现这一点上遇到了困难 我努力实现的目标是: 用户使用 个人资料 用户选择一个 订阅选项(8个选项中的1个-每个不同的价格)并提交表格 用户被发送到PayPal进行支付 用户在成功付款后返回站点,个人详细信息存储在创建用户帐户(会员资格)的数据库中 另外还有表单验证,我在CodeIgniter中使用表单验证助手,但这需要在PayPal支付开始之前完成 我曾尝试从Ran Aroussi实现Pa

我正在尝试在一个内置CodeIgniter的网站上实现会员订阅服务。我希望使用PayPal来管理付款,我在实现这一点上遇到了困难

我努力实现的目标是:

  • 用户使用 个人资料
  • 用户选择一个 订阅选项(8个选项中的1个-每个不同的价格)并提交表格
  • 用户被发送到PayPal进行支付
  • 用户在成功付款后返回站点,个人详细信息存储在创建用户帐户(会员资格)的数据库中
  • 另外还有表单验证,我在CodeIgniter中使用表单验证助手,但这需要在PayPal支付开始之前完成

    我曾尝试从Ran Aroussi实现PayPal_库,但我觉得它没有足够清晰的文档或指导。任何实施的示例或建议都将不胜感激


    Lucas

    下面是Jamie Rumme提供的paypal库,我对其进行了一些小调整:


    下面是我在Ran的库中使用的未经修改的代码。 希望能有帮助

    <?php
    /**
     * PayPal_Lib Controller Class (Paypal IPN Class)
     *
     * Paypal controller that provides functionality to the creation for PayPal forms, 
     * submissions, success and cancel requests, as well as IPN responses.
     *
     * The class requires the use of the PayPal_Lib library and config files.
     *
     * @package     CodeIgniter
     * @subpackage  Libraries
     * @category    Commerce
     * @author      Ran Aroussi <ran@aroussi.com>
     * @copyright   Copyright (c) 2006, http://aroussi.com/ci/
     *
     */
    
    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', 'herrka_1245670546_biz@pandorascode.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', '470874552'); // <-- Verify return
    
            $this->paypal_lib->add_field('item_name', 'Paypal Test Transaction');
            $this->paypal_lib->add_field('item_number', '5');
            $this->paypal_lib->add_field('amount', '9.95');
    
            // if you want an image button use this:
            $this->paypal_lib->image('button_03.gif');
    
            // otherwise, don't write anything or (if you want to 
            // change the default button text), write this:
            // $this->paypal_lib->button('Click to Pay!');
    
            $data['paypal_form'] = $this->paypal_lib->paypal_form();
    
            $this->load->view('paypal/form', $data);
    
        }
    
        function cancel()
        {
            $this->load->view('paypal/cancel');
        }
    
        function success()
        {
            //$data['pp_info'] = $this->input->post();
            $data['pp_info'] = $_POST; //FIX?
            $this->load->view('paypal/success', $data);
        }
    
        function ipn()
        {
    
            $ipn_valid = $this->paypal_lib->validate_ipn();
            if ( $ipn_valid == TRUE )
            {
    
    
                /**
                    Log IPN
                    TODO: bunu daha guzel gozukecek sekilde yapayim ilerde.
                **/
                date_default_timezone_set('Europe/Istanbul');
                $this->load->helper('date');
    
                $raw = '';
                foreach ($this->paypal_lib->ipn_data as $key=>$value)
                {
                    $raw .= "\n$key: $value";
                }
    
                $this->load->model('model_paypal');
    
                $data_ipn['user_id']            = $this->paypal_lib->ipn_data['custom']; /* get USER_ID from custom field. */
                $data_ipn['txn_id']             = $this->paypal_lib->ipn_data['txn_id'];
                $data_ipn['payment_status']     = $this->paypal_lib->ipn_data['payment_status'];
                $data_ipn['mc_gross']           = $this->paypal_lib->ipn_data['mc_gross'];
                $data_ipn['mc_fee']             = $this->paypal_lib->ipn_data['mc_fee'];
                $data_ipn['mc_currency']        = $this->paypal_lib->ipn_data['mc_currency'];
                $data_ipn['item_number']        = $this->paypal_lib->ipn_data['item_number'];
                $data_ipn['datetime']           = mdate( "%Y-%m-%d %H:%i:%s" );
                $data_ipn['status']             = IPN_ENTRY_AWAITING;
                $data_ipn['raw']                = $raw;
    
                $this->model_paypal->ipn_entry_add ( $data_ipn );
    
    
    
                $ipn_payment_status = $this->paypal_lib->ipn_data['payment_status'];
                if ( strtolower($ipn_payment_status) == 'pending' )
                {
    
    
                    log_message('debug', 'payment status TAMAM');
                    $this->load->model('model_user_premium');
    
    
                    $ipn_item_number    = $this->paypal_lib->ipn_data['item_number'];
                    $item_info          = $this->model_user_premium->Premium_item_info ( $ipn_item_number );
    
                    $ipn_mc_gross       = $this->paypal_lib->ipn_data['mc_gross'];
    
                    log_message('debug', 'Item fee: '. $item_info['item_fee'] );                
    
                    if ( $item_info['item_fee'] == $ipn_mc_gross ) 
                    {
    
                        log_message('debug', 'fee ile gross TAMAM');
    
    
    
                        $data_account['user_id']        = $data_ipn['user_id'];
                        $data_account['type']           = $item_info['item_type'];
                        $data_account['date_expire']    = date("Y-m-d", mktime(0, 0, 0, date("m") + $item_info['date_extender'], date("d"), date("y") ) ); 
    
    
                        log_message('debug', 'UserID: '.    $data_account['user_id']        );
                        log_message('debug', 'Type:'.       $data_account['type']           );
                        log_message('debug', 'Expire:'.     $data_account['date_expire']    );
    
    
                        $this->model_user_premium->Premium_membership_change( $data_ipn['user_id'], $data_account );
    
                    }
                    else
                    {
    
                        //TODO: report eksik transaction.
    
                    }
    
                }
    
    
    
            }
            elseif ( $ipn_valid == FALSE )
            {
    
                $this->load->library('email');
                $this->email->to( 'demo@demo.com' );
                $this->email->subject('IPN - FAILED');
                $this->email->from( 'notify@bulusturx.com', 'PAYPAL' );
                $this->email->message('or 4 life'); 
    
                $this->email->send();
    
            }
    
    
        }
    
        function ipn_list()
        {
            //TODO: admin check
            $this->load->helper('form');
            $this->load->model('model_theme');
    
            switch ( $_SERVER['REQUEST_METHOD'] ) 
            {
    
                case 'GET':
    
                    /* Theme System with Reference Variable ( first param ) */
                    $this->model_theme->Theme_returnThemeInfo( $data, 'paypal' );
                    $this->load->view( $data['theme_folder_vault'] . 'master-ipn_list', $data );
    
    
                break;
    
                case 'POST':
    
                    $this->load->model('model_paypal');
                    $user_id    = $this->input->post('user_id');
                    $txn_id     = $this->input->post('txn_id');
    
                    $list_ipn = $this->model_paypal->ipn_entry_list ( $user_id, $txn_id );
    
                    echo '<pre>';
                    print_r( $list_ipn );
                    echo '</pre>';
    
    
                break;
    
    
                default:
                break;
            }
    
    
        }
    
    
        function ipn_test()
        {
    
            $this->load->model('model_user_premium');
    
            $data_account['user_id']        = 123;
            $data_account['type']           = 4;
            $data_account['date_expire']    = date("Y-m-d", mktime(0, 0, 0, date("m") + 12, date("d"), date("y") ) );
    
            echo '<pre>';
            print_r( $data_account );
            echo '</pre>';
    
    
            $this->model_user_premium->Premium_membership_change( 123, $data_account );
    
        }
    
    }
    
    ?>
    

    我发现Ran的库也有点难以使用,因此我编写了一个替换库,它还可以对事务执行更多检查,并将IPN调用和订单详细信息记录在数据库中。这是GitHub上的库,我希望您会发现它很有用:


    Paypal是一个相对难以使用的API。我个人会使用像DPS这样的服务。如果您将“if($this->CI->input->post()”)更改为“if(isset($\u post))”,则该库工作正常。你犯了什么错误?做得好Alex。然而,你们有一个不需要条令的版本吗?嗨,布莱恩,是的,现在有一个版本不需要条令