简体   繁体   中英

Add discount to Paypal payment

i'm using Paypal PHP SDK (in Laravel) to prepare a payment. At the moment, that payment looks like this:

{
   "intent":"sale",
   "payer":{
      "payment_method":"paypal"
   },
   "redirect_urls":{
      "return_url":"http://website.lab/payment/paypal/success",
      "cancel_url":"http://website.lab/payment/paypal/cancel"
   },
   "transactions":[
      {
         "amount":{
            "currency":"EUR",
            "total":"223",
            "details":{
               "shipping":"0",
               "subtotal":"273"
            }
         },
         "description":"...",
         "item_list":{
            "items":[
               {
                  "name":"product 8",
                  "currency":"EUR",
                  "quantity":21,
                  "sku":"w9",
                  "price":"13.00"
               }
            ],
            "shipping_address":{
               "city":"...",
               "postal_code":"...",
               "country_code":"...",
               "recipient_name":"...",
               "line1":"..."
            }
         }
      }
   ]
}

As you can see there are 50€ missing from the total to the subtotal and this cause this error

400{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].amount","issue":"Transaction amount details (subtotal, tax, shipping) must add up to specified amount total"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"91d27597e954"}

Now looking to the Paypal SDK i'm not able to find any sort of method/Object that can tell Paypal to add a discount to the subtotal.
Any help will be appreciate, i really can't find any resource on the web that can solve this problem

You can add an item to your "item_list" with a negative value to the transaction:

{
    "name": "Discount",
    "price": "-50",
    "currency": "EUR",
    "quantity": "1"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM