mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
fix bug: user cant debit his wallet when admin pay a plan for this user with invoice disabled
This commit is contained in:
parent
5a4eaefc02
commit
f487133825
@ -15,7 +15,7 @@ class API::SubscriptionsController < API::ApiController
|
||||
if current_user.is_admin?
|
||||
@subscription = Subscription.find_or_initialize_by(user_id: subscription_params[:user_id])
|
||||
@subscription.attributes = subscription_params
|
||||
is_subscribe = @subscription.save_with_local_payment(!User.find(subscription_params[:user_id]).invoicing_disabled?, coupon_params[:coupon_code])
|
||||
is_subscribe = @subscription.save_with_local_payment(true, coupon_params[:coupon_code])
|
||||
else
|
||||
@subscription = Subscription.find_or_initialize_by(user_id: current_user.id)
|
||||
@subscription.attributes = subscription_params
|
||||
|
@ -18,6 +18,8 @@ class Subscription < ActiveRecord::Base
|
||||
after_save :notify_partner_subscribed_plan, if: :of_partner_plan?
|
||||
|
||||
# Stripe subscription payment
|
||||
# @params [invoice] if true then subscription pay itself, dont pay with reservation
|
||||
# if false then subscription pay with reservation
|
||||
def save_with_payment(invoice = true, coupon_code = nil)
|
||||
if valid?
|
||||
begin
|
||||
@ -131,6 +133,8 @@ class Subscription < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# @params [invoice] if true then subscription pay itself, dont pay with reservation
|
||||
# if false then subscription pay with reservation
|
||||
def save_with_local_payment(invoice = true, coupon_code = nil)
|
||||
if valid?
|
||||
# very important to set expired_at to nil that can allow method is_new? to return true
|
||||
@ -143,16 +147,19 @@ class Subscription < ActiveRecord::Base
|
||||
if save
|
||||
UsersCredits::Manager.new(user: self.user).reset_credits if expired_date_changed
|
||||
if invoice
|
||||
invoc = generate_invoice(nil, coupon_code)
|
||||
@wallet_amount_debit = get_wallet_amount_debit
|
||||
|
||||
# debit wallet
|
||||
wallet_transaction = debit_user_wallet
|
||||
if wallet_transaction
|
||||
invoc.wallet_amount = @wallet_amount_debit
|
||||
invoc.wallet_transaction_id = wallet_transaction.id
|
||||
|
||||
if !self.user.invoicing_disabled?
|
||||
invoc = generate_invoice(nil, coupon_code)
|
||||
if wallet_transaction
|
||||
invoc.wallet_amount = @wallet_amount_debit
|
||||
invoc.wallet_transaction_id = wallet_transaction.id
|
||||
end
|
||||
invoc.save
|
||||
end
|
||||
invoc.save
|
||||
end
|
||||
return true
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user