0
votes

I am trying to get multiple items into the Express Checkout. I tried all kind of changes, but only the first item ('product name 1') appears in paypal with the amount 35$. How can i fix this to work with multiple items ? The code is this:

<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>
1
Need to see a sample of the raw NVP string that you're sending to PayPal.Drew Angell

1 Answers

0
votes

I had the same problem.

Their code in the demo only manually checks for one item with isset() in their CallShortcutExpressCheckout function in the paypal_functions.php file and it also changes the sum of the individual item it checks for to the total sum of all items in the paypal_ec_redirect.php, which is why it appears in your paypal with the amount 35$ for the one item it shows you.

You can change their code in the CallShortcutExpressCheckout function to use a foreach loop to loop through the post data instead manually checking for isset() on their predetermined parameters.

also you need to comment out where it changes the value of the of the product item amount to the total amount of all products.

Change the CallShortcutExpressCheckout in paypal_functions.php function from this:

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;
}

to this:

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;
}

and then just comment out this line on the paypal_ec_redirect.php:

//$_POST["L_PAYMENTREQUEST_0_AMT0"] = $_POST["PAYMENTREQUEST_0_ITEMAMT"]; 

Late answer, but i hope this helps someone :-)