Search code examples
phppaypalpaypal-sandbox

PAYPAL php SDK1.0.1, how to set NO_SHIPPING


I'm making an ecommerce website, which sells only digital things (no shipping). So I tried to set the "shipping_preferences" key to "NO_SHIPPING" inside the request creation, but it doesn't seem to work (it doesn't give any error). I'm following the documentation here.

PHP code (buildRequestBody):

function buildRequestBody()
{
    return array(
          'intent' => 'CAPTURE',
          'purchase_units' =>
                array(
                  0 =>
                    array(
                      'amount' =>
                        array(
                          'currency_code' => 'EUR',
                          'value' => '150.00'
                        ),

                      'payee' =>
                        array(
                          'email_address' => 'sb-qloys3515897@business.example.com'
                          )

                  )
                ),
                
          'order_application_context' =>
             array(
               'shipping_preferences' => 'NO_SHIPPING'
             )
            );
}

Here is the returned json, (there isn't anything related to shipping, so during the checkout it still asks for the address)

{
  "statusCode": 201,
  "result": {
    "id": "23K326254X491844S",
    "intent": "CAPTURE",
    "status": "CREATED",
    "purchase_units": [
      {
        "reference_id": "default",
        "amount": {
          "currency_code": "EUR",
          "value": "150.00"
        },
        "payee": {
          "email_address": "sb-qloys3515897@business.example.com"
        }
      }
    ],
    "create_time": "2020-10-23T19:52:24Z",
    "links": [
      {
        "href": "https://api.sandbox.paypal.com/v2/checkout/orders/23K326254X491844S",
        "rel": "self",
        "method": "GET"
      },
      {
        "href": "https://www.sandbox.paypal.com/checkoutnow?token=23K326254X491844S",
        "rel": "approve",
        "method": "GET"
      },
      {
        "href": "https://api.sandbox.paypal.com/v2/checkout/orders/23K326254X491844S",
        "rel": "update",
        "method": "PATCH"
      },
      {
        "href": "https://api.sandbox.paypal.com/v2/checkout/orders/23K326254X491844S/capture",
        "rel": "capture",
        "method": "POST"
      }
    ]
  },
  "headers": {
    "": "",
    "Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
    "Content-Length": "718",
    "Content-Type": "application/json",
    "Date": "Fri, 23 Oct 2020 19",
    "Paypal-Debug-Id": "cc5deeef2624d"
  }
}

I also tried 'application_context' instead of 'order_application_context', but it gave me the same result (the checkout asks for the shipping address, and the json is the same as before)

Here is the modified PHP code:

return array(
          'intent' => 'CAPTURE',
          'application_context' =>
            array(
              'shipping_preferences' => 'NO_SHIPPING'
              //'user_action' => 'PAY_NOW'
            ),
          'purchase_units' =>
                array(
                  0 =>
                    array(
                      'amount' =>
                        array(
                          'currency_code' => 'EUR',
                          'value' => '150.00'
                        ),

                      'payee' =>
                        array(
                          'email_address' => 'sb-qloys3515897@business.example.com'
                          )

                  )
                )
            );

Solution

  • You linked to the object's definition, not the part of the documentation that tells you what its key name in the Request body should be: https://developer.paypal.com/docs/api/orders/v2/#orders-create-request-body

    And that is, application_context