Class: Braintree::CredentialsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/braintree/credentials_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



3
4
5
# File 'lib/braintree/credentials_parser.rb', line 3

def access_token
  @access_token
end

#client_idObject (readonly)

Returns the value of attribute client_id.



4
5
6
# File 'lib/braintree/credentials_parser.rb', line 4

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



5
6
7
# File 'lib/braintree/credentials_parser.rb', line 5

def client_secret
  @client_secret
end

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/braintree/credentials_parser.rb', line 6

def environment
  @environment
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.



7
8
9
# File 'lib/braintree/credentials_parser.rb', line 7

def merchant_id
  @merchant_id
end

Instance Method Details

#parse_access_token(access_token) ⇒ Object

Raises:



27
28
29
30
31
32
33
34
# File 'lib/braintree/credentials_parser.rb', line 27

def parse_access_token(access_token)
  raise ConfigurationError.new("Missing access_token when constructing Braintree::Gateway") if access_token.nil?
  raise ConfigurationError.new("Value passed for access_token is not a valid access_token") unless access_token.start_with?("access_token")

  @access_token = access_token
  @environment = parse_environment(access_token)
  @merchant_id = parse_merchant_id(access_token)
end

#parse_client_credentials(client_id, client_secret) ⇒ Object

Raises:



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

def parse_client_credentials(client_id, client_secret)
  raise ConfigurationError.new("Missing client_id when constructing Braintree::Gateway") if client_id.nil?
  raise ConfigurationError.new("Value passed for client_id is not a client_id") unless client_id.start_with?("client_id")

  raise ConfigurationError.new("Missing client_secret when constructing Braintree::Gateway") if client_secret.nil?
  raise ConfigurationError.new("Value passed for client_secret is not a client_secret") unless client_secret.start_with?("client_secret")
  client_id_environment = parse_environment(client_id)
  client_secret_environment = parse_environment(client_secret)

  if client_id_environment != client_secret_environment
    raise ConfigurationError.new("Mismatched credential environments: client_id environment is #{client_id_environment} and client_secret environment is #{client_secret_environment}")
  end

  @client_id = client_id
  @client_secret = client_secret
  @environment = client_id_environment
end

#parse_environment(credential) ⇒ Object



36
37
38
# File 'lib/braintree/credentials_parser.rb', line 36

def parse_environment(credential)
  credential.split("$")[1].to_sym
end

#parse_merchant_id(access_token) ⇒ Object



40
41
42
# File 'lib/braintree/credentials_parser.rb', line 40

def parse_merchant_id(access_token)
  access_token.split("$")[2]
end