paypalpaypal-rest-sdk

How to handle PayPal orders with no shipping data


I'm using the PayPal REST API to create and process orders of a software product. Even though we don't ship the product, we use the purchase_units/0/shipping data to compute tax after the order has been placed by pulling it from the /v2/checkout/orders/ endpoint.

This has worked for hundreds of orders with no problem but recently an order came in where the shipping object was null. Is that supposed to be possible? And if so, what is the correct way to pull the order's country of origin in order to compute the tax?


Solution

  • If nothing tangible is being shipped, you don't need a shipping address as part of the transaction. Best not even collect one and set the item category as DIGITAL_GOODS for tracking purposes.

    {
      "intent": "CAPTURE",
      "purchase_units": [
        {
          "amount": {
            "currency_code": "USD",
            "value": "10",
            "breakdown": {
              "item_total": {
                "currency_code": "USD",
                "value": "10"
              }
            }
          },
          "items": [
            {
              "category": "DIGITAL_GOODS",
              "name": "Name of Item #1 (can be viewed in the upper-right dropdown during payment approval)",
              "description": "Optional description; item details will also be in the completed paypal.com transaction view",
              "unit_amount": {
                "currency_code": "USD",
                "value": "10"
              },
              "quantity": "1"
            }
          ]
        }
      ],
      "payment_method": {
        "paypal" : {
          "shippig_preference":"NO_SHIPPING" 
        }
      }
    }
    

    The billing country of the payer is returned at

    payment_source.paypal.address.country_code