Class: PinPayment::Charge

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

#amountObject

Returns the value of attribute amount.



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

def amount
  @amount
end

#cardObject

Returns the value of attribute card.



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

def card
  @card
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#currencyObject

Returns the value of attribute currency.



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

def currency
  @currency
end

#customerObject

Returns the value of attribute customer.



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

def customer
  @customer
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#ip_addressObject

Returns the value of attribute ip_address.



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

def ip_address
  @ip_address
end

#successObject

Returns the value of attribute success.



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

def success
  @success
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#total_feesObject

Returns the value of attribute total_fees.



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

def total_fees
  @total_fees
end

Class Method Details

.allArray<PinPayment::Charge>

Fetches all of your charges using the pin API.

TODO: pagination

Returns:



38
39
40
41
# File 'lib/pin_payment/charge.rb', line 38

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

.create(charge_data) ⇒ PinPayment::Charge

Uses the pin API to create a charge.

Parameters:

  • charge_data (Hash)

Options Hash (charge_data):

  • :amount (String)

    required

  • :currency (String)

    required only AUD and USD supported

  • :email (String)

    required

  • :description (String)

    required

  • :ip_address (String)

    required

  • :customer (String, PinPayment::Customer)

    can be a customer token or a customer object

  • :card (String, PinPayment::Card, Hash)

    can be a card token, hash or a card object

Returns:



17
18
19
20
21
22
# File 'lib/pin_payment/charge.rb', line 17

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

.find(token) ⇒ PinPayment::Charge

Fetches a charge using the Pin API.

Parameters:

  • token (String)

    the charge token

Returns:



28
29
30
31
# File 'lib/pin_payment/charge.rb', line 28

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

Instance Method Details

#refund!PinPayment::Refund

Refund a charge via the pin API.

Returns:



46
47
48
# File 'lib/pin_payment/charge.rb', line 46

def refund!
  Refund.create self
end

#success?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/pin_payment/charge.rb', line 51

def success?
  success == true
end