Class: CreditGateway::Authenticate

Inherits:
Object
  • Object
show all
Defined in:
lib/credit_gateway/authenticate.rb

Instance Method Summary collapse

Instance Method Details

#call(client_id, client_secret) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/credit_gateway/authenticate.rb', line 9

def call(client_id, client_secret)
  response = post(
    '/auth/connect/token',
    client_id: client_id,
    client_secret: client_secret,
    grant_type: 'client_credentials'
  )

  if response.success?
    response.body[:access_token]
  elsif response.status == 400
    raise InvalidRequestError, response.body
  else
    raise GenericError, response.body
  end
end