6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/services/spree/checkout/add_store_credit.rb', line 6
def call(order:, amount: nil)
@order = order
return failed unless @order
remaining_total = amount ? [amount, @order.outstanding_balance].min : @order.outstanding_balance
ApplicationRecord.transaction do
@order.payments.store_credits.where(state: :checkout).map(&:invalidate!)
apply_store_credits(remaining_total) if @order.user&.store_credits&.any?
end
@order.reload.payments.store_credits.valid.any? ? success(@order) : failure(@order)
end
|