-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate all reusable credit card to wallet sources #1765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
default: credit_card.read_attribute(:default), | ||
) | ||
payment_source: credit_card | ||
) do |wallet_source| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL 👍
def up | ||
credit_cards = Spree::CreditCard. | ||
where(default: true). | ||
where("gateway_customer_profile_id IS NOT NULL"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where.not(gateway_customer_profile_id: nil)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes! I left a few questions/comments.
class WalletPaymentSource < ActiveRecord::Base | ||
self.table_name = 'spree_wallet_payment_sources' | ||
end | ||
|
||
def up | ||
credit_cards = Spree::CreditCard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to use CreditCard
here instead of Spree::CreditCard
?
where.not(user_id: nil) | ||
|
||
credit_cards.find_each do |credit_card| | ||
Spree::WalletPaymentSource.create!( | ||
Spree::WalletPaymentSource.find_or_create_by!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WalletPaymentSource
instead of Spree::WalletPaymentSource
?
) | ||
payment_source: credit_card | ||
) do |wallet_source| | ||
wallet_source.default = credit_card[:default] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this in a block instead of alongside the other attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use your in-migration classes you can just do credit_card.default
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing a block to find_or_create_by
behaves the same as passing a block to create
if the record doesn't already exist.
We want to do this here, because we absolutely only want to have one WalletPaymentSource
per credit card, the block specifies the values if one doesn't already exist. This makes the up migration idempotent, which we want since the down migration doesn't remove WalletPaymentSource
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I stared at this at least 10 times and still managed to miss the fact that you'd changed it from create
to find_or_create_by
:)
@@ -19,7 +27,7 @@ def down | |||
add_column :spree_credit_cards, :default, :boolean, default: false, null: false | |||
|
|||
wallet_payment_sources = Spree::WalletPaymentSource. | |||
where(default: true, source_type: 'Spree::CreditCard'). | |||
where(default: true, payment_source_type: 'Spree::CreditCard'). | |||
includes(:source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need some tweaking for the includes
to work with the in-migration classes right?
payment_source: credit_card | ||
) do |wallet_source| | ||
wallet_source.default = credit_card[:default] | ||
end | ||
end | ||
|
||
remove_column :spree_credit_cards, :default, :boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should hold off on actually dropping this column for another release.
Looking at it again right now I feel nervous about dropping a payment-related column like that. Holding off would make the "down" migration simpler also.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 As long as we provide deprecations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Spree::CreditCard#default
method does have deprecations, but if someone was doing a Spree::CreditCard.where(default: true)
I'm not sure how we could add a deprecation for that. Perhaps we could rename the column to deprecated_default
instead of dropping it? Or just go ahead and drop it?
8d8d472
to
5c16a23
Compare
user_id: credit_card.user_id, | ||
payment_source: credit_card | ||
) do |wallet_source| | ||
wallet_source.default = credit_card.default] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unexpected token tRBRACK
@jordan-brough I think I have addressed your feedback. It no longer removes the |
The behaviour prior to adding the Wallet was to allow reuse of any CreditCard which had a payment profile. However the migration was only migrating CreditCards marked "default". This now migrates all credit cards with an associated gateway_customer_profile_id. This also no longer removes the "default" column from the credit card, as we decided this was safer to leave in for at least one release.
5c16a23
to
0c37df7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, thanks.
Follow up to #1707
The behaviour prior to adding the Wallet was to allow reuse of any
CreditCard
which had a payment profile. However the migration was only migratingCreditCard
s markeddefault
.This now migrates all credit cards with an associated
gateway_customer_profile_id
.