我正在尝试将多个项目放入快速结账。我尝试了各种更改,但只有第一项("产品名称 1")出现在PayPal中,金额为 35 美元。如何解决此问题以处理多个项目?代码是这样的:
<form action="paypal_ec_redirect.php" method="POST">
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME0" value="product name 1"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_DESC0" value="this is the product description"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT0" value="10.00"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_NUMBER0" value="1"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY0" value="1"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME1" value="product name 2"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_DESC1" value="this is the product description"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT1" value="25.00"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_NUMBER1" value="2"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY1" value="1"></input>
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="35.00"></input>
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="35.00"></input>
<input type="hidden" name="currencyCodeType" value="USD"></input>
<input type="hidden" name="paymentType" value="Sale"></input>
<!--Pass additional input parameters based on your shopping cart. For complete list of all the parameters click here -->
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-large.png" alt="PayPal Credit"></input>
</form>
我遇到了同样的问题。
他们在演示中的代码仅在 PayPal_functions.php 文件中的 CallShortcutExpressCheckout 函数中使用 isset() 手动检查一个项目,并且它还将它检查的单个项目的总和更改为 PayPal_ec_redirect.php 中所有项目的总和,这就是为什么它出现在您的PayPal中,它显示的一个项目的金额为 35 美元。
您可以在 CallShortcutExpressCheckout 函数中更改其代码,以使用 foreach 循环遍历发布数据,而不是手动检查其预定参数上的 isset()。
此外,您还需要注释掉它将产品项目金额的值更改为所有产品总量的位置。
更改 PayPal_functions.php 函数中的 CallShortcutExpressCheckout
:function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL)
{
//------------------------------------------------------------------------------------------------------------------------------------
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
// For more information on the customizing the parameters passed refer: https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/
//Mandatory parameters for SetExpressCheckout API call
if(isset($paramsArray["PAYMENTREQUEST_0_AMT"])){
$nvpstr = "&PAYMENTREQUEST_0_AMT=". $paramsArray["PAYMENTREQUEST_0_AMT"];
$_SESSION["Payment_Amount"]= $paramsArray["PAYMENTREQUEST_0_AMT"];
}
if(isset($paramsArray["paymentType"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paramsArray["paymentType"];
$_SESSION["PaymentType"] = $paramsArray["paymentType"];
}
if(isset($returnURL))
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
if(isset($cancelURL))
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
//Optional parameters for SetExpressCheckout API call
if(isset($paramsArray["currencyCodeType"])) {
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $paramsArray["currencyCodeType"];
$_SESSION["currencyCodeType"] = $paramsArray["currencyCodeType"];
}
if(isset($paramsArray["PAYMENTREQUEST_0_ITEMAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_ITEMAMT=" . $paramsArray["PAYMENTREQUEST_0_ITEMAMT"];
$_SESSION['itemAmt']= $paramsArray["PAYMENTREQUEST_0_ITEMAMT"];
}
if(isset($paramsArray["PAYMENTREQUEST_0_TAXAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_TAXAMT=" . $paramsArray["PAYMENTREQUEST_0_TAXAMT"];
$_SESSION['taxAmt']= $paramsArray["PAYMENTREQUEST_0_TAXAMT"];
}
if(isset($paramsArray["PAYMENTREQUEST_0_SHIPPINGAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPPINGAMT=" . $paramsArray["PAYMENTREQUEST_0_SHIPPINGAMT"];
$_SESSION['shippingAmt'] = $paramsArray["PAYMENTREQUEST_0_SHIPPINGAMT"];
}
if(isset($paramsArray["PAYMENTREQUEST_0_HANDLINGAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_HANDLINGAMT=" . $paramsArray["PAYMENTREQUEST_0_HANDLINGAMT"];
$_SESSION['handlingAmt'] = $paramsArray["PAYMENTREQUEST_0_HANDLINGAMT"];
}
if(isset($paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPDISCAMT=" . $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
$_SESSION['shippingDiscAmt'] = $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
}
if(isset($paramsArray["PAYMENTREQUEST_0_INSURANCEAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_INSURANCEAMT=" . $paramsArray["PAYMENTREQUEST_0_INSURANCEAMT"];
$_SESSION['insuranceAmt'] = $paramsArray["PAYMENTREQUEST_0_INSURANCEAMT"];
}
if(isset($paramsArray["L_PAYMENTREQUEST_0_NAME0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NAME0=" . $paramsArray["L_PAYMENTREQUEST_0_NAME0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_NUMBER0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NUMBER0=" . $paramsArray["L_PAYMENTREQUEST_0_NUMBER0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_DESC0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_DESC0=" . $paramsArray["L_PAYMENTREQUEST_0_DESC0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_AMT0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_AMT0=" . $paramsArray["L_PAYMENTREQUEST_0_AMT0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_QTY0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_QTY0=" . $paramsArray["L_PAYMENTREQUEST_0_QTY0"];
if(isset($paramsArray["LOGOIMG"]))
$nvpstr = $nvpstr . "&LOGOIMG=". $paramsArray["LOGOIMG"];
/*
* Make the API call to PayPal
* If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
* If an error occured, show the resulting errors
*/
$resArray=hash_call("SetExpressCheckout", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$token = urldecode($resArray["TOKEN"]);
$_SESSION['TOKEN']=$token;
}
return $resArray;
}
对此:
function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL)
{
//------------------------------------------------------------------------------------------------------------------------------------
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
// For more information on the customizing the parameters passed refer: https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/
//Mandatory parameters for SetExpressCheckout API call
if(isset($returnURL))
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
if(isset($cancelURL))
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
foreach ($paramsArray as $k => $value){
$nvpstr = $nvpstr . "&" . $k . "=" . $value;
}
/*
* Make the API call to PayPal
* If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
* If an error occured, show the resulting errors
*/
$resArray=hash_call("SetExpressCheckout", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$token = urldecode($resArray["TOKEN"]);
$_SESSION['TOKEN']=$token;
}
return $resArray;
}
然后只需在 PayPal_ec_redirect.php 上注释掉这一行:
//$_POST["L_PAYMENTREQUEST_0_AMT0"] = $_POST["PAYMENTREQUEST_0_ITEMAMT"];
迟到的回答,但我希望这对某人有所帮助:-)