gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:46 25 4
gpt4 key购买 nike

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

由于库只包含项目的静态值,但我需要从我的购物车中获取项目,我如何才能将它们添加到 $this->paypal->add('T-衬衫',2.99,6);

我的 Controller 函数:

    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');


}

购物车 View :

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

最佳答案

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 库类,只是简单地硬编码一些产品

关于php - 如何在 codeigniter 中为 paypal 支付网关获取购物车值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28049314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com