Class: Cardgate::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/cardgate/payment.rb

Direct Known Subclasses

Ideal::Payment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Payment

Returns a new instance of Payment.



10
11
12
13
14
# File 'lib/cardgate/payment.rb', line 10

def initialize(attributes = {})
  attributes.each do |k,v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def address
  @address
end

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def amount
  @amount
end

#cityObject

Returns the value of attribute city.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def city
  @city
end

#company_nameObject

Returns the value of attribute company_name.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def company_name
  @company_name
end

#control_urlObject

Returns the value of attribute control_url.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def control_url
  @control_url
end

#country_codeObject

Returns the value of attribute country_code.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def country_code
  @country_code
end

#currencyObject

Returns the value of attribute currency.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def description
  @description
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def first_name
  @first_name
end

#ip_addressObject

Returns the value of attribute ip_address.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def ip_address
  @ip_address
end

#languageObject

Returns the value of attribute language.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def language
  @language
end

#last_nameObject

Returns the value of attribute last_name.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def last_name
  @last_name
end

#phone_numberObject

Returns the value of attribute phone_number.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def phone_number
  @phone_number
end

#postal_codeObject

Returns the value of attribute postal_code.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def postal_code
  @postal_code
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def provider
  @provider
end

#refObject

Returns the value of attribute ref.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def ref
  @ref
end

#return_urlObject

Returns the value of attribute return_url.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def return_url
  @return_url
end

#site_idObject

Returns the value of attribute site_id.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def site_id
  @site_id
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/cardgate/payment.rb', line 5

def state
  @state
end

Instance Method Details

#api_payment_endpointObject



68
69
70
# File 'lib/cardgate/payment.rb', line 68

def api_payment_endpoint
  "/rest/v1/#{provider}/payment/"
end

#default_paramsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cardgate/payment.rb', line 16

def default_params
  default_params = {
    payment: {
      site_id: @site_id,
      currency: @currency,
      ref: @ref,
      return_url: @return_url,
      control_url: @control_url,
      currency: @currency,
      language: @language,
      ip_address: @ip_address,
      description: @description,
      amount: @amount
    }
  }

  customer_fields = %w(first_name last_name company_name address city state postal_code country_code phone_number email)

  customer_fields.each do |field|
    var = instance_variable_get("@#{field}")

    if !var.nil? && !var.empty?
      default_params[:payment][:customer] = {} if default_params[:payment][:customer].nil?
      default_params[:payment][:customer][field.to_sym] = var
    end
  end

  return default_params
end

#initiateObject



46
47
48
49
50
# File 'lib/cardgate/payment.rb', line 46

def initiate
  @response ||= response

  self
end

#paramsObject



60
61
62
# File 'lib/cardgate/payment.rb', line 60

def params
  default_params.deep_merge!(payment_params)
end

#payment_paramsObject



64
65
66
# File 'lib/cardgate/payment.rb', line 64

def payment_params
  {}
end

#payment_urlObject



52
53
54
# File 'lib/cardgate/payment.rb', line 52

def payment_url
  @response.body['payment']['issuer_auth_url']
end

#transaction_idObject



56
57
58
# File 'lib/cardgate/payment.rb', line 56

def transaction_id
  @response.body['payment']['transaction_id']
end