Search code examples
phppaypalpaypal-sandbox

How to show multiple items on Paypal


It is possible to show all the items that we have in the shopping cart on paypal ??

For example (This is inside of paypal already):
5 Paddle Boards -- Price of those 5 items
3 Surf Shirts -- Price

TOTAL PRICE: total price

My code :

 <form name="frm_customer_detail" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
    <input type='hidden'name='business' value='sb-unhom7091284@business.example.com'> 
    <input type='hidden' name='item_name' value='Prancha Surf'> 
    <input type='hidden' name='amount' value='<?php echo $item_price; ?>'> 
    <input type='hidden' name='quantity' value='<?php echo $item_quantity; ?>'> 
    <input type='hidden' name='currency_code' value='EUR'> 
    <input type="hidden" name="cmd" value="_xclick">  

    <input type="hidden" name="order" value="<?php echo $order;?>">
    <div>
        <input type="submit" class="btn-action"
                name="continue_payment" value="Continue Payment">
    </div>
</form>

My $item_price it's the total of all products.
And the $item_quantity it's the quantity of all products that you have on cart.
I know that I need to change cmd value to _cart, but it's missing a lot of things here right ? Thanks in advance


Solution

  • Cart upload (_cart) is a very old (20 years?), deprecated integration method that doesn't give a good checkout experience.

    The best solution is to use a smart button; see the current guide at Set up standard payments, particularly the section on extending the order creation with more detail:

    createOrder: function(data, actions) {
          return actions.order.create({
             "purchase_units": [{
                "amount": {
                  "currency_code": "USD",
                  "value": "100",
                  "breakdown": {
                    "item_total": {  /* Required when including the `items` array */
                      "currency_code": "USD",
                      "value": "100"
                    }
                  }
                },
                "items": [
                  {
                    "name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
                    "description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
                    "unit_amount": {
                      "currency_code": "USD",
                      "value": "50"
                    },
                    "quantity": "2"
                  },
                ]
              }]
          });
        },
    

    Since you are using a PHP backend, for best results you should do this order creation and capture from your server via API instead of in the JS. There are notes in that guide for how to do a server integration and connect it to the JS with fetch(, see the demo linked there.