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
44
45
46
|
# File 'app/controllers/kaui/chargebacks_controller.rb', line 12
def create
cached_options_for_klient = options_for_klient
@chargeback = Kaui::Chargeback.new(params.require(:chargeback))
should_cancel_subs = (params[:cancel_all_subs] == '1')
begin
payment = @chargeback.chargeback(current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)
rescue StandardError => e
flash.now[:error] = "Error while creating a new chargeback: #{as_string(e)}"
render action: :new and return
end
if should_cancel_subs
begin
account = Kaui::Account.find_by_id(payment.account_id, false, false, cached_options_for_klient)
account.bundles(cached_options_for_klient).each do |bundle|
bundle.subscriptions.each do |subscription|
next if subscription.billing_end_date.present?
entitlement = Kaui::Subscription.new(subscription_id: subscription.subscription_id)
entitlement.cancel_entitlement_immediately(current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)
end
end
rescue StandardError => e
flash[:error] = "Error while cancelling subscriptions: #{as_string(e)}"
render action: :new and return
end
end
redirect_to kaui_engine.account_payment_path(payment.account_id, payment.payment_id), notice: 'Chargeback created'
end
|