Php 接收PaymentAction错误
我正在个人网站上进行我的第一次PayPal express签出,作为学习目的,我在网上找到了一个很好的教程,解释了如何构建快速签出。我正在使用本教程中提供的示例页面来更好地理解,但我收到了一个错误:PaymentAction:缺少必需的参数,我似乎无法跟踪问题 因此,我知道我必须发送PaymentAction参数,我将其作为销售发送。我不明白为什么它说我不会把它寄过来。我希望有人能发现编码中的错误,或者给出一个关于导致这种错误的原因的建议 $paymentType与下面代码中使用的一些其他变量一起存储在my config.php中 这就是我的$paymentType在我的config.php中的样子: $paymentType=‘销售’;//支付类型Php 接收PaymentAction错误,php,paypal,express-checkout,Php,Paypal,Express Checkout,我正在个人网站上进行我的第一次PayPal express签出,作为学习目的,我在网上找到了一个很好的教程,解释了如何构建快速签出。我正在使用本教程中提供的示例页面来更好地理解,但我收到了一个错误:PaymentAction:缺少必需的参数,我似乎无法跟踪问题 因此,我知道我必须发送PaymentAction参数,我将其作为销售发送。我不明白为什么它说我不会把它寄过来。我希望有人能发现编码中的错误,或者给出一个关于导致这种错误的原因的建议 $paymentType与下面代码中使用的一些其他变量一
<?php
session_start();
include_once("config.php");
include_once("paypal.class.php");
include ("../inc/settings.php");
$paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';
if($_POST) //Post Data received from product list page.
{
//Mainly we need 4 variables from product page Item Name, Item Price, Item Number and Item Quantity.
//Please Note : People can manipulate hidden field amounts in form,
//In practical world you must fetch actual price from database using item id. Eg:
//$ItemPrice = $mysqli->query("SELECT item_price FROM products WHERE id = Product_Number");
// Connect to DB
mysql_connect($server, $user, $pass) or die(mysql_error());
mysql_select_db($name) or die(mysql_error());
// Get the item price from the database
$result = mysql_query("SELECT * FROM admin_settings");
while($row = mysql_fetch_array( $result )) {
// Check how many credits they are buying
if ($_POST["itemnumber"] == 5) {
$ItemPrice = $row['five_credits'];
} else if ($_POST["itemnumber"] == 10) {
$ItemPrice = $row['ten_credits'];
} else if ($_POST["itemnumber"] == 20) {
$ItemPrice = $row['twenty_credits'];
} else if ($_POST["itemnumber"] == 30) {
$ItemPrice = $row['thirty_credits'];
}
}// end while
$ItemName = $_POST["itemname"]; //Item Name
//$ItemPrice = $_POST["itemprice"]; //Item Price
$ItemNumber = $_POST["itemnumber"]; //Item Number
$ItemDesc = $_POST["itemdesc"]; //Item Number
$ItemQty = $_POST["itemQty"]; // Item Quantity
$ItemTotalPrice = ($ItemPrice*$ItemQty); //(Item Price x Quantity = Total) Get total amount of product;
//Other important variables like tax, shipping cost
$TotalTaxAmount = 0; //2.58; //Sum of tax for all items in this order.
$HandalingCost = 0; //2.00; //Handling cost for this order.
$InsuranceCost = 0; //1.00; //shipping insurance cost for this order.
$ShippinDiscount = 0; //-3.00; //Shipping discount for this order. Specify this as negative number.
$ShippinCost = 0; //3.00; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate.
//Grand total including all tax, insurance, shipping cost and discount
// $GrandTotal = ($ItemTotalPrice + $TotalTaxAmount + $HandalingCost + $InsuranceCost + $ShippinCost + $ShippinDiscount);
$GrandTotal = $ItemTotalPrice;
//Parameters for SetExpressCheckout, which will be sent to PayPal
$padata = '&METHOD=SetExpressCheckout'.
'&RETURNURL='.urlencode($PayPalReturnURL ).
'&CANCELURL='.urlencode($PayPalCancelURL).
'&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode($paymentType).
'&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber).
'&L_PAYMENTREQUEST_0_DESC0='.urlencode($ItemDesc).
'&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice).
'&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty).
'&NOSHIPPING=1'. //set 1 to hide buyer's shipping address, in-case products that does not require shipping
'&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
'&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal).
'&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode).
'&LOCALECODE=US'. //PayPal pages to match the language on your website.
'&LOGOIMG=http://www.sanwebe.com/wp-content/themes/sanwebe/img/logo.png'. //site logo
'&CARTBORDERCOLOR=FFFFFF'. //border color of cart
'&ALLOWNOTE=0';
############# set session variable we need later for "DoExpressCheckoutPayment" #######
$_SESSION['ItemName'] = $ItemName; //Item Name
$_SESSION['ItemPrice'] = $ItemPrice; //Item Price
$_SESSION['ItemNumber'] = $ItemNumber; //Item Number
$_SESSION['ItemDesc'] = $ItemDesc; //Item Number
$_SESSION['ItemQty'] = $ItemQty; // Item Quantity
$_SESSION['ItemTotalPrice'] = $ItemTotalPrice; //(Item Price x Quantity = Total) Get total amount of product;
$_SESSION['GrandTotal'] = $GrandTotal;
//We need to execute the "SetExpressCheckOut" method to obtain paypal token
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
//Respond according to message we receive from Paypal
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
{
//Redirect user to PayPal store with Token received.
$paypalurl ='https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].'';
header('Location: '.$paypalurl);
}else{
//Show error message
echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
}
}
//Paypal redirects back to this page using ReturnURL, We should receive TOKEN and Payer ID
if(isset($_GET["token"]) && isset($_GET["PayerID"]))
{
//we will be using these two variables to execute the "DoExpressCheckoutPayment"
//Note: we haven't received any payment yet.
$token = $_GET["token"];
$payer_id = $_GET["PayerID"];
//get session variables
$ItemName = $_SESSION['ItemName']; //Item Name
$ItemPrice = $_SESSION['ItemPrice'] ; //Item Price
$ItemNumber = $_SESSION['ItemNumber']; //Item Number
$ItemDesc = $_SESSION['ItemDesc']; //Item Number
$ItemQty = $_SESSION['ItemQty']; // Item Quantity
$ItemTotalPrice = $_SESSION['ItemTotalPrice']; //(Item Price x Quantity = Total) Get total amount of product;
$GrandTotal = $_SESSION['GrandTotal'];
$padata = '&TOKEN='.urlencode($token).
'&PAYERID='.urlencode($payer_id).
'&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode($paymentType).
//set item info here, otherwise we won't see product details later
'&L_PAYMENTREQUEST_0_NAME0='.urlencode($ItemName).
'&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber).
'&L_PAYMENTREQUEST_0_DESC0='.urlencode($ItemDesc).
'&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice).
'&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty).
'&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
'&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal).
'&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode);
//We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
//Check if everything went ok..
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
{
echo '<h2>Success</h2>';
echo 'Your Transaction ID : '.urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]);
/*
//Sometimes Payment are kept pending even when transaction is complete.
//hence we need to notify user about it and ask him manually approve the transiction
*/
if('Completed' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
{
echo '<div style="color:green">Payment Received! Your product will be sent to you very soon!</div>';
echo '<div style="color:green">Add the code here to add credits to the user\'s account.</div>';
}
elseif('Pending' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
{
echo '<div style="color:red">Transaction Complete, but payment is still pending! '.
'You need to manually authorize this payment in your <a target="_new" href="http://www.paypal.com">Paypal Account</a></div>';
echo '<div style="color:red">Once you have authorized your payment manually, you will need to contact me via admin@etseo.net to apply the credits to your account. Due to your payment being blocked until authorized, credits can not be added automatically.</div>';
}
// we can retrive transection details using either GetTransactionDetails or GetExpressCheckoutDetails
// GetTransactionDetails requires a Transaction ID, and GetExpressCheckoutDetails requires Token returned by SetExpressCheckOut
$padata = '&TOKEN='.urlencode($token);
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('GetExpressCheckoutDetails', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
{
echo '<br /><b>Stuff to store in database :</b><br /><pre>';
/*
#### SAVE BUYER INFORMATION IN DATABASE ###
//see (http://www.sanwebe.com/2013/03/basic-php-mysqli-usage) for mysqli usage
$buyerName = $httpParsedResponseAr["FIRSTNAME"].' '.$httpParsedResponseAr["LASTNAME"];
$buyerEmail = $httpParsedResponseAr["EMAIL"];
//Open a new connection to the MySQL server
$mysqli = new mysqli('host','username','password','database_name');
//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$insert_row = $mysqli->query("INSERT INTO BuyerTable
(BuyerName,BuyerEmail,TransactionID,ItemName,ItemNumber, ItemAmount,ItemQTY)
VALUES ('$buyerName','$buyerEmail','$transactionID','$ItemName',$ItemNumber, $ItemTotalPrice,$ItemQTY)");
if($insert_row){
print 'Success! ID of last inserted record is : ' .$mysqli->insert_id .'<br />';
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
*/
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
} else {
echo '<div style="color:red"><b>GetTransactionDetails failed:</b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
}
}else{
echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
}
}
?>
显然,在SetExpress签出或DoExpress签出API调用中未传递PAYMENTREQUEST\u 0\u PAYMENTACTION。 尝试打印$paymentType,查看变量的作用域是否存在于配置文件中声明的$paymentType中。 或
声明此文件中的$paymentType='Sale'只是为了交叉检查。我花了将近4个小时,发现在获得令牌后,当paypal返回返回url时,会话被破坏 所以你得到了这个错误 解决方案:我将其用作返回url,而不是
问题已成功解决。我键入了单词sale而不是变量,但无效。我已经在sane文件中声明了,不起作用。当我在屏幕上打印$paymentType时,它显示为Sale。我不再需要这个问题的答案,因为我找到了一个更好的教程,教我如何自己编写代码。
Error : PaymentAction : Required parameter missing
Array
(
[TIMESTAMP] => 2014%2d02%2d22T14%3a41%3a42Z
[CORRELATIONID] => 57246c353bd81
[ACK] => Failure
[VERSION] => 109%2e0
[BUILD] => 9720069
[L_ERRORCODE0] => 81115
[L_SHORTMESSAGE0] => Missing%20Parameter
[L_LONGMESSAGE0] => PaymentAction%20%3a%20Required%20parameter%20missing
[L_SEVERITYCODE0] => Error
)