0

我正在使用一个框架来处理 PayPal。此代码在 Sandbox 上运行良好,但是当我尝试使用实时模式付款时,它向我显示:

Array
(
    [TIMESTAMP] => 2013%2d01%2d09T22%3a21%3a12Z
    [CORRELATIONID] => a6af5582b727d
    [ACK] => Failure
    [VERSION] => 94%2e0
    [BUILD] => 4181146
    [L_ERRORCODE0] => 10400
    [L_SHORTMESSAGE0] => Transaction%20refused%20because%20of%20an%20invalid%20argument%2e%20See%20additional%20error%20messages%20for%20details%2e
    [L_LONGMESSAGE0] => Order%20total%20is%20missing%2e
    [L_SEVERITYCODE0] => Error
)

我不知道我做错了什么。API 密钥是正确的。该框架将这些变量发送到 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);  

我希望你能帮助我

这是所有代码:

如果我 "echo" $padata 一些值是空的,比如 "AMT"。

&TOKEN=EC-2TW28437TX702052X&PAYERID=T9FV73NEH3UU2&PAYMENTACTION=SALE&AMT=&CURRENCYCODE=MXN

现在代码:

<?php $articulo = "Proceso Finalizado"; ?>
<?php include ('header.php'); ?>
<div id="contenido">
<?php
session_start();
include_once("config.php");
include_once("paypal.class.php");


