class PinPayment::Charge

Attributes

amount[RW]
card[RW]
created_at[RW]
currency[RW]
customer[RW]
description[RW]
email[RW]
ip_address[RW]
success[RW]
token[RW]
total_fees[RW]

Public Class Methods

all() click to toggle source

Fetches all of your charges using the pin API.

@return [Array<PinPayment::Charge>] TODO: pagination

# 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) click to toggle source

Uses the pin API to create a charge.

@param [Hash] charge_data @option charge_data [String] :amount required @option charge_data [String] :currency required only AUD and USD supported @option charge_data [String] :email required @option charge_data [String] :description required @option charge_data [String] :ip_address required @option charge_data [String, PinPayment::Customer] :customer can be a customer token or a customer object @option charge_data [String, PinPayment::Card, Hash] :card can be a card token, hash or a card object @return [PinPayment::Charge]

# 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) click to toggle source

Fetches a charge using the Pin API.

@param [String] token the charge token @return [PinPayment::Charge]

# 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

Protected Class Methods

attributes() click to toggle source
# File lib/pin_payment/charge.rb, line 66
def self.attributes
  [:token, :amount, :currency, :description, :email, :ip_address, :created_at, :card, :customer, :success, :total_fees]
end

Public Instance Methods

refund!() click to toggle source

Refund a charge via the pin API.

@return [PinPayment::Refund]

# File lib/pin_payment/charge.rb, line 46
def refund!
  Refund.create self
end
refunds() click to toggle source

Fetches all refunds of your charge using the pin API.

@return [Array<PinPayment::Refund>] TODO: pagination

# File lib/pin_payment/charge.rb, line 54
def refunds
  response = Charge.get(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" })
  response.map{|x| Refund.new(x.delete('token'), x) }
end
success?() click to toggle source

@return [Boolean]

# File lib/pin_payment/charge.rb, line 60
def success?
  success == true
end