我刚接近paypal快速结账,我有这个代码支付给paypal
$resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
RedirectToPayPal ( $resArray["TOKEN"] );
}
else
{
//Display a user friendly Error on the page using any of the following error information returned by PayPal
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo "SetExpressCheckout API call failed. ";
echo "Detailed Error Message: " . $ErrorLongMsg;
echo "Short Error Message: " . $ErrorShortMsg;
echo "Error Code: " . $ErrorCode;
echo "Error Severity Code: " . $ErrorSeverityCode;
}
这是CallShortcutExpressCheckout函数的代码
function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL)
{
//------------------------------------------------------------------------------------------------------------------------------------
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
$nvpstr="&PAYMENTREQUEST_0_AMT=". $paymentAmount;
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
$_SESSION["currencyCodeType"] = $currencyCodeType;
$_SESSION["PaymentType"] = $paymentType;
//'---------------------------------------------------------------------------------------------------------------
//' 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;
}
我的问题,我不知道如何发送购物车完整信息,如产品标题和代码,它是我需要的因为我没有订单部分到我的购物车我想通过电子邮件管理一切 所以我需要的是通过订单发送产品描述,一旦我收到订单的订单,电子邮件确认有项目描述
答案 0 :(得分:0)
我正在尝试做同样的事情。
首先我要说的是,我一直试图让完整的结账工作2天,而且我还没有完全成功:(
然而,看起来我比你更进一步。
不确定这是否是正确的方法,但我会告诉你我现在得到的以及我仍然遇到的问题。
我做的是以下内容:
如果用户点击结帐按钮,则调用php文件(让我们称之为checkout.php
)。
在checkout.php
文件中,我使用用户想要订购的项目构建array
。
// fill array with two products
// normally you would loop through all products in the basket to create this array
$items = array('L_PAYMENTREQUEST_0_NAME0'=>'Productname 1',
'L_PAYMENTREQUEST_0_NUMBER0'=>'Productcode 1',
'L_PAYMENTREQUEST_0_DESC0'=>'Productdescription 1',
'L_PAYMENTREQUEST_0_AMT0'=>39.99, // price per unit
'L_PAYMENTREQUEST_0_QTY0'=>2, // quantity
'L_PAYMENTREQUEST_0_NAME1'=>'Productname 2',
'L_PAYMENTREQUEST_0_NUMBER1'=>'Productcode 2',
'L_PAYMENTREQUEST_0_DESC1'=>'Productdescription 2',
'L_PAYMENTREQUEST_0_AMT1'=>200.99,
'L_PAYMENTREQUEST_0_QTY1'=>1,
);
// set total amount of order in session (this will be used by paypal throughout the payment process)
$_SESSION['Payment_Amount'] = 280.97;
// now normally call CallShortcutExpressCheckout only with the addition of the $items array
$resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items);
现在,对于具有实际向PayPal发出请求的函数的文件:
我创建了一个额外的函数(generate_nvp_string
)并更改了CallShortcutExpressCheckout
函数以使用此字符串。
function generate_nvp_string($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items = array())
{
$params = array('PAYMENTREQUEST_0_AMT'=>$paymentAmount,
'PAYMENTREQUEST_0_PAYMENTACTION'=>$paymentType,
'RETURNURL'=>$returnURL,
'CANCELURL'=>$cancelURL,
'PAYMENTREQUEST_0_CURRENCYCODE'=>$currencyCodeType,
);
$params = array_merge($params, $items);
$nvp_string = '';
foreach($params as $name => $value) {
$nvp_string.= '&'.$name.'='.$value;
}
return $nvp_string;
}
function CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items= array())
{
$_SESSION['currencyCodeType'] = $this->currency;
$_SESSION['PaymentType'] = $this->payment_type;
$result = $this->hash_call('SetExpressCheckout', $this->generate_nvp_string($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items));
$ack = strtoupper($result['ACK']);
if ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') {
$_SESSION['TOKEN'] = urldecode($result['TOKEN']);
}
return $result;
}
现在,当用户点击结帐按钮时,请求字符串也会包含产品。当用户被重定向到PayPal结账时,他们将对所有订购的产品有一个很好的概述。
我用以下内容开始了这个答案:
我还有什么问题。
结帐流程似乎现在可以正常工作,但是当用户完成结帐流程并被重定向回我的网站($returnURL
)并且由于某种原因没有获得交易ID时。
交易ID对于能够在后端进一步处理付款至关重要。
答案 1 :(得分:0)
我试图使用表单提交来遍历项目。 PayPal的示例代码仅适用于1个项目。我只是检查是否设置了L_PAYMENTREQUEST_0_NAME0,而不是像PeeHaa那样设置函数,如果是,则将所有变量添加到$ nvpstr字符串中。然后继续查看是否设置了L_PAYMENTREQUEST_0_NAME1,如果是,则将其添加到字符串中,等等。以下是需要它的人的代码:
for($i=0; $i<99999; $i++){
if(isset($paramsArray["L_PAYMENTREQUEST_0_NAME$i"])){
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NAME$i=" . $paramsArray["L_PAYMENTREQUEST_0_NAME$i"];
}
if(isset($paramsArray["L_PAYMENTREQUEST_0_NUMBER$i"])){
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NUMBER$i=" . $paramsArray["L_PAYMENTREQUEST_0_NUMBER$i"];
}
if(isset($paramsArray["L_PAYMENTREQUEST_0_DESC$i"])){
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_DESC$i=" . $paramsArray["L_PAYMENTREQUEST_0_DESC$i"];
}
if(isset($paramsArray["L_PAYMENTREQUEST_0_AMT$i"])){
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_AMT$i=" . $paramsArray["L_PAYMENTREQUEST_0_AMT$i"];
}
if(isset($paramsArray["L_PAYMENTREQUEST_0_QTY$i"])){
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_QTY$i=" . $paramsArray["L_PAYMENTREQUEST_0_QTY$i"];
}
if(!isset($paramsArray["L_PAYMENTREQUEST_0_NAME$i"])){
break;
}
}