Class: Spree::Refund

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/refund.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

display_includes

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Instance Attribute Details

#perform_responseObject (readonly)

Returns the value of attribute perform_response.



17
18
19
# File 'app/models/spree/refund.rb', line 17

def perform_response
  @perform_response
end

Class Method Details

.total_amount_reimbursed_for(reimbursement) ⇒ Object



29
30
31
# File 'app/models/spree/refund.rb', line 29

def total_amount_reimbursed_for(reimbursement)
  reimbursement.refunds.to_a.sum(&:amount)
end

Instance Method Details

#amount=(price) ⇒ Object

Sets this price’s amount to a new value, parsing it if the new value is a string.

Parameters:

  • price (String, #to_d)

    a new amount



38
39
40
# File 'app/models/spree/refund.rb', line 38

def amount=(price)
  self[:amount] = Spree::LocalizedNumber.parse(price)
end

#descriptionObject



42
43
44
# File 'app/models/spree/refund.rb', line 42

def description
  payment.payment_method.name
end

#moneyObject Also known as: display_amount



23
24
25
# File 'app/models/spree/refund.rb', line 23

def money
  Spree::Money.new(amount, { currency: currency })
end

#perform!Object

Must be called for the refund transaction to be processed.

Attempts to perform the refund, raises an error if the refund fails.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/spree/refund.rb', line 50

def perform!
  return true if transaction_id.present?

  credit_cents = money.cents

  @perform_response = process!(credit_cents)
  log_entries.build(parsed_payment_response_details_with_fallback: perform_response)

  self.transaction_id = perform_response.authorization
  save!

  update_order
end