Class: PinPayment::Recipient

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

#bank_accountObject

Returns the value of attribute bank_account.



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

def 
  @bank_account
end

#bank_account_tokenObject

Returns the value of attribute bank_account_token.



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

def 
  @bank_account_token
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Class Method Details

.allArray<PinPayment::Recipient>

Fetches all of your recipients using the pin API.

TODO: pagination

Returns:



35
36
37
38
# File 'lib/pin_payment/recipient.rb', line 35

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

.create(recipient_data) ⇒ PinPayment::Recipient

Uses the pin API to create a recipient.

Parameters:

  • recipient_data (Hash)

Options Hash (recipient_data):

  • :email (String)

    required

  • :name (String)

    required

  • :bank_account (String, PinPayment::BankAccount, Hash)

    can be a token, hash or bank account object

Returns:



14
15
16
17
18
19
# File 'lib/pin_payment/recipient.rb', line 14

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

.find(token) ⇒ PinPayment::Recipient

Fetches a customer using the pin API.

Parameters:

  • token (String)

    the recipient token

Returns:



44
45
46
47
# File 'lib/pin_payment/recipient.rb', line 44

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

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

Update a recipient using the pin API.

Parameters:

  • token (String)

    required

  • email (String)

    required

  • bank_account (String, PinPayment::BankAccount, Hash)

    can be a token, hash or bank account object required

Returns:



27
28
29
# File 'lib/pin_payment/recipient.rb', line 27

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, account_or_token = nil) ⇒ PinPayment::Customer

Update a recipient using the pin API.

Parameters:

  • email (String)

    the recipients’s new email address

  • account_or_token (String, PinPayment::BankAccount, Hash) (defaults to: nil)

    the recipient’s new bank account details

Returns:



54
55
56
57
58
59
60
61
# File 'lib/pin_payment/recipient.rb', line 54

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