Class: PinPayment::Transfer

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_payment/transfer.rb

Defined Under Namespace

Classes: LineItem

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

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def amount
  @amount
end

#currencyObject

Returns the value of attribute currency.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def description
  @description
end

Returns the value of attribute paid_at.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def paid_at
  @paid_at
end

#recipientObject

Returns the value of attribute recipient.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def recipient
  @recipient
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def status
  @status
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def token
  @token
end

#total_creditsObject

Returns the value of attribute total_credits.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def total_credits
  @total_credits
end

#total_debitsObject

Returns the value of attribute total_debits.



4
5
6
# File 'lib/pin_payment/transfer.rb', line 4

def total_debits
  @total_debits
end

Class Method Details

.allArray<PinPayment::Transfer>

Fetches all of your transfers using the pin API.

TODO: pagination

Returns:



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

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

.create(transfer_data) ⇒ PinPayment::Transfer

Uses the pin API to create a transfer.

Parameters:

  • transfer_data (Hash)

Options Hash (transfer_data):

  • :description (String)

    required

  • :amount (String)

    required

  • :currency (String)

    required (Currenly only AUD is supported)

  • :recipient (String)

    required a token for a stored recipient

Returns:



15
16
17
18
19
20
# File 'lib/pin_payment/transfer.rb', line 15

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

.find(token) ⇒ PinPayment::Transfer

Fetches a transfer using the pin API.

Parameters:

  • token (String)

    the recipient token

Returns:



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

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

Instance Method Details

#line_itemsObject



40
41
42
43
# File 'lib/pin_payment/transfer.rb', line 40

def line_items
  response = self.class.get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/transfers/#{token}/line_items" })
  response.map{|hash| LineItem.new(hash.delete('token')) }
end