Class: PinPayment::Customer
Instance Attribute Summary collapse
-
#card ⇒ Object
readonly
Returns the value of attribute card.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
-
.all ⇒ Array<PinPayment::Customer>
Fetches all of your customers using the pin API.
-
.create(email, card_or_token = nil) ⇒ PinPayment::Customer
Uses the pin API to create a customer.
- .delete_customer(token) ⇒ Object
-
.find(token) ⇒ PinPayment::Customer
Fetches a customer using the pin API.
-
.update(token, email, card_or_token = nil) ⇒ PinPayment::Customer
Update a customer using the pin API.
Instance Method Summary collapse
-
#update(email, card_or_token = nil) ⇒ PinPayment::Customer
Update a customer using the pin API.
Methods inherited from Base
Constructor Details
This class inherits a constructor from PinPayment::Base
Instance Attribute Details
#card ⇒ Object
Returns the value of attribute card.
3 4 5 |
# File 'lib/pin_payment/customer.rb', line 3 def card @card end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/pin_payment/customer.rb', line 3 def created_at @created_at end |
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/pin_payment/customer.rb', line 3 def email @email end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/pin_payment/customer.rb', line 3 def token @token end |
Class Method Details
.all ⇒ Array<PinPayment::Customer>
Fetches all of your customers using the pin API.
TODO: pagination
45 46 47 48 |
# File 'lib/pin_payment/customer.rb', line 45 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.
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] = (attributes, email: email, card: card_or_token) response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/customers' }, ) new(response.delete('token'), response) end |
.delete_customer(token) ⇒ Object
18 19 20 |
# File 'lib/pin_payment/customer.rb', line 18 def self.delete_customer(token) delete(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{token}" }) end |
.find(token) ⇒ PinPayment::Customer
Fetches a customer using the pin API.
36 37 38 39 |
# File 'lib/pin_payment/customer.rb', line 36 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.
28 29 30 |
# File 'lib/pin_payment/customer.rb', line 28 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.
55 56 57 58 59 60 61 62 |
# File 'lib/pin_payment/customer.rb', line 55 def update email, card_or_token = nil attributes = self.class.attributes - [:token, :created_at] = self.class.(attributes, email: email, card: card_or_token) response = self.class.put(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{token}" }, ) self.email = response['email'] self.card = response['card'] self end |