Class: IshManager::PricesController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/ish_manager/prices_controller.rb', line 7
def create
@price = Wco::Price.new params[:price].permit( :amount_cents, :interval, :product_id )
puts! @price, '@price'
authorize! :create, @price
if !params[:price][:interval].present?
@price.interval = nil
end
@product = Wco::Product.find @price.product_id
stripe_product = Stripe::Product.retrieve( @product.product_id )
price_hash = {
product: stripe_product.id,
unit_amount: @price.amount_cents,
currency: 'usd',
}
if @price.interval.present?
price_hash[:recurring] = { interval: @price.interval }
end
stripe_price = Stripe::Price.create( price_hash )
flash_notice 'Created stripe price.'
@price.product = @product
@price.price_id = stripe_price[:id]
if @price.save
flash_notice @price
else
flash_alert @price
end
redirect_to controller: :products, action: :index
end
|
#update ⇒ Object
38
39
40
41
42
43
|
# File 'app/controllers/ish_manager/prices_controller.rb', line 38
def update
end
|