Class: SolidusSubscriptions::Installment

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/solidus_subscriptions/installment.rb

Instance Method Summary collapse

Instance Method Details

#failed!(order) ⇒ SolidusSubscriptions::InstallmentDetail

Mark this installment as a failure

Parameters:

  • order (Spree::Order)

    The order generated for this processing attempt

Returns:



70
71
72
73
74
75
76
77
78
# File 'app/models/solidus_subscriptions/installment.rb', line 70

def failed!(order)
  advance_actionable_date!

  details.create!(
    success: false,
    order: order,
    message: I18n.t('solidus_subscriptions.installment_details.failed')
  )
end

#fulfilled?Boolean

Had this installment been fulfilled by a completed order

Returns:

  • (Boolean)


90
91
92
# File 'app/models/solidus_subscriptions/installment.rb', line 90

def fulfilled?
  details.exists?(success: true)
end

#out_of_stockSolidusSubscriptions::InstallmentDetail

Mark this installment as out of stock.

Returns:



37
38
39
40
41
42
43
44
# File 'app/models/solidus_subscriptions/installment.rb', line 37

def out_of_stock
  advance_actionable_date!

  details.create!(
    success: false,
    message: I18n.t('solidus_subscriptions.installment_details.out_of_stock')
  )
end

#payment_failed!(order) ⇒ SolidusSubscriptions::InstallmentDetail

Mark this installment as having a failed payment

Parameters:

  • order (Spree::Order)

    The order generated for this processing attempt

Returns:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/models/solidus_subscriptions/installment.rb', line 108

def payment_failed!(order)
  details.create!(
    success: false,
    order: order,
    message: I18n.t('solidus_subscriptions.installment_details.payment_failed')
  )

  if subscription.maximum_reprocessing_time_reached? && !subscription.canceled?
    subscription.force_cancel!
    update!(actionable_date: nil)
  else
    advance_actionable_date!
  end
end

#stateSymbol

Returns the state of this fulfillment

Returns:

  • (Symbol)

    :fulfilled/:unfulfilled



97
98
99
# File 'app/models/solidus_subscriptions/installment.rb', line 97

def state
  fulfilled? ? :fulfilled : :unfulfilled
end

#success!(order) ⇒ SolidusSubscriptions::InstallmentDetail

Mark this installment as a success

Parameters:

  • order (Spree::Order)

    The order generated for this processing attempt

Returns:



53
54
55
56
57
58
59
60
61
# File 'app/models/solidus_subscriptions/installment.rb', line 53

def success!(order)
  update!(actionable_date: nil)

  details.create!(
    success: true,
    order: order,
    message: I18n.t('solidus_subscriptions.installment_details.success')
  )
end

#unfulfilled?Boolean

Does this installment still need to be fulfilled by a completed order

Returns:

  • (Boolean)


83
84
85
# File 'app/models/solidus_subscriptions/installment.rb', line 83

def unfulfilled?
  !fulfilled?
end