Class: Spree::PaymentSession

Inherits:
Object
  • Object
show all
Includes:
Metafields
Defined in:
app/models/spree/payment_session.rb

Instance Method Summary collapse

Instance Method Details

#amount_in_centsObject



67
68
69
# File 'app/models/spree/payment_session.rb', line 67

def amount_in_cents
  money.cents
end

#expired?Boolean

Returns:



75
76
77
# File 'app/models/spree/payment_session.rb', line 75

def expired?
  expires_at.present? && expires_at <= Time.current
end

#find_or_create_payment!(metadata = {}) ⇒ Spree::Payment

Creates or finds the Spree::Payment record for this session. Gateway subclasses can override this in their PaymentSession subclass to handle gateway-specific source creation (credit cards, wallets, etc).

Parameters:

  • metadata (Hash) (defaults to: {})

    gateway-specific metadata

Returns:



85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/spree/payment_session.rb', line 85

def find_or_create_payment!( = {})
  return payment if payment.present?

  order.payments.find_or_create_by!(
    payment_method: payment_method,
    response_code: external_id,
  ) do |p|
    p.amount = amount
    p.skip_source_requirement = true
  end
end

#moneyObject



71
72
73
# File 'app/models/spree/payment_session.rb', line 71

def money
  @money ||= Spree::Money.new(amount, currency: currency)
end