Class: Payola::Sale

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AASM, GuidBehavior
Defined in:
app/models/payola/sale.rb

Instance Method Summary collapse

Methods included from GuidBehavior

#populate_guid

Instance Method Details

#custom_fieldsObject



67
68
69
70
71
72
73
# File 'app/models/payola/sale.rb', line 67

def custom_fields
  if self.signed_custom_fields.present?
    verifier.verify(self.signed_custom_fields)
  else
    nil
  end      
end

#redirectorObject



75
76
77
# File 'app/models/payola/sale.rb', line 75

def redirector
  product
end

#verifierObject



46
47
48
# File 'app/models/payola/sale.rb', line 46

def verifier
  @verifier ||= ActiveSupport::MessageVerifier.new(Payola.secret_key_for_sale(self), digest: 'SHA256')
end

#verify_chargeObject



50
51
52
53
54
55
56
57
# File 'app/models/payola/sale.rb', line 50

def verify_charge
  begin
    self.verify_charge!
  rescue RuntimeError => e
    self.error = e.message
    self.fail!
  end
end

#verify_charge!Object



59
60
61
62
63
64
65
# File 'app/models/payola/sale.rb', line 59

def verify_charge!
  if Payola.charge_verifier.arity > 1
    Payola.charge_verifier.call(self, custom_fields)
  else
    Payola.charge_verifier.call(self)
  end
end