class PinPayment::Refund

Attributes

amount[RW]
charge[RW]
created_at[RW]
currency[RW]
status_message[RW]
token[RW]

Public Class Methods

create(refund_data) click to toggle source

Uses the pin API to create a refund.

@param [String, PinPayment::Charge] charge_or_token the charge (or token of the charge) to refund @return [PinPayment::Refund]

# File lib/pin_payment/refund.rb, line 10
def self.create refund_data
  charge_or_token = refund_data.is_a?(Hash) ? refund_data[:charge] : refund_data
  token = charge_or_token.is_a?(Charge) ? charge_or_token.token : charge_or_token
  options = refund_data.is_a?(Hash) && refund_data[:amount] ? { amount: refund_data[:amount] } : {}
  response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" }, options)
  new(response.delete('token'), response)
end
find(token) click to toggle source

Fetches a refund using the Pin API.

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

# File lib/pin_payment/refund.rb, line 22
def self.find token
  response = get(URI.parse(PinPayment.api_url).tap{ |uri| uri.path = "/1/refunds/#{token}" })
  new(response.delete('token'), response)
end

Protected Class Methods

attributes() click to toggle source
# File lib/pin_payment/refund.rb, line 42
def self.attributes
  [:token, :amount, :currency, :charge, :created_at, :status_message]
end

Public Instance Methods

status() click to toggle source

@return [String]

# File lib/pin_payment/refund.rb, line 36
def status
  status_message
end
success?() click to toggle source

@return [Boolean] TODO: API documentation only shows success as being “null” in the JSON response, so not sure this is possible. All my refunds on the test site end up in a “Pending” state so not entirely sure on this one.

# File lib/pin_payment/refund.rb, line 31
def success?
  @success == true
end