如何在codeigniter中为paypal支付网关获取购物车价值

时间:2015-01-20 15:37:29

标签: php codeigniter paypal

我坚持在codeigniter上集成paypal支付网关  我正在使用当前的库 https://github.com/romaldyminaya/ci_paypal

由于图书馆仅包含项目的静态值,但我需要获取来自我的购物车的商品,我如何才能将它们带到 $ this-> paypal-> add('短衫”,2.99,6);

我的控制器功能:

    public function do_purchase(){

    $config['business']             = 'babar.seller@gmail.com';
        $config['cpp_header_image']     = ''; //Image header url [750 pixels wide by 90 pixels high]
        $config['return']               = 'http://localhost/final-project/index.php/mysite/modify_payment';
        $config['cancel_return']        = 'http://final-project/mysite/canceled.php';
        $config['notify_url']           = 'process_payment.php'; //IPN Post
        $config['production']           = FALSE; //Its false by default and will use sandbox
        $config["invoice"]              = random_string('numeric',8); //The invoice id

        $this->load->library('paypal',$config);

        #$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);

        $this->paypal->add('T-shirt',2.99,6); //First item
        $this->paypal->add('Pants',40);       //Second item
        $this->paypal->add('Blowse',10,10,'B-199-26'); //Third item with code


        $this->paypal->pay(); //Proccess the payment

    }

    public function modify_payment(){


        $received_data = print_r($this->input->post(),TRUE);
        echo "<pre>".$received_data."<pre>";

                $this->load->view('mysite/modify_payment',$received_data);

        }

public function cart()

    {
        $cart = $this->cart->contents();
        //print_r($cart);
        //die;
      //$data['user_id']=$this->mainmodel->get_user_i($user_id);    

        $this->load->view('mysite/cart');
        $this->load->view('mysite/include/footer');


    }

购物车视图

    <?php $i = 1; ?>

<?php foreach ($this->cart->contents() as $items): ?>

    <?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
    <tr>
<td>         <input name="qty[<?php echo $items['rowid'];?>]" id="qty" type="text" value="<?php echo $items['qty']?>" class="input" />
</td>
      <td>
        <?php echo $items['name']; ?>

            <?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>

                <p>
                    <?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>

                        <strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />

                    <?php endforeach; ?>
                </p>

            <?php endif; ?>

1 个答案:

答案 0 :(得分:0)

function add($item_name = '',$item_amount = NULL,$item_qty = NULL,$item_number = NULL){
        $this->config['item_name_'.$this->item]     = $item_name;
        $this->config['amount_'.$this->item]        = $item_amount;
        $this->config['quantity_'.$this->item]      = $item_qty;
        $this->config['item_number_'.$this->item]   = $item_number;
        $this->item++;
    }   

我所做的是有一个paypal库类处理添加,只是简单地硬编码了一些产品