Class: Cybersourcery::Profile

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/cybersourcery/profile.rb

Constant Summary collapse

VALID_ENDPOINTS =
{
  standard: '/silent/pay',
  create_payment_token: '/silent/token/create',
  update_payment_token: '/silent/token/update',
  iframe_standard: '/silent/embedded/pay',
  iframe_create_payment_token: 'silent/embedded/token/create',
  iframe_update_payment_token: '/silent/embedded/token/update'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_id, profiles = Cybersourcery.configuration.profiles) ⇒ Profile

Returns a new instance of Profile.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cybersourcery/profile.rb', line 27

def initialize(profile_id, profiles = Cybersourcery.configuration.profiles)
  profiles[profile_id].each do |k,v|
    self.send "#{k}=", v
  end

  @profile_id = profile_id
  @endpoint_type = @endpoint_type.to_sym

  unless self.valid?
    raise Cybersourcery::CybersourceryError, self.errors.full_messages.to_sentence
  end
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def access_key
  @access_key
end

#currencyObject

Returns the value of attribute currency.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def currency
  @currency
end

#endpoint_typeObject

Returns the value of attribute endpoint_type.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def endpoint_type
  @endpoint_type
end

#localeObject

Returns the value of attribute locale.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def name
  @name
end

#payment_methodObject

Returns the value of attribute payment_method.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def payment_method
  @payment_method
end

#profile_idObject

Returns the value of attribute profile_id.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def profile_id
  @profile_id
end

#secret_keyObject

Returns the value of attribute secret_key.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def secret_key
  @secret_key
end

#serviceObject

Returns the value of attribute service.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def service
  @service
end

#success_urlObject

Returns the value of attribute success_url.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def success_url
  @success_url
end

#transaction_typeObject

Returns the value of attribute transaction_type.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def transaction_type
  @transaction_type
end

#unsigned_field_namesObject

Returns the value of attribute unsigned_field_names.



17
18
19
# File 'lib/cybersourcery/profile.rb', line 17

def unsigned_field_names
  @unsigned_field_names
end

Instance Method Details

#transaction_url(proxy_url = ENV['CYBERSOURCERY_SOP_PROXY_URL'], env = Rails.env) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cybersourcery/profile.rb', line 40

def transaction_url(proxy_url = ENV['CYBERSOURCERY_SOP_PROXY_URL'], env = Rails.env)
  if env == 'test' && proxy_url.present?
    "#{proxy_url}#{VALID_ENDPOINTS[@endpoint_type]}"
  elsif env == 'test' && proxy_url.blank?
    "#{Cybersourcery.configuration.sop_test_url}#{VALID_ENDPOINTS[@endpoint_type]}"
  elsif @service == 'test'
    "#{Cybersourcery.configuration.sop_test_url}#{VALID_ENDPOINTS[@endpoint_type]}"
  elsif @service == 'live'
    "#{Cybersourcery.configuration.sop_live_url}#{VALID_ENDPOINTS[@endpoint_type]}"
  else
    raise Cybersourcery::CybersourceryError, 'Invalid conditions for determining the transaction_url'
  end
end