Class: PinPayment::Card

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_payment/card.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PinPayment::Base

Instance Attribute Details

#address_cityObject

Returns the value of attribute address_city.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def address_city
  @address_city
end

#address_countryObject

Returns the value of attribute address_country.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def address_country
  @address_country
end

#address_line1Object

Returns the value of attribute address_line1.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def address_line1
  @address_line1
end

#address_line2Object

Returns the value of attribute address_line2.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def address_line2
  @address_line2
end

#address_postcodeObject

Returns the value of attribute address_postcode.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def address_postcode
  @address_postcode
end

#address_stateObject

Returns the value of attribute address_state.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def address_state
  @address_state
end

#display_numberObject

Returns the value of attribute display_number.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def display_number
  @display_number
end

#schemeObject

Returns the value of attribute scheme.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def scheme
  @scheme
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/pin_payment/card.rb', line 3

def token
  @token
end

Class Method Details

.create(card_data) ⇒ PinPayment::Card

Use the pin API to create a credit card token, usable for 1 month from creation.

Parameters:

  • card_data (Hash)

Options Hash (card_data):

  • :name (#to_s)
  • :number (#to_s)
  • :cvc (#to_s)
  • :address_line1 (#to_s)
  • :address_line2 (#to_s) — default: optional
  • :address_city (#to_s)
  • :address_postcode (#to_s)
  • :address_country (#to_s)
  • :expiry_month (#to_s)
  • :expiry_year (#to_s) — default: 4 digits required

Returns:



24
25
26
27
28
29
# File 'lib/pin_payment/card.rb', line 24

def self.create card_data
  attributes = self.attributes - [:token, :display_number, :scheme] # fix attributes allowed by POST API
  options    = parse_options_for_request(attributes, card_data)
  response   = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/cards' }, options)
  new(response.delete('token'), response)
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


32
33
34
# File 'lib/pin_payment/card.rb', line 32

def to_hash
  {}.tap{|h| self.class.attributes.each{|k| v = send(k) ; h[k] = v if v }}
end