Class: Pin::Customer

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_up/customer.rb

Overview

This class models Pins Customers API

Instance Attribute Summary

Attributes inherited from Base

#key

Class Method Summary collapse

Methods inherited from Base

#base_uri, build_collection_response, build_response, #initialize, make_request

Constructor Details

This class inherits a constructor from Pin::Base

Class Method Details

.all(page = nil, pagination = false) ⇒ Object

Lists all customers for your account args: page (Fixnum), pagination (Boolean) returns: a collection of customer objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pinpayments.com/docs/api/customers#get-customers



14
15
16
# File 'lib/pin_up/customer.rb', line 14

def self.all(page = nil, pagination = false)
  build_collection_response(make_request(:get, {url: "customers?page=#{page}" } ), pagination)
end

.cards(token, page = nil, pagination = false) ⇒ Object

Get a list of cards for a customer args: token (String), page (Fixnum), pagination (Boolean) returns: a collection of cards objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pinpayments.com/docs/api/customers#get-customers-cards



78
79
80
81
82
# File 'lib/pin_up/customer.rb', line 78

def self.cards(token, page = nil, pagination = false)
  build_collection_response(
    make_request(:get, {url: "customers/#{token}/cards?page=#{page}" }), pagination
  )
end

.charges(token, page = nil, pagination = false) ⇒ Object

Get a list of charges for a customer args: token (String), page (Fixnum), pagination (Boolean) returns: a collection of charge objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pinpayments.com/docs/api/customers#get-customers-charges



63
64
65
66
67
# File 'lib/pin_up/customer.rb', line 63

def self.charges(token, page = nil, pagination = false)
  build_collection_response(
    make_request(:get, {url: "customers/#{token}/charges?page=#{page}" }), pagination
  )
end

.create(email, card) ⇒ Object

Create a customer given customer details and a card OR a card_token args: email(String), card (Hash) returns: a customer object pinpayments.com/docs/api/customers#post-customers



23
24
25
26
27
28
29
30
31
# File 'lib/pin_up/customer.rb', line 23

def self.create(email, card)
  options = if card.respond_to?(:to_hash)
    { card: card.to_hash }
  else
    { card_token: card }
  end.merge(email: email)

  build_response(make_request(:post, { url: 'customers', options: options }))
end

.create_card(token, card) ⇒ Object

Create a card for customer given a card OR a card_token args: customer_token (String), card (Hash) or (String) see docs. returns: a card object pinpayments.com/docs/api/customers#post-customers-cards



89
90
91
92
93
94
95
96
97
# File 'lib/pin_up/customer.rb', line 89

def self.create_card(token, card)
  options = if card.respond_to?(:to_hash)
    card
  else
    { card_token: card }
  end

  build_response(make_request(:post, {url: "customers/#{token}/cards", options: options} ))
end

.delete_card(token, card_token) ⇒ Object

Deletes a card for customer given a card_token args: customer_token (String), card_token (String) returns: a card object pinpayments.com/docs/api/customers#delete-customers-card



104
105
106
# File 'lib/pin_up/customer.rb', line 104

def self.delete_card(token, card_token)
  build_response(make_request(:delete, {url: "customers/#{token}/cards/#{card_token}"} ))
end

.find(token) ⇒ Object

Find a customer for your account given a token args: token (String) returns: a customer object pinpayments.com/docs/api/customers#get-customers



38
39
40
# File 'lib/pin_up/customer.rb', line 38

def self.find(token)
  build_response(make_request(:get, {url: "customers/#{token}" } ))
end

.update(token, options = {}) ⇒ Object

Update a customer for your account given a token and any of: email, card (hash),card_token args: token (String), options (Hash) returns: a customer object pinpayments.com/docs/api/customers#put-customer NB: When providing a card (hash), you need to specify the full list of details.



50
51
52
# File 'lib/pin_up/customer.rb', line 50

def self.update(token, options = {})
  build_response(make_request(:put, { url: "customers/#{token}", options: options }))
end