125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/spree/store_credit.rb', line 125
def credit(amount, authorization_code, order_currency, options = {})
capture_event = store_credit_events.find_by(action: CAPTURE_ACTION, authorization_code: authorization_code)
if currency != order_currency
errors.add(:base, Spree.t('store_credit.currency_mismatch'))
false
elsif capture_event && amount <= capture_event.amount
action_attributes = {
action: CREDIT_ACTION,
action_amount: amount,
action_originator: options[:action_originator],
action_authorization_code: authorization_code
}
create_credit_record(amount, action_attributes)
true
else
errors.add(:base, Spree.t('store_credit.unable_to_credit', auth_code: authorization_code))
false
end
end
|