Class: PandaPay::Customer
- Inherits:
-
Object
- Object
- PandaPay::Customer
- Defined in:
- lib/pandapay/customer.rb
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#livemode ⇒ Object
readonly
Returns the value of attribute livemode.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
- .create(email:, source:) ⇒ Object
- .delete(customer_id:) ⇒ Object
- .update(customer_id:, email: nil, source: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Customer
constructor
A new instance of Customer.
Constructor Details
#initialize(attributes) ⇒ Customer
Returns a new instance of Customer.
6 7 8 9 10 11 12 |
# File 'lib/pandapay/customer.rb', line 6 def initialize(attributes) @id = attributes["id"] @object = attributes["object"] @email = attributes["email"] @livemode = attributes["livemode"] @cards = attributes["cards"] end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
4 5 6 |
# File 'lib/pandapay/customer.rb', line 4 def cards @cards end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
4 5 6 |
# File 'lib/pandapay/customer.rb', line 4 def email @email end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/pandapay/customer.rb', line 4 def id @id end |
#livemode ⇒ Object (readonly)
Returns the value of attribute livemode.
4 5 6 |
# File 'lib/pandapay/customer.rb', line 4 def livemode @livemode end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
4 5 6 |
# File 'lib/pandapay/customer.rb', line 4 def object @object end |
Class Method Details
.create(email:, source:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pandapay/customer.rb', line 14 def self.create(email: , source: ) conn = Faraday.new(:url => "https://#{PandaPay.secret_key}:@#{PandaPay_API_URL}") response = conn.post '/v1/customers', { :email => email, :source => source} attributes = JSON.parse(response.body) if attributes.has_key? "error" or attributes.has_key? "errors" raise response.body else new(attributes) end end |
.delete(customer_id:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pandapay/customer.rb', line 43 def self.delete(customer_id: ) conn = Faraday.new(:url => "https://#{PandaPay.secret_key}:@#{PandaPay_API_URL}") response = conn.delete "/v1/customers/#{customer_id}" attributes = JSON.parse(response.body) if attributes.has_key? "error" or attributes.has_key? "errors" raise response.body else new(attributes) end end |
.update(customer_id:, email: nil, source: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pandapay/customer.rb', line 25 def self.update(customer_id: , email: nil, source: nil) params = {} unless email.nil? params[:email] = email end unless source.nil? params[:source] = source end conn = Faraday.new(:url => "https://#{PandaPay.secret_key}:@#{PandaPay_API_URL}") response = conn.put "/v1/customers/#{customer_id}", params attributes = JSON.parse(response.body) if attributes.has_key? "error" or attributes.has_key? "errors" raise response.body else new(attributes) end end |