Class: IshManager::SubscriptionsController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
A stripe subscription is currently single-item only.
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
37
38
39
40
41
42
43
|
# File 'app/controllers/ish_manager/subscriptions_controller.rb', line 11
def create
@subscription = Wco::Subscription.new params[:subscription].permit!
authorize! :create, @subscription
@subscription.leadset_id = Leadset.where({ customer_id: params[:subscription][:customer_id] }).first&.id
@subscription.price = Wco::Price.find_by price_id: params[:subscription][:price_id]
@subscription.product = @subscription.price.product
if params[:is_stripe]
payment_methods = Stripe::Customer.list_payment_methods( params[:subscription][:customer_id] ).data
params = {
customer: params[:subscription][:customer_id],
default_payment_method: payment_methods[0][:id],
items: [
{ price: params[:subscription][:price_id],
quantity: params[:subscription][:quantity],
},
],
}
@stripe_subscription = Stripe::Subscription.create( params )
flash_notice @stripe_subscription
end
flag = @subscription.save
if flag
flash_notice @subscription
redirect_to action: :show, id: @subscription.id
else
flash_alert @subscription
redirect_to action: :new
end
end
|
#index ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/ish_manager/subscriptions_controller.rb', line 46
def index
authorize! :index, Wco::Subscription
@stripe_customers = Stripe::Customer.list().data
@stripe_subscriptions = Stripe::Subscription.list().data
@customers = {} customer_ids = @stripe_customers.map &:id
@leadsets = Leadset.where( :customer_id.in => customer_ids )
@leadsets.each do |i|
@customers[i[:customer_id]] ||= {}
@customers[i[:customer_id]][:leadsets] ||= []
@customers[i[:customer_id]][:leadsets].push( i )
end
@profiles = Ish::UserProfile.where( :customer_id.in => customer_ids )
@profiles.each do |i|
@customers[i[:customer_id]] ||= {}
@customers[i[:customer_id]][:profiles] ||= []
@customers[i[:customer_id]][:profiles].push( i )
end
@wco_subscriptions = Wco::Subscription.all
end
|
#new ⇒ Object
72
73
74
75
|
# File 'app/controllers/ish_manager/subscriptions_controller.rb', line 72
def new
@subscription = Wco::Subscription.new
authorize! :new, @subscription
end
|
#new_stripe ⇒ Object
77
78
79
80
|
# File 'app/controllers/ish_manager/subscriptions_controller.rb', line 77
def new_stripe
@subscription = Wco::Subscription.new
authorize! :new, @subscription
end
|
#new_wco ⇒ Object
82
83
84
85
|
# File 'app/controllers/ish_manager/subscriptions_controller.rb', line 82
def new_wco
@subscription = Wco::Subscription.new
authorize! :new, @subscription
end
|
#show ⇒ Object
87
88
89
90
|
# File 'app/controllers/ish_manager/subscriptions_controller.rb', line 87
def show
@subscription = Wco::Subscription.find params[:id]
authorize! :show, @subscription
end
|