API /v2/checkout/orders shipping not added to total

icicic
Contributor
Contributor

I'm sending the following to the orders endpoint, but the total requested does not include shipping, what do i need to change:

{
  "intent": "CAPTURE",
  "application_context": {
    "return_url": "https://mydomain.localhost/cart/checkout-success",
    "cancel_url": "https://mydomain.localhost/cart/checkout-success"
  },
  "purchase_units": [
    {
      "items": [
        {
          "name": "Cubik",
          "description": "Lorem ipsum dolor sit ame",
          "quantity": 1,
          "unit_amount": { "currency_code": "GBP", "value": "10" }
        },
        {
          "name": "product 1",
          "description": "Lorem ipsum dolor sit ame",
          "quantity": 1,
          "unit_amount": { "currency_code": "GBP", "value": "15" }
        }
      ],
      "amount": {
        "value": 25,
        "currency_code": "GBP",
        "breakdown": {
          "item_total": {
            "currency_code": "GBP",
            "value": "25",
            "shipping": "4.50"
          }
        }
      }
    }
  ]
}

 

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

MTS_Chiranjeevi
Moderator
Moderator

@icicic 

 

Yes , "Shipping" is an object which needs to include "currency_code & value" inside "breakdownobject


Happy to hear that your issue is resolved. 

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

View solution in original post

Login to Me Too
4 REPLIES 4

MTS_Chiranjeevi
Moderator
Moderator

Good day @icicic,

 

Thank you for your post and welcome to the Community Forum.

 

I could see that you have placed the "Shipping" under "item_totalobject


Can you please try placing the "Shipping"object inside "breakdownobject

 

Guide link - https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown 

 

Sincerely,

Chiranjeevi

PayPal/Braintree MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too

icicic
Contributor
Contributor

Thank you, but it fails

'{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"e7477312020e8","details":[{"field":"\/purchase_units\/0\/amount\/breakdown\/shipping","location":"body","issue":"MALFORMED_REQUEST_JSON","description":"The request JSON is not well formed."}],"links":[{"href":"https:\/\/developer.paypal.com\/docs\/api\/orders\/v2\/#error-MALFORMED_REQUEST_JSON","rel":"information_link","encType":"application\/json"}]}

 

Array
(
    [intent] => CAPTURE
    [application_context] => Array
        (
            [return_url] => https://myhost.localhost/cart/checkout-response1
            [cancel_url] => https://myhost.localhost/cart/checkout-response1
        )
    [purchase_units] => Array
        (
            [0] => Array
                (
                    [items] => Array
                        (
                            [0] => Array
                                (
                                    [name] => Cubik
                                    [description] => Lorem ipsum dolor sit ame
                                    [quantity] => 1
                                    [unit_amount] => Array
                                        (
                                            [currency_code] => GBP
                                            [value] => 10
                                        )
                                )
                            [1] => Array
                                (
                                    [name] => Lorem ipsum
                                    [description] => Lorem ipsum dolor sit ame
                                    [quantity] => 1
                                    [unit_amount] => Array
                                        (
                                            [currency_code] => GBP
                                            [value] => 15
                                        )
                                )
                        )
                    [amount] => Array
                        (
                            [value] => 25
                            [currency_code] => GBP
                            [breakdown] => Array
                                (
                                    [item_total] => Array
                                        (
                                            [currency_code] => GBP
                                            [value] => 29.5
                                        )
                                    [shipping] => 4.50
                                )
                        )
                )
        )
)

 

Login to Me Too

icicic
Contributor
Contributor

 

 

 

Array
(
    [intent] => CAPTURE
    [application_context] => Array
        (
            [return_url] => https://myhost.localhost/cart/checkout-response1
            [cancel_url] => https://myhost.localhost/cart/checkout-response1
        )
    [purchase_units] => Array
        (
            [0] => Array
                (
                    [items] => Array
                        (
                            [0] => Array
                                (
                                    [name] => Lorem
                                    [description] => Lorem ipsum dolor sit ame
                                    [quantity] => 1
                                    [unit_amount] => Array
                                        (
                                            [currency_code] => GBP
                                            [value] => 10
                                        )
                                )
                            [1] => Array
                                (
                                    [name] => Lorem2
                                    [description] => Lorem ipsum dolor sit ame
                                    [quantity] => 1
                                    [unit_amount] => Array
                                        (
                                            [currency_code] => GBP
                                            [value] => 15
                                        )
                                )
                        )
                    [amount] => Array
                        (
                            [value] => 29.5
                            [currency_code] => GBP
                            [breakdown] => Array
                                (
                                    [item_total] => Array
                                        (
                                            [currency_code] => GBP
                                            [value] => 25
                                        )
                                    [shipping] => Array
                                        (
                                            [value] => 4.50
                                            [currency_code] => GBP
                                        )
                                )
                        )
                )
        )
)

 

got it, shipping needs to be an object and include currency_code

Login to Me Too
Solved

MTS_Chiranjeevi
Moderator
Moderator

@icicic 

 

Yes , "Shipping" is an object which needs to include "currency_code & value" inside "breakdownobject


Happy to hear that your issue is resolved. 

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.