gpt4 book ai didi

Php Cart 没有转移到 Paypal

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

您好,我正在尝试创建一个在线电子商务商店,尽管有 paypal 购物车上传功能,但我一切正常,我一直在关注来自 developphp.com 的一系列视频这是我的文件 cart.php 中的代码

<?php
session_start();//start session first thing in script
//script error Reporting
error_reporting(E_ALL);
ini_set('display_errors','1');
//connect to mysql
include './store_scripts/DB_Connection.php';
?>
<?php
///////////////////////////////////////////////////////////////////////////////////
// Section 1 (if user attempts to add something to there cart from products) //
///////////////////////////////////////////////////////////////////////////////////
if(isset($_POST['p_code'])){
$p_code=$_POST['p_code'];
$wasFound = false;
$i=0;
//if cart session variable is not set or cart array is empty
if(!isset($_SESSION["Cart_Array"])||count($_SESSION["Cart_Array"])<1){
//run if the cart is empty or not set
$_SESSION["Cart_Array"]= array(0=>array("product_code" =>$p_code,"quantity" =>1));
}else{
//run if the cart has at least one item in it
foreach($_SESSION["Cart_Array"] as $each_item){
$i++;
while(list($key,$value) =each($each_item)){
if($key =="product_code" && $value==$p_code){
//That item is in the cart already so lets adjust its quantity using the array_splice()
array_splice($_SESSION["Cart_Array"],$i-1,1,array(array("product_code"=>$p_code,"quantity"=>$each_item['quantity'] + 1)));
$wasFound = true;
}//close if condition
}//close while loop
}//close foreach loop
if ($wasFound==false){
array_push($_SESSION["Cart_Array"],array("product_code"=>$p_code,"quantity"=> 1));
}
}
header("location:cart.php");
exit();
}
?>
<?php
////////////////////////////////////////////////////////////
// Section 2(if the user emptys there shopping cart) //
////////////////////////////////////////////////////////////
if (isset($_GET['cmd'])&&$_GET['cmd']=="emptycart")
unset($_SESSION["Cart_Array"]);
?>
<?php
/////////////////////////////////////////////////////////////////
// Section 3(if the user chooses to adjust item quantity) //
/////////////////////////////////////////////////////////////////
if (isset($_POST['item_to_adjust'])&&$_POST['item_to_adjust']!=""){
//execute some code
$item_to_adjust =$_POST['item_to_adjust'];
$quantity =$_POST['quantity'];
$quantity = preg_replace ('#[^0-9]#i','',$quantity);//filter everything but numbers
$i=0;
foreach($_SESSION["Cart_Array"] as $each_item){
$i++;
while(list($key,$value) =each($each_item)){
if($key =="product_code" && $value==$item_to_adjust){
//That item is in the cart already so lets adjust its quantity using the array_splice()
array_splice($_SESSION["Cart_Array"],$i-1,1,array(array("product_code"=>$item_to_adjust,"quantity"=>$quantity)));
}//close if condition
}//close while loop
}//close foreach loop
}

