cancel
Showing results for 
Search instead for 
Did you mean: 

Applying Discounts to Payment Orders

Member

Applying Discounts to Payment Orders

I would like to be able to apply discounts to payments to be shown in the Paypal payment authorization window. In the latest API version, aside from shipping discounts, there does not seem to be any way of applying discounts on payments when creating an order as documented in the create order API reference.

 

In the previous version, discount implementation can be done by simply putting a negative value in one of the payment items in the request body as shown below.

{
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "1900",
        "currency": "JPY",
      },
      "item_list": {
        "items": [
          {
            "name": "Sample Item Name",
            "quantity": "1",
            "price": "2000",
            "sku": "sample1",
            "currency": "JPY"
          },
          {
            "name": "Sample Discount",
            "quantity": "1",
            "price": "-100",
            "sku": "discount1",
            "currency": "JPY"
          }
        ],
      }
    }
  ],
  "redirect_urls": {
    "return_url": "https://example.com/return",
    "cancel_url": "https://example.com/cancel"
  }
}

I tried to apply a similar implementation to the new API version's request body for creating payment order as shown below.

{
  "intent": "authorize",
  "purchase_units": [
    {
      "amount": {
        "currency_code": "JPY",
        "value": "1900",
        "breakdown": {
          "item_total": {
            "currency_code": "JPY",
            "value": "1900",
          },
        },
      },
      "items": [
        {
          "name": "Sample Item Name",
          "unit_amount": {
            "currency_code": "JPY",
            "value": "2000",
          },
          "quantity": "1",
        },
        {
          "name": "Sample Discount",
          "unit_amount": {
            "currency_code": "JPY",
            "value": "-100",
          },
          "quantity": "1",
        }
      ],
    }
  ],
}

I was expecting it to work similar to the previous version, but I received an error response as shown below instead.

{
    "name": "UNPROCESSABLE_ENTITY",
    "details": [
        {
            "field": "/purchase_units/0/item/1/unit_amount/value",
            "value": "-100",
            "issue": "CANNOT_BE_NEGATIVE",
            "description": "Must be greater than or equal to 0. If the currency supports decimals, only two decimal place precision is supported."
        }
    ],
    "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
    "debug_id": "745c3cca484ea",
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/orders/v2/#error-CANNOT_BE_NEGATIVE",
            "rel": "information_link",
            "method": "GET"
        }
    ]
}

The item unit amount however, should be able to receive negative numbers as a monetary value as described in the corresponding API reference.

 

Is there a correct way of including custom discounts to be shown in the Paypal Payment authorization window?