Class: Refund
Constant Summary collapse
- BRAINTREE_UNSETTLED_MESSAGE =
"Cannot refund a transaction unless it is settled. (91506)"
- FRIENDLY_UNSETTLED_MESSAGE =
"The processor cannot refund that transaction yet. Please try again in a few hours."
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.
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
Methods included from Adjustments
#number_of_non_free_items, #service_fee_per_item
Constructor Details
#initialize(order, items) ⇒ Refund
Returns a new instance of Refund.
8 9 10 11 |
# File 'app/models/refund.rb', line 8 def initialize(order, items) self.order = order self.items = items end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'app/models/refund.rb', line 3 def items @items end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'app/models/refund.rb', line 3 def @message end |
#order ⇒ Object
Returns the value of attribute order.
3 4 5 |
# File 'app/models/refund.rb', line 3 def order @order end |
#refund_order ⇒ Object
Returns the value of attribute refund_order.
3 4 5 |
# File 'app/models/refund.rb', line 3 def refund_order @refund_order 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
39 40 41 42 43 |
# File 'app/models/refund.rb', line 39 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
48 49 50 |
# File 'app/models/refund.rb', line 48 def refund_amount item_total + service_fee end |
#service_fee ⇒ Object
52 53 54 |
# File 'app/models/refund.rb', line 52 def service_fee (number_of_non_free_items(items) * service_fee_per_item(order.items)) end |
#submit(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/refund.rb', line 13 def submit( = {}) return_items_to_inventory = [:and_return] || false 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 items.each { |i| i.return!(return_items_to_inventory) } items.each(&:refund!) create_refund_order(@payment.transaction_id) end end |
#successful? ⇒ Boolean
34 35 36 |
# File 'app/models/refund.rb', line 34 def successful? @success || false end |