Class: Spree::PaymentMethod::StoreCredit
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- Spree::PaymentMethod::StoreCredit
- Defined in:
- app/models/spree/payment_method/store_credit.rb
Instance Method Summary collapse
- #authorize(amount_in_cents, provided_store_credit, gateway_options = {}) ⇒ Object
- #capture(amount_in_cents, auth_code, gateway_options = {}) ⇒ Object
- #credit(amount_in_cents, auth_code, gateway_options = {}) ⇒ Object
- #payment_source_class ⇒ Object
- #purchase(amount_in_cents, store_credit, gateway_options = {}) ⇒ Object
- #source_required? ⇒ Boolean
- #try_void(payment) ⇒ Object
- #void(auth_code, gateway_options = {}) ⇒ Object
Instance Method Details
#authorize(amount_in_cents, provided_store_credit, gateway_options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/spree/payment_method/store_credit.rb', line 9 def (amount_in_cents, provided_store_credit, = {}) if provided_store_credit.nil? ActiveMerchant::Billing::Response.new(false, I18n.t("spree.store_credit.unable_to_find"), {}, {}) else action = ->(store_credit) { store_credit.( amount_in_cents / BigDecimal("100.0"), [:currency], action_originator: [:originator] ) } handle_action_call(provided_store_credit, action, :authorize) end end |
#capture(amount_in_cents, auth_code, gateway_options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/spree/payment_method/store_credit.rb', line 24 def capture(amount_in_cents, auth_code, = {}) action = ->(store_credit) { store_credit.capture( amount_in_cents / BigDecimal("100.0"), auth_code, [:currency], action_originator: [:originator] ) } handle_action(action, :capture, auth_code) end |
#credit(amount_in_cents, auth_code, gateway_options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/spree/payment_method/store_credit.rb', line 58 def credit(amount_in_cents, auth_code, = {}) action = ->(store_credit) do currency = [:currency] || store_credit.currency originator = [:originator] store_credit.credit(amount_in_cents / BigDecimal("100.0"), auth_code, currency, action_originator: originator) end handle_action(action, :credit, auth_code) end |
#payment_source_class ⇒ Object
5 6 7 |
# File 'app/models/spree/payment_method/store_credit.rb', line 5 def payment_source_class ::Spree::StoreCredit end |
#purchase(amount_in_cents, store_credit, gateway_options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/spree/payment_method/store_credit.rb', line 37 def purchase(amount_in_cents, store_credit, = {}) eligible_events = store_credit.store_credit_events.where(amount: amount_in_cents / BigDecimal("100.0"), action: Spree::StoreCredit::ELIGIBLE_ACTION) event = eligible_events.find do |eligible_event| store_credit.store_credit_events.where(authorization_code: eligible_event.) .where.not(action: Spree::StoreCredit::ELIGIBLE_ACTION).empty? end if event.blank? ActiveMerchant::Billing::Response.new(false, I18n.t("spree.store_credit.unable_to_find"), {}, {}) else capture(amount_in_cents, event., ) end end |
#source_required? ⇒ Boolean
86 87 88 |
# File 'app/models/spree/payment_method/store_credit.rb', line 86 def source_required? true end |
#try_void(payment) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/spree/payment_method/store_credit.rb', line 70 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 # payment#cancel! handles the refund elsif store_credit_event. void(auth_code) else ActiveMerchant::Billing::Response.new(false, "", {}, {}) end end |
#void(auth_code, gateway_options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'app/models/spree/payment_method/store_credit.rb', line 51 def void(auth_code, = {}) action = ->(store_credit) { store_credit.void(auth_code, action_originator: [:originator]) } handle_action(action, :void, auth_code) end |