Class: PinPayment::Refund

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_payment/refund.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/refund.rb', line 3

def amount
  @amount
end

#chargeObject

Returns the value of attribute charge.



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

def charge
  @charge
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#currencyObject

Returns the value of attribute currency.



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

def currency
  @currency
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Class Method Details

.create(refund_data) ⇒ PinPayment::Refund

Uses the pin API to create a refund.

Parameters:

  • charge_or_token (String, PinPayment::Charge)

    the charge (or token of the charge) to refund

Returns:



10
11
12
13
14
15
16
# 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) ⇒ PinPayment::Refund

Fetches a refund using the Pin API.

Parameters:

  • token (String)

    the charge token

Returns:



22
23
24
25
# 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

Instance Method Details

#statusString

Returns:

  • (String)


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

def status
  status_message
end

#success?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.

Returns:

  • (Boolean)


31
32
33
# File 'lib/pin_payment/refund.rb', line 31

def success?
  @success == true
end