Class: Spree::Refund
- Defined in:
- app/models/spree/refund.rb
Instance Attribute Summary collapse
-
#perform_after_create ⇒ Object
Returns the value of attribute perform_after_create.
-
#perform_response ⇒ Object
readonly
Returns the value of attribute perform_response.
Class Method Summary collapse
Instance Method Summary collapse
-
#amount=(price) ⇒ Object
Sets this price’s amount to a new value, parsing it if the new value is a string.
- #description ⇒ Object
- #money ⇒ Object (also: #display_amount)
-
#perform! ⇒ Object
Must be called for the refund transaction to be processed.
Methods inherited from Base
display_includes, page, preference, #preferences
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Instance Attribute Details
#perform_after_create ⇒ Object
Returns the value of attribute perform_after_create.
18 19 20 |
# File 'app/models/spree/refund.rb', line 18 def perform_after_create @perform_after_create end |
#perform_response ⇒ Object (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
34 35 36 |
# File 'app/models/spree/refund.rb', line 34 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.
43 44 45 |
# File 'app/models/spree/refund.rb', line 43 def amount=(price) self[:amount] = Spree::LocalizedNumber.parse(price) end |
#description ⇒ Object
47 48 49 |
# File 'app/models/spree/refund.rb', line 47 def description payment.payment_method.name end |
#money ⇒ Object Also known as: display_amount
28 29 30 |
# File 'app/models/spree/refund.rb', line 28 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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/spree/refund.rb', line 55 def perform! return true if perform_after_create == false return true if transaction_id.present? # This is needed otherwise set_perform_after_create_default callback # will print a deprecation warning when save! creates a record self.perform_after_create = false unless persisted? credit_cents = money.cents @perform_response = process!(credit_cents) @response = Spree::DeprecatedInstanceVariableProxy.new( self, :perform_response, :@response, Spree::Deprecation, "Please, do not use Spree::Refund @response anymore, use Spree::Refund#perform_response" ) log_entries.build(details: perform_response.to_yaml) self.transaction_id = perform_response. save! update_order end |