Skip to content

Commit

Permalink
Deprecate @payment_sources ivar from checkout payments controller
Browse files Browse the repository at this point in the history
This method returns payment sources of the current user. It is no more
used into our frontend. We used to assign the content of this method
into an ivar (@payment_sources) into the checkout payment step. This
method is here only to be able to deprecate this ivar and will be removed.
  • Loading branch information
kennyadsl committed Mar 1, 2019
1 parent 762fbe4 commit 52374f4
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions frontend/app/controllers/spree/checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,14 @@ def before_payment
@wallet_payment_sources = try_spree_current_user.wallet.wallet_payment_sources
@default_wallet_payment_source = @wallet_payment_sources.detect(&:default) ||
@wallet_payment_sources.first
# TODO: How can we deprecate this instance variable? We could try
# wrapping it in a delegating object that produces deprecation warnings.
@payment_sources = try_spree_current_user.wallet.wallet_payment_sources.map(&:payment_source).select { |ps| ps.is_a?(Spree::CreditCard) }

@payment_sources = Spree::DeprecatedInstanceVariableProxy.new(
self,
:deprecated_payment_sources,
:@payment_sources,
Spree::Deprecation,
"Please, do not use @payment_sources anymore, use @wallet_payment_sources instead."
)
end
end

Expand Down Expand Up @@ -251,5 +256,22 @@ def insufficient_stock_error
end
end
end

# This method returns payment sources of the current user. It is no more
# used into our frontend. We used to assign the content of this method
# into an ivar (@payment_sources) into the checkout payment step. This
# method is here only to be able to deprecate this ivar and will be removed.
#
# DO NOT USE THIS METHOD!
#
# @return [Array<Spree::PaymentSource>] Payment sources connected to
# current user wallet.
# @deprecated This method has been added to deprecate @payment_sources
# ivar and will be removed. Use @wallet_payment_sources instead.
def deprecated_payment_sources
try_spree_current_user.wallet.wallet_payment_sources
.map(&:payment_source)
.select { |ps| ps.is_a?(Spree::CreditCard) }
end
end
end

0 comments on commit 52374f4

Please sign in to comment.