Class: Spree::PaymentMethod::StoreCredit
Constant Summary
DISPLAY
Instance Method Summary
collapse
active?, #auto_capture?, available, #deprecated_method_type_override, #display_on, #display_on=, find_with_destroyed, #gateway, #method_type, model_name, #options, #partial_name, #payment_profiles_supported?, providers, #reusable_sources, #store_credit?, #supports?
#preference_source=, #preferences, #preferences=
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#authorize(amount_in_cents, provided_store_credit, gateway_options = {}) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/models/spree/payment_method/store_credit.rb', line 7
def authorize(amount_in_cents, provided_store_credit, gateway_options = {})
if provided_store_credit.nil?
ActiveMerchant::Billing::Response.new(false, Spree.t('store_credit.unable_to_find'), {}, {})
else
action = ->(store_credit) {
store_credit.authorize(
amount_in_cents / 100.0.to_d,
gateway_options[:currency],
action_originator: gateway_options[:originator]
)
}
handle_action_call(provided_store_credit, action, :authorize)
end
end
|
#capture(amount_in_cents, auth_code, gateway_options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/models/spree/payment_method/store_credit.rb', line 22
def capture(amount_in_cents, auth_code, gateway_options = {})
action = ->(store_credit) {
store_credit.capture(
amount_in_cents / 100.0.to_d,
auth_code,
gateway_options[:currency],
action_originator: gateway_options[:originator]
)
}
handle_action(action, :capture, auth_code)
end
|
#credit(amount_in_cents, auth_code, gateway_options = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'app/models/spree/payment_method/store_credit.rb', line 56
def credit(amount_in_cents, auth_code, gateway_options = {})
action = ->(store_credit) do
currency = gateway_options[:currency] || store_credit.currency
originator = gateway_options[:originator]
store_credit.credit(amount_in_cents / 100.0.to_d, auth_code, currency, action_originator: originator)
end
handle_action(action, :credit, auth_code)
end
|
#payment_source_class ⇒ Object
3
4
5
|
# File 'app/models/spree/payment_method/store_credit.rb', line 3
def payment_source_class
::Spree::StoreCredit
end
|
#purchase(amount_in_cents, store_credit, gateway_options = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/models/spree/payment_method/store_credit.rb', line 35
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.find 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.unable_to_find'), {}, {})
else
capture(amount_in_cents, event.authorization_code, gateway_options)
end
end
|
#source_required? ⇒ Boolean
84
85
86
|
# File 'app/models/spree/payment_method/store_credit.rb', line 84
def source_required?
true
end
|
#try_void(payment) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/models/spree/payment_method/store_credit.rb', line 68
def try_void(payment)
auth_code = payment.response_code
store_credit_event = auth_or_capture_event(auth_code)
store_credit = store_credit_event.try(:store_credit)
if store_credit_event.nil? || store_credit.nil?
ActiveMerchant::Billing::Response.new(false, '', {}, {})
elsif store_credit_event.capture_action?
false elsif store_credit_event.authorization_action?
void(auth_code)
else
ActiveMerchant::Billing::Response.new(false, '', {}, {})
end
end
|
#void(auth_code, gateway_options = {}) ⇒ Object
49
50
51
52
53
54
|
# File 'app/models/spree/payment_method/store_credit.rb', line 49
def void(auth_code, gateway_options = {})
action = ->(store_credit) {
store_credit.void(auth_code, action_originator: gateway_options[:originator])
}
handle_action(action, :void, auth_code)
end
|