Skip to content

Commit

Permalink
Migrate all reusable credit card to wallet sources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhawthorn committed Mar 14, 2017
1 parent 7289efd commit 0c37df7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class MigrateCreditCardsToWalletPaymentSources < ActiveRecord::Migration[4.2]
class CreditCard < ActiveRecord::Base
self.table_name = 'spree_credit_cards'
end
class WalletPaymentSource < ActiveRecord::Base
self.table_name = 'spree_wallet_payment_sources'
end

def up
credit_cards = CreditCard.
where.not(gateway_customer_profile_id: nil).
where.not(user_id: nil)

credit_cards.find_each do |credit_card|
WalletPaymentSource.find_or_create_by!(
user_id: credit_card.user_id,
payment_source: credit_card
) do |wallet_source|
wallet_source.default = credit_card.default
end
end
end

def down
end
end

This file was deleted.

0 comments on commit 0c37df7

Please sign in to comment.