if($_POST) //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 = $_POST["itemname"]; //Item Name
    $ItemPrice = $_POST["itemprice"]; //Item Price
    $ItemNumber = $_POST["itemnumber"]; //Item Number
    $ItemQty = $_POST["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);  
        $padatafin = $padata;
        //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'];
    $nombre2        = $_SESSION['nombre'];
    $apellidos2     = $_SESSION['apellidos'];
    $edad2          = $_SESSION['edad'];
    $sexo2          = $_SESSION['sexo'];
    $telefono2      = $_SESSION['telefono'];
    $celular2       = $_SESSION['celular'];
    $email2         = $_SESSION['email'];
    $dir2           = $_SESSION['dir'];
    $colonia2       = $_SESSION['colonia'];
    $cp2            = $_SESSION['cp'];
    $ciudad2        = $_SESSION['ciudad'];
    $pais2          = $_SESSION['pais'];
    $confirmacion   = urldecode($httpParsedResponseAr["TRANSACTIONID"]);
    $fecha          = date("j, n, Y"); 
    $cantidad       = $_SESSION['itemQTY'];

    $padata =           
                        '&TOKEN='.urlencode($token).
                        '&PAYERID='.urlencode($playerid).
                        '&PAYMENTACTION='.urlencode("SALE").
                        '&AMT='.urlencode($ItemTotalPrice).
                        '&CURRENCYCODE='.urlencode($PayPalCurrencyCode);
                                    echo '<pre>';
            print_r($padata);
            echo '</pre>';

    //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>Transacción Exitosa</h2>';

            $con = mysql_connect("localhost","cruxcong","gress12AdT");
            if (!$con)
              {
                die('Could not connect: ' . mysql_error());
              }
            mysql_select_db("pagopaypal", $con);
            mysql_query("SET NAMES 'utf8'");
            mysql_query("INSERT INTO asistentes (confirmacion, fecha, paquete, Cantidad, nombre, apellidos, edad, sexo, telefono, celular, email, dir, colonia, cp, ciudad, pais)
            VALUES ('".urldecode($httpParsedResponseAr["TRANSACTIONID"])."','$fecha','$ItemName','$cantidad','$nombre2','$apellidos2','$edad2','$sexo2','$telefono2','$celular2','$email2','$dir2','$colonia2','$cp2','$ciudad2','$pais2')");
            mysql_close($con);

                /*
                //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 '¡El pago ha sido hecho! tu número de confirmación es: <div style="color:red"><b>' .urldecode($httpParsedResponseAr["TRANSACTIONID"]).'</b></div> El cual deberás de presentar junto con una identificación oficial para tener acceso al congreso.';
                }
                elseif('Pending' == $httpParsedResponseAr["PAYMENTSTATUS"])
                {
                    echo 'Transacción Completada, pero el pago todavía está pendiente! Necesitas autorizarlo manualmente en tu <a target="_new" href="http://www.paypal.com">Cuenta de PayPal</a>.<br /><br /> Tu número de confirmación es: <div style="color:red"><b>' .urldecode($httpParsedResponseAr["TRANSACTIONID"]).'</b></div> El cual deberás de presentar junto con una identificación oficial para tener acceso al congreso, una vez que hayas confirmado el pago.';
                }

                echo "<p><b>IMPRIME ESTA DOCUMENTO COMO COMPROBANTE DE PAGO</b></p>";
                echo "<form><input type=\"button\" name=\"imprimir\" value=\"Imprimir\" onclick=\"window.print();\"> </form> <br />";
                $con = mysql_connect("localhost","cruxcong","gress12AdT");
            if (!$con)
              {
                die('Could not connect: ' . mysql_error());
              }
            mysql_select_db("pagopaypal", $con);
            mysql_query("SET NAMES 'utf8'");
            $result = mysql_query("SELECT * FROM asistentes WHERE confirmacion='".urldecode($httpParsedResponseAr["TRANSACTIONID"])."'");
            while($row = mysql_fetch_array($result))
              {     
              echo "<b>Fecha de compra: </b>".$row['fecha']."<br>";   
              echo "<b>Paquete: </b>".$row['paquete']."<br>";
              echo "<b>Cantidad de boletos: </b>".$row['Cantidad']."<br><br>";  
              echo "<b>Nombre: </b>".$row['nombre'] . " " . $row['apellidos']."<br>";
              echo "<b>Edad: </b>".$row['edad']."<br>";
              echo "<b>Sexo: </b>".$row['sexo']."<br>";
              echo "<b>Teléfono: </b>".$row['telefono']."<br>";
              echo "<b>Celular: </b>".$row['celular']."<br>";
              echo "<b>Email: </b>".$row['email']."<br>";
              echo "<b>Dirección: </b>".$row['dir']."<br>";
              echo "<b>Colonia: </b>".$row['colonia']."<br>";
              echo "<b>Código Postal: </b>".$row['cp']."<br>";
              echo "<b>Ciudad: </b>".$row['ciudad']."<br>";
              echo "<b>País: </b>".$row['pais'];

              echo "<br>";
              }
            mysql_close($con);


            //echo '<br /><b>Stuff to store in database :</b><br /><pre>';

                $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"];

                    $conn = mysql_connect("localhost","MySQLUsername","MySQLPassword");
                    if (!$conn)
                    {
                     die('Could not connect: ' . mysql_error());
                    }

                    mysql_select_db("Database_Name", $conn);

                    mysql_query("INSERT INTO BuyerTable 
                    (BuyerName,BuyerEmail,TransactionID,ItemName,ItemNumber, ItemAmount,ItemQTY)
                    VALUES 
                    ('$buyerName','$buyerEmail','$transactionID','$ItemName',$ItemNumber, $ItemTotalPrice,$ItemQTY)");

                    mysql_close($con);
                    */

                    //echo '<pre>';
                    //print_r($httpParsedResponseAr);
                    //echo '</pre>';
                } else  {
                    echo '<h2>No se ha podido realizar la transacción</h2>';
                    echo '<p>Asegúrate de haber seleccionado correctamente un paquete, o bien que tu tarjeta de débito, crédito o cuenta de PayPal tenga fondos suficientes para realizar la transacción</p>';

                }

    }else{  
            echo '<pre>';
            print_r($padata);
            echo '</pre>';

            echo "<br /><br />";
            print_r($httpParsedResponseAr);
            echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
            echo '<pre>';
            print_r($httpParsedResponseAr);
            echo '</pre>';
    }
}
?>
</div>
</div>
</body>
</html>
<?php session_destroy(); ?>
4

0 回答 0