42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/models/spree/payment_method/store_credit.rb', line 42
def purchase(amount_in_cents, store_credit, gateway_options = {})
eligible_events = store_credit.store_credit_events.where(
amount: amount_in_cents / 100.0.to_d,
action: Spree::StoreCredit::ELIGIBLE_ACTION
)
event = eligible_events.detect do |eligible_event|
store_credit.store_credit_events.where(authorization_code: eligible_event.authorization_code).
where.not(action: Spree::StoreCredit::ELIGIBLE_ACTION).empty?
end
if event.blank?
ActiveMerchant::Billing::Response.new(false, Spree.t('store_credit_payment_method.unable_to_find'), {}, {})
else
capture(amount_in_cents, event.authorization_code, gateway_options)
end
end
|