Last active
December 11, 2015 20:49
-
-
Save mhenrixon/4658337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Refill | |
attr_reader :card, :product, :prices, :details, :total_price | |
def initialize(card, product, discount_price = nil) | |
@card = card | |
@product = product | |
@discount_price = discount_price | |
@prices = product.prices.map(&:price) | |
@total_price = if product.product_type === 'discount' | |
set_discount_price | |
else | |
set_regular_price | |
end | |
end | |
def set_discount_price | |
@details = @card.purse_details | |
if prices.include?(discount_price.to_i) | |
discount_price | |
else | |
prices[0] | |
end | |
end | |
def set_regular_price | |
@details = card.period_details | |
card.period_price | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Public::RefillsController < ApplicationController | |
def new | |
card = Card.find(params[:card_id]) | |
product = Product.find(params[:product_id]) | |
@refill = Refill.new(car, product, params[:discount_price]) | |
find_or_create_order | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment