Class: Spree::GiftCard

Inherits:
Object
  • Object
show all
Extended by:
DisplayMoney
Includes:
Security::GiftCards, SingleStoreResource
Defined in:
app/models/spree/gift_card.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DisplayMoney

money_methods

Class Method Details

.json_api_columnsObject



88
89
90
# File 'app/models/spree/gift_card.rb', line 88

def self.json_api_columns
  %w[code amount expires_at]
end

Instance Method Details

#active?Boolean

Checks if the gift card is active, i.e. not expired and not redeemed

Returns:

  • (Boolean)


118
119
120
# File 'app/models/spree/gift_card.rb', line 118

def active?
  super && !expired?
end

#amount=(amount) ⇒ Object

Sets the amount

Parameters:

  • amount (String)


76
77
78
# File 'app/models/spree/gift_card.rb', line 76

def amount=(amount)
  self[:amount] = Spree::LocalizedNumber.parse(amount)
end

#amount_remainingDecimal

Calculates the remaining amount

Returns:

  • (Decimal)


82
83
84
# File 'app/models/spree/gift_card.rb', line 82

def amount_remaining
  amount - amount_used - amount_authorized
end

#can_be_deleted?Boolean

Checks if the gift card can be deleted

Returns:

  • (Boolean)


100
101
102
# File 'app/models/spree/gift_card.rb', line 100

def can_be_deleted?
  !redeemed? && !partially_redeemed?
end

#display_codeString

Displays the code in uppercase, eg. ABC1234

Returns:

  • (String)


106
107
108
# File 'app/models/spree/gift_card.rb', line 106

def display_code
  code.upcase
end

#display_stateString

Displays state as expired if the gift card is expired, otherwise displays the state

Returns:

  • (String)


124
125
126
127
128
129
130
# File 'app/models/spree/gift_card.rb', line 124

def display_state
  if expired?
    :expired
  else
    state
  end.to_s
end

#editable?Boolean

Checks if the gift card is editable

Returns:

  • (Boolean)


94
95
96
# File 'app/models/spree/gift_card.rb', line 94

def editable?
  active?
end

#expired?Boolean

Checks if the gift card is expired

Returns:

  • (Boolean)


112
113
114
# File 'app/models/spree/gift_card.rb', line 112

def expired?
  !redeemed? && expires_at.present? && expires_at <= Date.current
end