Module: PaypalAPI::Authentication::APIs

Included in:
PaypalAPI::Authentication, PaypalAPI::Authentication
Defined in:
lib/paypal-api/api_collections/authentication.rb

Overview

Common methods for PayplaAPI::Authentication class and client.authentication instance

Instance Method Summary collapse

Instance Method Details

#generate_access_token(query: nil, body: nil, headers: nil) ⇒ Response

Generates access token.

Default headers are:

{ "content-type" => "application/x-www-form-urlencoded", "authorization" => "Basic <TOKEN>" }

Default body is:

{grant_type: "client_credentials"}

Examples:

PaypalAPI::Authentication.generate_access_token
PaypalAPI.client.authorization.generate_access_token # same

Parameters:

  • query (Hash, nil) (defaults to: nil)

    Request query string parameters

  • body (Hash, nil) (defaults to: nil)

    Request body parameters

  • headers (Hash, nil) (defaults to: nil)

    Request headers

Returns:

  • (Response)

    detailed http request-response representation

Raises:

  • (Error)

    on network error or non 2** status code returned from PayPal

See Also:



41
42
43
44
45
46
47
48
49
50
# File 'lib/paypal-api/api_collections/authentication.rb', line 41

def generate_access_token(query: nil, body: nil, headers: nil)
  body ||= {grant_type: "client_credentials"}

  default_headers = {
    "content-type" => "application/x-www-form-urlencoded",
    "authorization" => "Basic #{["#{client.env.client_id}:#{client.env.client_secret}"].pack("m0")}"
  }

  client.post(PATH, query: query, body: body, headers: merge_headers!(default_headers, headers))
end