Class: PinPayment::Customer

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_payment/customer.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

#cardObject

Returns the value of attribute card.



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

def card
  @card
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Class Method Details

.allArray<PinPayment::Customer>

Fetches all of your customers using the pin API.

TODO: pagination

Returns:



41
42
43
44
# File 'lib/pin_payment/customer.rb', line 41

def self.all
  response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/customers' })
  response.map{|x| new(x.delete('token'), x) }
end

.create(email, card_or_token = nil) ⇒ PinPayment::Customer

Uses the pin API to create a customer.

Parameters:

  • email (String)

    the customer’s email address

  • card_or_token (String, PinPayment::Card, Hash) (defaults to: nil)

    the customer’s credit card details

Returns:



11
12
13
14
15
16
# File 'lib/pin_payment/customer.rb', line 11

def self.create email, card_or_token = nil
  attributes = self.attributes - [:token, :created_at]
  options    = parse_options_for_request(attributes, email: email, card: card_or_token)
  response   = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/customers' }, options)
  new(response.delete('token'), response)
end

.find(token) ⇒ PinPayment::Customer

Fetches a customer using the pin API.

Parameters:

  • token (String)

    the customer token

Returns:



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

def self.find token
  response = get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{token}" })
  new(response.delete('token'), response)
end

.update(token, email, card_or_token = nil) ⇒ PinPayment::Customer

Update a customer using the pin API.

Parameters:

  • token (String)

    the customer token

  • email (String)

    the customer’s new email address

  • card_or_token (String, PinPayment::Card, Hash) (defaults to: nil)

    the customer’s new credit card details

Returns:



24
25
26
# File 'lib/pin_payment/customer.rb', line 24

def self.update token, email, card_or_token = nil
  new(token).tap{|c| c.update(email, card_or_token) }
end

Instance Method Details

#update(email, card_or_token = nil) ⇒ PinPayment::Customer

Update a customer using the pin API.

Parameters:

  • email (String)

    the customer’s new email address

  • card_or_token (String, PinPayment::Card, Hash) (defaults to: nil)

    the customer’s new credit card details

Returns:



51
52
53
54
55
56
57
58
# File 'lib/pin_payment/customer.rb', line 51

def update email, card_or_token = nil
  attributes = self.class.attributes - [:token, :created_at]
  options    = self.class.parse_options_for_request(attributes, email: email, card: card_or_token)
  response   = self.class.put(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{token}" }, options)
  self.email = response['email']
  self.card  = response['card']
  self
end