0
votes

Before someone marks as duplicate, i have read all the other posts regarding adding multiple items to express checkout and have not been able to solve my issue.

I am using a working shopping cart demo supplied by PayPal, though all their demos or documentation only provide examples with a single item added to the cart, it's not possible in the demos to add multiple items. No where can i find any documentation on how to add multiple items properly.

In the code below(directly taken from paypal demo but with an additional product i added) it allows the transaction to be valid, but when the user logs into their paypal account it only displays the first product, BUT also the price of that product is the total of the two products.

for example it displays as follows:

  • DSLR Camera $20.00 USD
  • Tax $2.00 USD
  • Shipping $5.00 USD
  • Shipping discount $-3.00 USD
  • Handling $1.00 USD
  • Insurance $2.00 USD
  • Total $27.00 USD

It doesn't show the second product. Any ideas? thanks

Code:

<!--Form containing item parameters and seller credentials needed for SetExpressCheckout Call-->
<form class="form" action="paypal_ec_redirect.php" method="POST">
   <div class="row-fluid">
      <div class="span6 inner-span">
            <!--Demo Product details -->
            <table>
            <tr><h3> DIGITAL SLR CAMERA </h3></tr>
            <tr><img src="img/camera.jpg" width="300" height="250"/></tr>
            <tr><td><p class="lead"> Buyer Credentials:</p></td></tr>
            <tr><td>Email-id:&nbsp;&nbsp;&nbsp;<input type="text" id="buyer_email" name="buyer_email" readonly></input> </td></tr>
            <tr><td>Password:<input type="text" id="buyer_password" name="buyer_password" readonly></input></td></tr>
            </table>
      </div>
      <div class="span6 inner-span">
            <p class="lead"> Item Specifications:</p>
            <table>

            <!-- First item -->
            <tr><td>Item Name:</td><td><input type="text" name="L_PAYMENTREQUEST_0_NAME0" value="DSLR Camera"></input></td></tr>
            <tr><td>Item ID: </td><td><input type="text" name="L_PAYMENTREQUEST_0_NUMBER0" value="A0123"></input></td></tr>
            <tr><td>Description:</td><td><input type="text" name="L_PAYMENTREQUEST_0_DESC0" value="Autofocus Camera"></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_QTY0" value="1" readonly></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_AMT0" value="10.00" readonly></input></td></tr>


            <!-- Second item -->
            <tr><td>Item Name:</td><td><input type="text" name="L_PAYMENTREQUEST_0_NAME1" value="Item 2"></input></td></tr>
            <tr><td>Item ID: </td><td><input type="text" name="L_PAYMENTREQUEST_0_NUMBER1" value="12345"></input></td></tr>
            <tr><td>Description:</td><td><input type="text" name="L_PAYMENTREQUEST_0_DESC1" value="Description"></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_QTY1" value="1" readonly></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_AMT1" value="10.00" readonly></input></td></tr>


            <tr><td>Price:</td><td><input type="text" name="PAYMENTREQUEST_0_ITEMAMT" value="20.00" readonly></input></td></tr>
            <tr><td>Tax:</td><td><input type="text" name="PAYMENTREQUEST_0_TAXAMT" value="2" readonly></input></td></tr>
            <tr><td>Shipping Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_SHIPPINGAMT" value="5" readonly></input></td></tr>
            <tr><td>Handling Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_HANDLINGAMT" value="1" readonly></input></td></tr>
            <tr><td>Shipping Discount:</td><td><input type="text" name="PAYMENTREQUEST_0_SHIPDISCAMT" value="-3" readonly></input></td></tr>
            <tr><td>Insurance Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_INSURANCEAMT" value="2" readonly></input></td></tr>
            <tr><td>Total Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_AMT" value="27" readonly></input></td></tr>
            <tr><td><input type="hidden" name="LOGOIMG" value=<?php echo('http://'.$_SERVER['HTTP_HOST'].preg_replace('/index.php/','img/logo.jpg',$_SERVER['SCRIPT_NAME'])); ?>></input></td></tr>
            <tr><td>Currency Code:</td><td><select name="currencyCodeType">
            <option value="AUD">AUD</option>
            <option value="BRL">BRL</option>
            <option value="CAD">CAD</option>
            <option value="CZK">CZK</option>
            <option value="DKK">DKK</option>
            <option value="EUR">EUR</option>
            <option value="HKD">HKD</option>
            <option value="MYR">MYR</option>
            <option value="MXN">MXN</option>
            <option value="NOK">NOK</option>
            <option value="NZD">NZD</option>
            <option value="PHP">PHP</option>
            <option value="PLN">PLN</option>
            <option value="GBP">GBP</option>
            <option value="RUB">RUB</option>
            <option value="SGD">SGD</option>
            <option value="SEK">SEK</option>
            <option value="CHF">CHF</option>
            <option value="THB">THB</option>
            <option value="USD" selected>USD</option><br></td></tr>
            <tr><td>Payment Type: </td><td><select>
                                               <option value="Sale">Sale</option>
                                               <option value="Authorization">Authorization</option>
                                               <option value="Order">Order</option>
                                             </select><br></td></tr>

            <tr><td colspan="2"><br/><br/><div id="myContainer"></div></td></tr>
            <tr><td> -- OR -- </td></tr>
            <tr><td ><input type="Submit" alt="Proceed to Checkout" class="btn btn-primary btn-large" value="Proceed to Checkout" name="checkout"/></td></tr>
            </table>
      </div>
   </div>
</form>
1
How is your paypal_ec_redirect.php handling the POST payload of the above?EdSF
I figured out the problem, it's purposely made to only accept one item in the paypal_functions.php. not sure why they would do that. I did post my answer to my question if you are curios. thanksuser3796133

1 Answers

0
votes

I figured it out, their demo code only manually checks for one item in the post data.

The POST data and return and cancel URLs are sent to a CallShortcutExpressCheckout function (paypal_functions.php) that only checks for predetermined parameters rather than actually looping through any of the POST data.

For example it only manually checks for if a parameter issset(), but only for one item:

function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL) {

        //it manually checks for all the paramters, i just have shown one for example
        if(isset($paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"])){
            $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPDISCAMT=" . $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
            $_SESSION['shippingDiscAmt'] = $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
        }

        //And here it only looks for one item
        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"];

I just deleted all the code and put in a simple foreach loop:

function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL) 
{

    if(isset($returnURL))
    $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;

    if(isset($cancelURL))
    $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;

    foreach ($paramsArray as $k => $value){
        $nvpstr = $nvpstr . "&" . $k . "=" . $value;
    }

And on top of that, for some reason in the paypal_ec_redirect.php they make sure to change the individual product item amount to the sum of all items amount as if to make sure that only one item is being sent, otherwise it throws a totals of the cart item amounts do not match order amounts (Error Code: 10413).

I just commented it out and everything works great now and i can place multiple item orders.

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

I hope this helps someone, i did see another stackoverflow question with the exactsame problem. Why they would make their demo code to purposely only accept one item is beyond me.