Class: Refund
- Inherits:
-
Object
- Object
- Refund
- Defined in:
- app/models/refund.rb
Constant Summary collapse
- BRAINTREE_UNSETTLED_MESSAGE =
"Cannot refund a transaction unless it is settled. (91506)"
- FRIENDLY_UNSETTLED_MESSAGE =
"Unfortunately we cannot refund credit card transactions until the day after they were processed. Please re-issue the refund tomorrow."
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#message ⇒ Object
Returns the value of attribute message.
-
#order ⇒ Object
Returns the value of attribute order.
-
#refund_order ⇒ Object
Returns the value of attribute refund_order.
-
#send_email_confirmation ⇒ Object
Returns the value of attribute send_email_confirmation.
Instance Method Summary collapse
-
#format_message(payment) ⇒ Object
This is brittle, sure, but active merchant doens’t pass along any processor codes so we have to match the whole stupid string.
-
#initialize(order, items) ⇒ Refund
constructor
A new instance of Refund.
-
#refund_amount ⇒ Object
The gross amount of the refund.
- #service_fee ⇒ Object
- #submit(options = {}) ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(order, items) ⇒ Refund
Returns a new instance of Refund.
7 8 9 10 |
# File 'app/models/refund.rb', line 7 def initialize(order, items) self.order = order self.items = items end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
2 3 4 |
# File 'app/models/refund.rb', line 2 def items @items end |
#message ⇒ Object
Returns the value of attribute message.
2 3 4 |
# File 'app/models/refund.rb', line 2 def @message end |
#order ⇒ Object
Returns the value of attribute order.
2 3 4 |
# File 'app/models/refund.rb', line 2 def order @order end |
#refund_order ⇒ Object
Returns the value of attribute refund_order.
2 3 4 |
# File 'app/models/refund.rb', line 2 def refund_order @refund_order end |
#send_email_confirmation ⇒ Object
Returns the value of attribute send_email_confirmation.
2 3 4 |
# File 'app/models/refund.rb', line 2 def send_email_confirmation @send_email_confirmation end |
Instance Method Details
#format_message(payment) ⇒ Object
This is brittle, sure, but active merchant doens’t pass along any processor codes so we have to match the whole stupid string
49 50 51 52 53 |
# File 'app/models/refund.rb', line 49 def (payment) unless payment.errors.empty? (payment.errors[:base].first.eql? BRAINTREE_UNSETTLED_MESSAGE) ? FRIENDLY_UNSETTLED_MESSAGE : payment.errors..to_sentence end end |
#refund_amount ⇒ Object
The gross amount of the refund. This is the total amount of money we are returning to the patron
58 59 60 |
# File 'app/models/refund.rb', line 58 def refund_amount item_total + service_fee end |
#service_fee ⇒ Object
62 63 64 |
# File 'app/models/refund.rb', line 62 def service_fee items.collect(&:service_fee).sum end |
#submit(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/refund.rb', line 12 def submit( = {}) return_items_to_inventory = [:and_return] || false @send_email_confirmation = [:send_email_confirmation] || false ActiveRecord::Base.transaction do items.each do |i| unless i.refundable? @message = "Those items have already been refunded." return end end @payment = Payment.create(@order.payment_method) @success = @payment.refund(refund_amount, order.transaction_id, .merge({:service_fee => service_fee})) @message = (@payment) if @success # # NOTE: That this will clean up the items, but the tickets will remain sold # if the show date has passed. # because ticket.reset_price! is guarded with sold? and return_to_inventory # is guarded with expired? (show date passed) # items.each { |i| i.return!(return_items_to_inventory) } items.each(&:refund!) create_refund_order(@payment.transaction_id) end #TODO: rollback refund as well end end |
#successful? ⇒ Boolean
44 45 46 |
# File 'app/models/refund.rb', line 44 def successful? @success || false end |