Class: SpreedlyCore::PaymentMethod

Inherits:
Base
  • Object
show all
Defined in:
lib/spreedly_core/payment_method.rb,
lib/spreedly_core/test_extensions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

configure, gateway_token, login, verify_get, verify_options, verify_post, verify_put, verify_request

Constructor Details

#initialize(attrs = {}) ⇒ PaymentMethod

Create a new PaymentMethod based on the attrs hash and then validate



29
30
31
32
# File 'lib/spreedly_core/payment_method.rb', line 29

def initialize(attrs={})
  super(attrs)
  validate
end

Instance Attribute Details

#address1Object (readonly)

Returns the value of attribute address1.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def address1
  @address1
end

#address2Object (readonly)

Returns the value of attribute address2.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def address2
  @address2
end

#card_typeObject (readonly)

Returns the value of attribute card_type.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def card_type
  @card_type
end

#cityObject (readonly)

Returns the value of attribute city.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def country
  @country
end

#created_atObject (readonly)

Returns the value of attribute created_at.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def created_at
  @created_at
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def data
  @data
end

#emailObject (readonly)

Returns the value of attribute email.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def email
  @email
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def errors
  @errors
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def first_name
  @first_name
end

#last_four_digitsObject (readonly)

Returns the value of attribute last_four_digits.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def last_four_digits
  @last_four_digits
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def last_name
  @last_name
end

#monthObject (readonly)

Returns the value of attribute month.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def month
  @month
end

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def number
  @number
end

#payment_method_typeObject (readonly)

Returns the value of attribute payment_method_type.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def payment_method_type
  @payment_method_type
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def phone_number
  @phone_number
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def state
  @state
end

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def token
  @token
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def updated_at
  @updated_at
end

#verification_valueObject (readonly)

Returns the value of attribute verification_value.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def verification_value
  @verification_value
end

#yearObject (readonly)

Returns the value of attribute year.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def year
  @year
end

#zipObject (readonly)

Returns the value of attribute zip.



3
4
5
# File 'lib/spreedly_core/payment_method.rb', line 3

def zip
  @zip
end

Class Method Details

.additional_required_cc_fields(*fields) ⇒ Object

configure additional required fiels. Like :address1, :city, :state



9
10
11
12
# File 'lib/spreedly_core/payment_method.rb', line 9

def self.additional_required_cc_fields *fields
  @@additional_required_fields ||= Set.new
  @@additional_required_fields += fields
end

.create_test_token(cc_data = {}, pass_through_data = nil) ⇒ Object

Call spreedly core to create a test token. pass_through_data will be added as the “data” field.



46
47
48
49
50
51
52
53
54
# File 'lib/spreedly_core/test_extensions.rb', line 46

def self.create_test_token(cc_data={}, pass_through_data=nil)
  data = cc_data.merge(:redirect_url => "http://example.com",
                       :api_login => SpreedlyCore::Base.,
                       :data => pass_through_data)

  self.verify_post "/payment_methods", :body => data, :has_key => "transaction" do |r|
    r['transaction']['payment_method']['token']
  end
end

.find(token) ⇒ Object

Lookup the PaymentMethod by token



20
21
22
23
24
25
26
# File 'lib/spreedly_core/payment_method.rb', line 20

def self.find(token)
  return nil if token.nil? 
  verify_get("/payment_methods/#{token}.xml",
             :has_key => "payment_method") do |response|
    new(response.parsed_response["payment_method"])
  end
end

.reset_additional_required_cc_fieldsObject

clear the configured additional required fields



15
16
17
# File 'lib/spreedly_core/payment_method.rb', line 15

def self.reset_additional_required_cc_fields
  @@additional_required_fields = Set.new
end

.submit_urlObject

Returns the URL that CC data should be submitted to.



61
62
63
# File 'lib/spreedly_core/payment_method.rb', line 61

def self.submit_url
  Base.base_uri + '/payment_methods'
end

Instance Method Details

#authorize(amount, currency = nil, _gateway_token = nil, ip_address = nil) ⇒ Object

Make an authorize against payment method. You can then later capture against the authorize



56
57
58
# File 'lib/spreedly_core/payment_method.rb', line 56

def authorize(amount, currency=nil,  _gateway_token=nil, ip_address=nil)
  purchase_or_authorize(:authorize, amount, currency, _gateway_token, ip_address)
end

#purchase(amount, currency = nil, _gateway_token = nil, ip_address = nil) ⇒ Object

Make a purchase against the payment method



51
52
53
# File 'lib/spreedly_core/payment_method.rb', line 51

def purchase(amount, currency=nil, _gateway_token=nil, ip_address=nil)
  purchase_or_authorize(:purchase, amount, currency, _gateway_token, ip_address)
end

#redactObject

Redact the payment method



43
44
45
46
47
48
# File 'lib/spreedly_core/payment_method.rb', line 43

def redact
  self.class.verify_put("/payment_methods/#{token}/redact.xml",
                        :body => {}, :has_key => "transaction") do |response|
    RedactTransaction.new(response.parsed_response["transaction"])
  end
end

#retainObject

Retain the payment method



35
36
37
38
39
40
# File 'lib/spreedly_core/payment_method.rb', line 35

def retain
  self.class.verify_put("/payment_methods/#{token}/retain.xml",
                        :body => {}, :has_key => "transaction") do |response|
    RetainTransaction.new(response.parsed_response["transaction"])
  end
end

#valid?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/spreedly_core/payment_method.rb', line 65

def valid?
  @errors.empty?
end