?>
<?php
////////////////////////////////////////////////////////////
// Section 4(If user wants to remove an item) //
////////////////////////////////////////////////////////////
if (isset($_POST['index_to_remove'])&& $_POST['index_to_remove']!=""){
//access the array and run code to remove that array index

$key_to_remove = $_POST['index_to_remove'];
if(count($_SESSION["Cart_Array"])<=1){
unset ($_SESSION["Cart_Array"]);
}else{
unset($_SESSION["Cart_Array"]["$key_to_remove"]);
sort($_SESSION["Cart_Array"]);
}
}
?>
<?php
////////////////////////////////////////////////////////////
// Section 5(render the cart for user to view) //
////////////////////////////////////////////////////////////
$cartOutput="";
$cartTotal ='';
$pp_checkout_btn ='';
if(!isset($_SESSION["Cart_Array"])||count($_SESSION["Cart_Array"])<1){
$cartOutput ="<h2 align='center'>Your Shopping Cart is empty</h2>";
}else{
//start paypal checkout button
$pp_checkout_btn.='<FORM ACTION="https://www.paypal.com/uk/cgi-bin/webscr" method="post"/>
<INPUT TYPE="hidden" name="cmd" value="_cart"/>
<INPUT TYPE="hidden" name="Upload" value="1">
<INPUT TYPE="hidden" name="Business" value="info@easterninspiration.co.uk"/>';
//start the foreach loop
$i =0;
foreach($_SESSION["Cart_Array"] as $each_item){

$Product_Name = $each_item['product_code'];
$sql=mysql_query("SELECT * FROM products WHERE product_name = '$Product_Name' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$item_price = $row["price"];
$details = $row["details"];
}
$Total_price =$item_price*$each_item['quantity'];
$cartTotal = $Total_price+$cartTotal;
$cart_VAT = 20/100*$cartTotal;
$postage = 5.00;
$final_Total = $cartTotal+$cart_VAT+$postage;
//dynamic checkout btn Assembly
$x =$i+1;
$pp_checkout_btn .= '<INPUT TYPE="hidden" name="item_name_' . $x . '" value="'.$Product_Name.'"/>
<INPUT TYPE="hidden" name="amount_ ' . $x . '" value="'.$item_price.'"/>
<INPUT TYPE="hidden" name="quantity_' . $x . '" value="'.$each_item['quantity'].'"/>';
//Dynamic table row assembly
$cartOutput .='<tr>';
$cartOutput .= '<td><a href="product.php?p_name='.$Product_Name.'">'.$Product_Name .'</a><br/><img src="product_images/'.$Product_Name.'.jpg" alt ="'.$Product_Name.'" width="70" height="70" border ="1"/></td>';
$cartOutput .='<td>'.$details.'</td>';
$cartOutput .='<td>£'.number_format($item_price,2).'</td>';
$cartOutput .='<td><form action ="cart.php" method ="post" >
<input name="quantity" type="text" value="'.$each_item['quantity'].'" size ="1" maxlength="2"/>
<input name="adjustBtn '.$Product_Name .'" type="Submit" style="width: auto; margin: 0 auto;" value="change '.$Product_Name.'">
<input name="item_to_adjust" type ="hidden" value="'.$Product_Name .'"/>
</form></td>';
$cartOutput .='<td>£'.number_format($Total_price,2).'</td>';
$cartOutput .='<td><form action ="cart.php" method ="post" ><input name="DeleteBtn '.$Product_Name .'" type="Submit" style="width: auto; margin: 0 auto;" value="Remove '.$Product_Name.'"><input name="index_to_remove" type ="hidden" value="'.$i.'"/></form></td>';
$cartOutput .='</tr>';
$i++;
}
$cartTotal = "<div style='color:red'; align='right'>Total excluding VAT: £".number_format($cartTotal,2)."</div>";
$cartTotal .="<div style='color:red'; align='right'>VAT: £".number_format($cart_VAT,2)."</div>";
$cartTotal .="<div style='color:red'; align='right'>Shipping: £".number_format($postage,2)."</div>";
$cartTotal .="<div style='color:red'; align='right'>Total: £".number_format($final_Total,2)."</div>";
//finish the paypal checkout button
$pp_checkout_btn .='<INPUT TYPE="hidden" name="notify_url" value="http://www.yoursite.com/storescripts/my_ipn.php"/>
<INPUT TYPE="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php"/>
<INPUT TYPE="hidden" name="rm" value="2"/>
<INPUT TYPE="hidden" name="cbt" value="Return to The Store"/>
<INPUT TYPE="hidden" name="cancel_return" value="https://www.yoursite.com/paypal_cancel.php"/>
<INPUT TYPE="hidden" name="lc" value="GB"/>
<INPUT TYPE="hidden" name="currency_code" value="GBP"/>
<INPUT TYPE="hidden" name="tax_cart" value="'.number_format($cart_VAT,2).'"/>
<INPUT TYPE="image" src="https://www.paypalobjects.com/WEBSCR-640-20110401-1/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110401-1/en_US/i/scr/pixel.gif" width="1" height="1">
</form>';
}
?>
<html>
<head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<Title>Your Shopping Cart</title>
</head>
<body>
<div align="center"id ="mainWrapper">
<?php include_once("template_header.php");?>
<div id ="pageContent">
<div style ="margin:24px;text-align:left;">

<table width="100%" border ="5" >
<tr>
<td width="7%" bgcolor="#0045f3"><B>Product</B></td>
<td width="47%" bgcolor="#0045f3"><B>Product Description</B></td>
<td width="10%" bgcolor="#0045f3"><B>unit Price</B></td>
<td width="9%" bgcolor="#0045f3"><B>Quantity</B></td>
<td width="7%" bgcolor="#0045f3"><B>Total</B></td>
<td width="9%" bgcolor="#0045f3"><B></B></td>
</tr>
<?php echo $cartOutput;?>

</table>

<br/>
<br/>
<a href="cart.php?cmd=emptycart">Click here to Empty your shopping cart</a>
</div>
<?php echo $cartTotal;?>
<br/>
<br/>
<?php echo $pp_checkout_btn;?>
<br/>
<br/>
</div>
<?php include_once('template_footer.php');?>
</div>
</body>
</html>

我在 Paypal 中遇到的错误如下:由于卖家网站出现问题,PayPal 无法处理此交易。请直接联系卖家解决此问题

我非常感谢我能得到的所有帮助

问候

库纳维尔玛

最佳答案

UploadBusiness 参数应该小写——例如:

$pp_checkout_btn.='<FORM ACTION="https://www.paypal.com/uk/cgi-bin/webscr" method="post"/>
<INPUT TYPE="hidden" name="cmd" value="_cart"/>
<INPUT TYPE="hidden" name="Upload" value="1">
<INPUT TYPE="hidden" name="Business" value="info@easterninspiration.co.uk"/>';

应该是:

$pp_checkout_btn.='<FORM ACTION="https://www.paypal.com/uk/cgi-bin/webscr" method="post"/>
<INPUT TYPE="hidden" name="cmd" value="_cart"/>
<INPUT TYPE="hidden" name="upload" value="1">
<INPUT TYPE="hidden" name="business" value="info@easterninspiration.co.uk"/>';

关于Php Cart 没有转移到 Paypal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18740740/

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