Class: Spree::PaymentSource

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/payment_source.rb

Direct Known Subclasses

CreditCard, StoreCredit

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

#admin_form_preference_names, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Attribute Details

#importedObject

Returns the value of attribute imported



10
11
12
# File 'app/models/spree/payment_source.rb', line 10

def imported
  @imported
end

Instance Method Details

#actionsArray<String>

Returns the actions available on this payment source

Returns:

  • (Array<String>)

    the actions available on this payment source



13
14
15
# File 'app/models/spree/payment_source.rb', line 13

def actions
  %w(capture void credit)
end

#can_capture?(payment) ⇒ Boolean

Returns true when the payment is in the pending or checkout states

Parameters:

  • payment (Spree::Payment)

    the payment we want to know if can be captured

Returns:

  • (Boolean)

    true when the payment is in the pending or checkout states



19
20
21
# File 'app/models/spree/payment_source.rb', line 19

def can_capture?(payment)
  payment.pending? || payment.checkout?
end

#can_credit?(payment) ⇒ Boolean

Indicates whether its possible to credit the payment. Note that most gateways require that the payment be settled first which generally happens within 12-24 hours of the transaction.

Parameters:

  • payment (Spree::Payment)

    the payment we want to know if can be credited

Returns:

  • (Boolean)

    true when the payment is completed and can be credited



35
36
37
# File 'app/models/spree/payment_source.rb', line 35

def can_credit?(payment)
  payment.completed? && payment.credit_allowed > 0
end

#can_void?(payment) ⇒ Boolean

Returns true when the payment is not failed or voided

Parameters:

  • payment (Spree::Payment)

    the payment we want to know if can be voided

Returns:

  • (Boolean)

    true when the payment is not failed or voided



25
26
27
# File 'app/models/spree/payment_source.rb', line 25

def can_void?(payment)
  !payment.failed? && !payment.void?
end

#reusable?Boolean

Indicates whether this payment source can be used more than once. E.g. a credit card with a 'payment profile'.

Returns:

  • (Boolean)


41
42
43
# File 'app/models/spree/payment_source.rb', line 41

def reusable?
  false
end