Class: Gold::InstallOp

Inherits:
Object
  • Object
show all
Includes:
Outcomes
Defined in:
app/operations/gold/install_op.rb

Overview

Invoked when a shop has installed (or reinstalled) this app.

Constant Summary

Constants included from Outcomes

Outcomes::AcceptedCharge, Outcomes::AcceptedTerms, Outcomes::ActiveCharge, Outcomes::CannotApplyDiscount, Outcomes::CannotIssueCredit, Outcomes::CannotProcessCharge, Outcomes::CannotSelectTier, Outcomes::ChargeNeeded, Outcomes::ChargeNotNeeded, Outcomes::DeclinedCharge, Outcomes::DeclinedTerms, Outcomes::ExpiredCharge, Outcomes::FrozenCharge, Outcomes::MismatchCharge, Outcomes::MissingCharge, Outcomes::PendingCharge, Outcomes::SameDiscount, Outcomes::SameTier, Outcomes::TierApplied, Outcomes::TierNotFound, Outcomes::Uninstalled

Instance Method Summary collapse

Constructor Details

#initialize(billing) ⇒ InstallOp

Returns a new instance of InstallOp.



8
9
10
# File 'app/operations/gold/install_op.rb', line 8

def initialize(billing)
  @billing = billing
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/operations/gold/install_op.rb', line 12

def call
  # If possible, transition to reinstalled
  @billing.transition_to(:reinstalled)

  case @billing.current_state
  when :new, :reinstalled
    Gold.configuration.on_install&.call(@billing)
  when :frozen
    return CheckChargeOp.new(@billing).call
  when :cleanup
    Gold.logger.warn("[#{@billing.id}] Tried installing?" \
                     "'#{@billing.shop.shopify_domain}', but on cleanup")
    return InstallFailed.new(:cleanup_in_progress)
  end

  Success.new
end