Hallo,
Ik heb voor het upgraden van packages een Paypal API.
Werkt gewoon tot toebehoren. Alleen als op de pagina komt na de betaling (Return URL) krijg ik een error, maar de package wordt wel toegevoegd. Hoe zorg ik dat die error verdwijnt?
Code
Error : This transaction cannot be processed. The amount to be charged is zero.
Array
(
[TIMESTAMP] => 2012%2d11%2d28T16%3a21%3a41Z
[CORRELATIONID] => 89923af7f3542
[ACK] => Failure
[VERSION] => 76%2e0
[BUILD] => 4181146
[L_ERRORCODE0] => 10525
[L_SHORTMESSAGE0] => Invalid%20Data
[L_LONGMESSAGE0] => This%20transaction%20cannot%20be%20processed%2e%20The%20amount%20to%20be%20charged%20is%20zero%2e
[L_SEVERITYCODE0] => Error
)
Success
Your Transaction ID :3HD13476S0937414R
Payment Received! Your product will be sent to you very soon!
You will be redicted to the dashboard.
Toon Meer
Script:
PHP
<?php
session_start();
include_once("config.php");
include_once("paypal.class.php");
?>
<!-- Here goes the content. -->
<section id="content" class="container_12 clearfix" data-sort="true">
<div class="grid_12">
<div class="box">
<div class="header"><h2>Paypal Checkout</h2></div>
<div class="content">
<?php
if($_GET) //Post Data received from product list page.
{
//Mainly we need 4 variables from an item, Item Name, Item Price, Item Number and Item Quantity.
$ItemName = mysql_real_escape_string($_GET["itemname"]); //Item Name
$ItemPrice = mysql_real_escape_string($_GET["itemprice"]); //Item Price
$ItemNumber = mysql_real_escape_string($_GET["itemnumber"]); //Item Number
$ItemQty = mysql_real_escape_string($_GET["itemQty"]); // Item Quantity
$ItemTotalPrice = ($ItemPrice*$ItemQty); //(Item Price x Quantity = Total) Get total amount of product;
//Data to be sent to paypal
$padata = '&CURRENCYCODE='.urlencode($PayPalCurrencyCode).
'&PAYMENTACTION=Sale'.
'&ALLOWNOTE=1'.
'&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode).
'&PAYMENTREQUEST_0_AMT='.urlencode($ItemTotalPrice).
'&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
'&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty).
'&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice).
'&L_PAYMENTREQUEST_0_NAME0='.urlencode($ItemName).
'&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber).
'&AMT='.urlencode($ItemTotalPrice).
'&RETURNURL='.urlencode($PayPalReturnURL ).
'&CANCELURL='.urlencode($PayPalCancelURL);
//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"]))
{
// If successful set some session variable we need later when user is redirected back to page from paypal.
$_SESSION['itemprice'] = $ItemPrice;
$_SESSION['totalamount'] = $ItemTotalPrice;
$_SESSION['itemName'] = $ItemName;
$_SESSION['itemNo'] = $ItemNumber;
$_SESSION['itemQTY'] = $ItemQty;
if($PayPalMode=='sandbox')
{
$paypalmode = '.sandbox';
}
else
{
$paypalmode = '';
}
//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"];
$playerid = $_GET["PayerID"];
//get session variables
$ItemPrice = $_SESSION['itemprice'];
$ItemTotalPrice = $_SESSION['totalamount'];
$ItemName = $_SESSION['itemName'];
$ItemNumber = $_SESSION['itemNo'];
$ItemQTY =$_SESSION['itemQTY'];
$padata = '&TOKEN='.urlencode($token).
'&PAYERID='.urlencode($playerid).
'&PAYMENTACTION='.urlencode("SALE").
'&AMT='.urlencode($ItemTotalPrice).
'&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 '<h1>Success</h2>';
echo 'Your Transaction ID :'.urldecode($httpParsedResponseAr["TRANSACTIONID"]);
/*
//Sometimes Payment are kept pending even when transaction is complete.
//May be because of Currency change, or user choose to review each payment etc.
//hence we need to notify user about it and ask him manually approve the transiction
*/
if('Completed' == $httpParsedResponseAr["PAYMENTSTATUS"])
{
echo '<div style="color:green">Payment Received! Your product will be sent to you very soon!<br>You will be redicted to the dashboard. </div><meta http-equiv="refresh" content="4;URL=dashboard.php" />';
}
elseif('Pending' == $httpParsedResponseAr["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>';
}
$transactionID = urlencode($httpParsedResponseAr["TRANSACTIONID"]);
$nvpStr = "&TRANSACTIONID=".$transactionID;
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('GetTransactionDetails', $nvpStr, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
#### SAVE BUYER INFORMATION IN DATABASE ###
$buyerName = $httpParsedResponseAr["FIRSTNAME"].' '.$httpParsedResponseAr["LASTNAME"];
$buyerEmail = $httpParsedResponseAr["EMAIL"];
$buyerCountry = $httpParsedResponseAr['COUNTRYCODE'];
$buyerStatus = $httpParsedResponseAr['PAYMENTSTATUS'];
$user_id = $user_info['id'];
mysql_query("INSERT INTO orders
(BuyerName,BuyerEmail,TransactionID,ItemNumber,ItemAmount,ItemQTY,Country,Status,Date)
VALUES
('$buyerName','$buyerEmail','$transactionID','$ItemNumber','$ItemTotalPrice','$ItemQTY','$buyerCountry','$buyerStatus','.NOW().')");
mysql_query("UPDATE users SET pack_id = '$ItemNumber' WHERE id = '$user_id'");
} 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>';
}
}
?>
</div><!-- End of .content -->
</div><!-- End of .box -->
</div><!-- End of .grid_4 -->
</section><!-- End of #content -->
Toon Meer