Class: Checkout
- Inherits:
-
Object
- Object
- Checkout
- Includes:
- ActiveSupport::Callbacks, Ext::Callbacks::Checkout
- Defined in:
- app/models/checkout.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cart ⇒ Object
Returns the value of attribute cart.
-
#error ⇒ Object
Returns the value of attribute error.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#payment ⇒ Object
Returns the value of attribute payment.
-
#person ⇒ Object
readonly
Returns the value of attribute person.
Class Method Summary collapse
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(cart, payment) ⇒ Checkout
constructor
A new instance of Checkout.
- #message ⇒ Object
- #pay ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(cart, payment) ⇒ Checkout
Returns a new instance of Checkout.
28 29 30 31 32 33 |
# File 'app/models/checkout.rb', line 28 def initialize(cart, payment) @cart = cart @payment = payment @customer = payment.customer @payment.amount = @cart.total end |
Instance Attribute Details
#cart ⇒ Object
Returns the value of attribute cart.
8 9 10 |
# File 'app/models/checkout.rb', line 8 def cart @cart end |
#error ⇒ Object
Returns the value of attribute error.
8 9 10 |
# File 'app/models/checkout.rb', line 8 def error @error end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
9 10 11 |
# File 'app/models/checkout.rb', line 9 def order @order end |
#payment ⇒ Object
Returns the value of attribute payment.
8 9 10 |
# File 'app/models/checkout.rb', line 8 def payment @payment end |
#person ⇒ Object (readonly)
Returns the value of attribute person.
9 10 11 |
# File 'app/models/checkout.rb', line 9 def person @person end |
Class Method Details
.for(cart, payment) ⇒ Object
11 12 13 |
# File 'app/models/checkout.rb', line 11 def self.for(cart, payment) cart.checkout_class.new(cart, payment) end |
Instance Method Details
#finish ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/checkout.rb', line 48 def finish run_callbacks :payment do pay end if cart.approved? = Time.now run_callbacks :order do @created_orders = create_order() end cart.finish end cart.approved? end |
#message ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/checkout.rb', line 15 def = @payment.errors..to_sentence.downcase = .gsub('customer', 'contact info') = .gsub('credit card is', 'payment details are') = [0].upcase + [1...length] unless .blank? #capitalize first word if .blank? = "We had a problem validating your payment. Wait a few moments and try again or contact us to complete your purchase." end end |
#pay ⇒ Object
66 67 68 69 |
# File 'app/models/checkout.rb', line 66 def pay @cart.pay_with(@payment) @cart.approved? end |
#valid? ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/checkout.rb', line 35 def valid? unless (!!cart and !!payment and payment.valid?) return false end if cart.empty? @error = "Your tickets have expired. Please select your tickets again." return false end true end |