spree_pag_seguro 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/app/models/spree/pag_seguro_payment.rb +1 -0
- data/lib/spree_pag_seguro/engine.rb +1 -7
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/admin/all.js +10 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/javascripts/store/all.js +10 -0
- data/spec/dummy/app/assets/stylesheets/admin/all.css +11 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/store/all.css +11 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +60 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +18 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/spree.rb +12 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spree.yml +2 -0
- data/spec/dummy/db/dummy_test +0 -0
- data/spec/dummy/db/migrate/20120301154050_spree_zero_nine_zero.rb +389 -0
- data/spec/dummy/db/migrate/20120301154051_create_indexes_for_inventory_units.rb +6 -0
- data/spec/dummy/db/migrate/20120301154052_add_count_on_hand_to_variants_and_products.rb +49 -0
- data/spec/dummy/db/migrate/20120301154053_change_taxons_to_nested_set.rb +46 -0
- data/spec/dummy/db/migrate/20120301154054_move_to_configurable_gateways.rb +54 -0
- data/spec/dummy/db/migrate/20120301154055_product_groups_and_scopes.rb +18 -0
- data/spec/dummy/db/migrate/20120301154056_add_open_id_authentication_tables.rb +15 -0
- data/spec/dummy/db/migrate/20120301154057_add_openid_field_to_users.rb +24 -0
- data/spec/dummy/db/migrate/20120301154058_change_preference_value_type.rb +10 -0
- data/spec/dummy/db/migrate/20120301154059_create_billing_integrations.rb +12 -0
- data/spec/dummy/db/migrate/20120301154060_charge_refactoring.rb +39 -0
- data/spec/dummy/db/migrate/20120301154061_add_some_indexes.rb +11 -0
- data/spec/dummy/db/migrate/20120301154062_checkout_state_machine.rb +5 -0
- data/spec/dummy/db/migrate/20120301154063_state_for_shipments.rb +5 -0
- data/spec/dummy/db/migrate/20120301154064_make_state_events_polymorphic.rb +12 -0
- data/spec/dummy/db/migrate/20120301154065_ship_address_id_for_checkouts.rb +5 -0
- data/spec/dummy/db/migrate/20120301154066_shipping_method_id_for_checkouts.rb +5 -0
- data/spec/dummy/db/migrate/20120301154067_creditcard_last_four_digits.rb +14 -0
- data/spec/dummy/db/migrate/20120301154068_populate_legacy_shipment_state.rb +15 -0
- data/spec/dummy/db/migrate/20120301154069_add_cost_price.rb +5 -0
- data/spec/dummy/db/migrate/20120301154070_shipment_id_for_inventory_units.rb +25 -0
- data/spec/dummy/db/migrate/20120301154071_cim_fields_for_creditcards.rb +6 -0
- data/spec/dummy/db/migrate/20120301154072_create_return_authorizations.rb +12 -0
- data/spec/dummy/db/migrate/20120301154073_add_return_authorization_to_inventory_units.rb +5 -0
- data/spec/dummy/db/migrate/20120301154074_create_trackers.rb +10 -0
- data/spec/dummy/db/migrate/20120301154075_creditcard_id_for_creditcard_txns.rb +5 -0
- data/spec/dummy/db/migrate/20120301154076_original_creditcard_txn_id_for_creditcard_txns.rb +5 -0
- data/spec/dummy/db/migrate/20120301154077_add_test_mode_to_billing_integration.rb +6 -0
- data/spec/dummy/db/migrate/20120301154078_create_products_product_groups.rb +8 -0
- data/spec/dummy/db/migrate/20120301154079_create_payment_methods.rb +16 -0
- data/spec/dummy/db/migrate/20120301154080_polymorphic_payments.rb +42 -0
- data/spec/dummy/db/migrate/20120301154081_change_payments_payment_method_to_belongs_to.rb +11 -0
- data/spec/dummy/db/migrate/20120301154082_assign_creditcard_txns_to_payment.rb +23 -0
- data/spec/dummy/db/migrate/20120301154083_sti_for_transactions.rb +15 -0
- data/spec/dummy/db/migrate/20120301154084_drop_billing_integrations.rb +16 -0
- data/spec/dummy/db/migrate/20120301154085_deleted_at_for_payment_methods.rb +14 -0
- data/spec/dummy/db/migrate/20120301154086_add_adjustments_index.rb +6 -0
- data/spec/dummy/db/migrate/20120301154087_fix_by_popularity.rb +9 -0
- data/spec/dummy/db/migrate/20120301154088_add_alt_text_to_images.rb +5 -0
- data/spec/dummy/db/migrate/20120301154089_fix_existing_coupon_credits.rb +13 -0
- data/spec/dummy/db/migrate/20120301154090_add_display_to_payment_methods.rb +5 -0
- data/spec/dummy/db/migrate/20120301154091_add_addresses_checkouts_indexes.rb +8 -0
- data/spec/dummy/db/migrate/20120301154092_add_icon_to_taxons.rb +17 -0
- data/spec/dummy/db/migrate/20120301154093_add_description_to_taxons.rb +11 -0
- data/spec/dummy/db/migrate/20120301154094_index_for_shipments_number.rb +5 -0
- data/spec/dummy/db/migrate/20120301154095_add_index_on_users_persistence_token.rb +5 -0
- data/spec/dummy/db/migrate/20120301154096_add_default_to_tax_categories.rb +5 -0
- data/spec/dummy/db/migrate/20120301154097_add_display_to_shipping_methods.rb +5 -0
- data/spec/dummy/db/migrate/20120301154098_rename_payment_method_display.rb +5 -0
- data/spec/dummy/db/migrate/20120301154099_rename_preferences_field.rb +5 -0
- data/spec/dummy/db/migrate/20120301154100_add_guest_flag.rb +5 -0
- data/spec/dummy/db/migrate/20120301154101_drop_order_token.rb +9 -0
- data/spec/dummy/db/migrate/20120301154102_payments_state_and_assigned_to_order_only.rb +14 -0
- data/spec/dummy/db/migrate/20120301154103_create_address_keys_for_order.rb +6 -0
- data/spec/dummy/db/migrate/20120301154104_payment_total_for_orders.rb +5 -0
- data/spec/dummy/db/migrate/20120301154105_shipping_method_id_for_orders.rb +5 -0
- data/spec/dummy/db/migrate/20120301154106_add_shipment_and_payment_state.rb +6 -0
- data/spec/dummy/db/migrate/20120301154107_refactor_adjustments.rb +29 -0
- data/spec/dummy/db/migrate/20120301154108_response_code_and_avs_response_for_payments.rb +6 -0
- data/spec/dummy/db/migrate/20120301154109_change_guest_flag_to_anonymous.rb +5 -0
- data/spec/dummy/db/migrate/20120301154110_email_for_orders.rb +5 -0
- data/spec/dummy/db/migrate/20120301154111_create_mail_methods.rb +10 -0
- data/spec/dummy/db/migrate/20120301154112_rename_frozen_to_locked.rb +5 -0
- data/spec/dummy/db/migrate/20120301154113_move_special_instructions_to_orders.rb +10 -0
- data/spec/dummy/db/migrate/20120301154114_create_log_entries.rb +11 -0
- data/spec/dummy/db/migrate/20120301154115_migrate_transactions_to_payment_state.rb +98 -0
- data/spec/dummy/db/migrate/20120301154116_delete_in_progress_orders.rb +19 -0
- data/spec/dummy/db/migrate/20120301154117_migrate_checkout_to_orders.rb +23 -0
- data/spec/dummy/db/migrate/20120301154118_remove_shipped_state.rb +12 -0
- data/spec/dummy/db/migrate/20120301154119_prevent_nil_payment_total.rb +8 -0
- data/spec/dummy/db/migrate/20120301154120_prevent_nil_email.rb +9 -0
- data/spec/dummy/db/migrate/20120301154121_generate_anonymous_users.rb +20 -0
- data/spec/dummy/db/migrate/20120301154122_update_order_state.rb +12 -0
- data/spec/dummy/db/migrate/20120301154123_cleanup_legacy_tables.rb +11 -0
- data/spec/dummy/db/migrate/20120301154124_remove_number_and_cvv_from_credicard.rb +11 -0
- data/spec/dummy/db/migrate/20120301154125_drop_anonymous_field_for_user.rb +9 -0
- data/spec/dummy/db/migrate/20120301154126_renamed_rma_cancelled_state.rb +9 -0
- data/spec/dummy/db/migrate/20120301154127_fix_problematic_index_names.rb +13 -0
- data/spec/dummy/db/migrate/20120301154128_add_position_to_variants.rb +5 -0
- data/spec/dummy/db/migrate/20120301154129_add_next_state_to_state_events.rb +5 -0
- data/spec/dummy/db/migrate/20120301154130_add_position_to_option_types.rb +5 -0
- data/spec/dummy/db/migrate/20120301154131_remove_trailing_slashes_in_taxon_permalinks.rb +19 -0
- data/spec/dummy/db/migrate/20120301154132_create_activators.rb +14 -0
- data/spec/dummy/db/migrate/20120301154133_eligible_for_adjustments.rb +5 -0
- data/spec/dummy/db/migrate/20120301154134_namespace_top_level_models.rb +52 -0
- data/spec/dummy/db/migrate/20120301154135_migrate_namespaced_polymorphic_models.rb +52 -0
- data/spec/dummy/db/migrate/20120301154136_make_adjustments_polymorphic.rb +9 -0
- data/spec/dummy/db/migrate/20120301154137_add_company_to_addresses.rb +5 -0
- data/spec/dummy/db/migrate/20120301154138_add_inc_tax_to_tax_rates.rb +5 -0
- data/spec/dummy/db/migrate/20120301154139_rename_inc_price_attribute.rb +5 -0
- data/spec/dummy/db/migrate/20120301154140_add_default_tax_zone.rb +5 -0
- data/spec/dummy/db/migrate/20120301154141_associate_shipping_methods_and_shipping_categories.rb +7 -0
- data/spec/dummy/db/migrate/20120301154142_add_match_rules_to_shipping_methods.rb +7 -0
- data/spec/dummy/db/migrate/20120301154143_new_preferences.rb +48 -0
- data/spec/dummy/db/migrate/20120301154144_add_deleted_at_to_tax_category.rb +5 -0
- data/spec/dummy/db/migrate/20120301154145_create_spree_payment_notifications.rb +12 -0
- data/spec/dummy/db/migrate/20120301154146_create_spree_pag_seguro_payments.rb +8 -0
- data/spec/dummy/db/schema.rb +569 -0
- data/spec/dummy/db/seeds.rb +11 -0
- data/spec/dummy/log/test.log +1073 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/dummy/script/rails +6 -0
- metadata +151 -16
@@ -0,0 +1,42 @@
|
|
1
|
+
# Legacy table support
|
2
|
+
class Checkout < ActiveRecord::Base; end;
|
3
|
+
|
4
|
+
class PolymorphicPayments < ActiveRecord::Migration
|
5
|
+
def up
|
6
|
+
remove_column :payments, :type
|
7
|
+
remove_column :payments, :creditcard_id
|
8
|
+
rename_column :payments, :order_id, :payable_id
|
9
|
+
change_table :payments do |t|
|
10
|
+
t.string :payable_type, :payment_method
|
11
|
+
t.references :source, :polymorphic => true
|
12
|
+
end
|
13
|
+
execute "UPDATE payments SET payable_type = 'Order'"
|
14
|
+
|
15
|
+
Spree::Creditcard.table_name = 'creditcards'
|
16
|
+
|
17
|
+
Spree::Creditcard.all.each do |creditcard|
|
18
|
+
if checkout = Checkout.find_by_id(creditcard.checkout_id) and checkout.order
|
19
|
+
if payment = checkout.order.payments.first
|
20
|
+
execute "UPDATE payments SET source_type = 'Creditcard', source_id = #{creditcard.id} WHERE id = #{payment.id}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Spree::Creditcard.table_name = 'spree_creditcards'
|
26
|
+
|
27
|
+
remove_column :creditcards, :checkout_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def down
|
31
|
+
add_column :creditcards, :checkout_id, :integer
|
32
|
+
change_table :payments do |t|
|
33
|
+
t.remove :payable_type
|
34
|
+
t.remove :payment_method
|
35
|
+
t.remove :source_id
|
36
|
+
t.remove :source_type
|
37
|
+
end
|
38
|
+
rename_column :payments, :payable_id, :order_id
|
39
|
+
add_column :payments, :creditcard_id, :integer
|
40
|
+
add_column :payments, :type, :string
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ChangePaymentsPaymentMethodToBelongsTo < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
remove_column :payments, :payment_method
|
4
|
+
add_column :payments, :payment_method_id, :integer
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
add_column :payments, :payment_method, :string
|
9
|
+
remove_column :payments, :payment_method_id
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class AssignCreditcardTxnsToPayment < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :creditcard_txns, :payment_id, :integer
|
4
|
+
|
5
|
+
# Temporarily set back to creditcards
|
6
|
+
Spree::Creditcard.table_name = 'creditcards'
|
7
|
+
|
8
|
+
ActiveRecord::Base.connection.select_all('SELECT * FROM creditcard_txns').each do |txn_attrs|
|
9
|
+
if creditcard = Spree::Creditcard.find_by_id(txn_attrs['creditcard_id']) and creditcard.payments.first
|
10
|
+
execute "UPDATE creditcard_txns SET payment_id = #{creditcard.payments.first.id} WHERE id = #{txn_attrs['id']}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Spree::Creditcard.table_name = 'spree_creditcards'
|
15
|
+
|
16
|
+
remove_column :creditcard_txns, :creditcard_payment_id
|
17
|
+
end
|
18
|
+
|
19
|
+
def down
|
20
|
+
remove_column :creditcard_txns, :payment_id
|
21
|
+
add_column :creditcard_txns, :creditcard_payment_id, :integer
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class StiForTransactions < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
rename_table :creditcard_txns, :transactions
|
4
|
+
add_column :transactions, :type, :string
|
5
|
+
remove_column :transactions, :creditcard_id
|
6
|
+
|
7
|
+
execute "UPDATE transactions SET type = 'CreditcardTxn'"
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
rename_table :transactions, :creditcard_txns
|
12
|
+
remove_column :transactions, :type
|
13
|
+
add_column :transactions, :creditcard_id, :integer
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class DropBillingIntegrations < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
drop_table :billing_integrations
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
create_table :billing_integrations do |t|
|
8
|
+
t.string :type, :name
|
9
|
+
t.text :description
|
10
|
+
t.boolean :active, :default => true
|
11
|
+
t.string :environment, :default => 'development'
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DeletedAtForPaymentMethods < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
change_table :payment_methods do |t|
|
4
|
+
t.timestamp :deleted_at, :default => nil
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
remove_column :payments_methods, :column_name
|
10
|
+
change_table :payment_methods do |t|
|
11
|
+
t.remove :deleted_at
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class FixByPopularity < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
execute("UPDATE product_scopes SET name='descend_by_popularity' WHERE name='by_popularity'")
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
execute("UPDATE product_scopes SET name='by_popularity' WHERE name='descend_by_popularity'")
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Adjustment < ActiveRecord::Base; end;
|
2
|
+
|
3
|
+
class FixExistingCouponCredits < ActiveRecord::Migration
|
4
|
+
def up
|
5
|
+
execute("UPDATE adjustments SET type='PromotionCredit' WHERE type='CouponCredit'")
|
6
|
+
execute("UPDATE adjustments SET adjustment_source_type='Promotion' WHERE adjustment_source_type='Coupon'")
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
execute("UPDATE adjustments SET adjustment_source_type='Coupon' WHERE adjustment_source_type='Promotion'")
|
11
|
+
execute("UPDATE adjustments SET type='CouponCredit' WHERE type='PromotionCredit'")
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddIconToTaxons < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
# skip this migration if the attribute already exists because of advanced taxon extension
|
4
|
+
return if column_exists?(:taxons, :icon_file_name)
|
5
|
+
add_column :taxons, :icon_file_name, :string
|
6
|
+
add_column :taxons, :icon_content_type, :string
|
7
|
+
add_column :taxons, :icon_file_size, :integer
|
8
|
+
add_column :taxons, :icon_updated_at, :datetime
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
remove_column :taxons, :icon_file_name
|
13
|
+
remove_column :taxons, :icon_content_type
|
14
|
+
remove_column :taxons, :icon_file_size
|
15
|
+
remove_column :taxons, :icon_updated_at
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddDescriptionToTaxons < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
# skip this migration if the attribute already exists because of advanced taxon extension
|
4
|
+
return if column_exists?(:taxons, :description)
|
5
|
+
add_column :taxons, :description, :text
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
remove_column :taxons, :description
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class PaymentsStateAndAssignedToOrderOnly < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
# TODO: migrate existing payments
|
4
|
+
rename_column :payments, :payable_id, :order_id
|
5
|
+
remove_column :payments, :payable_type
|
6
|
+
add_column :payments, :state, :string
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
remove_column :payments, :state
|
11
|
+
add_column :payments, :payable_type, :string
|
12
|
+
rename_column :payments, :order_id, :payable_id
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class RefactorAdjustments < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
change_table :adjustments do |t|
|
4
|
+
t.boolean :mandatory
|
5
|
+
t.boolean :frozen
|
6
|
+
t.rename :adjustment_source_id, :source_id
|
7
|
+
t.rename :adjustment_source_type, :source_type
|
8
|
+
t.references :originator
|
9
|
+
t.string :originator_type
|
10
|
+
t.remove :type
|
11
|
+
t.rename :description, :label
|
12
|
+
t.remove :position
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def down
|
17
|
+
change_table :adjustments do |t|
|
18
|
+
t.integer :position
|
19
|
+
t.rename :label, :description
|
20
|
+
t.string :type
|
21
|
+
t.remove :originator_type
|
22
|
+
t.remove :originator_id
|
23
|
+
t.rename :source_type, :adjustment_source_type
|
24
|
+
t.rename :source_id, :adjustment_source_id
|
25
|
+
t.remove :frozen
|
26
|
+
t.remove :mandatory
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class MoveSpecialInstructionsToOrders < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :orders, :special_instructions, :text
|
4
|
+
execute "UPDATE orders SET special_instructions = (SELECT special_instructions FROM checkouts WHERE order_id = orders.id)"
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
remove_column :orders, :special_instructions, :text
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class Transaction < ActiveRecord::Base; end
|
2
|
+
class CreditcardTxn < Transaction; end
|
3
|
+
|
4
|
+
class MigrateTransactionsToPaymentState < ActiveRecord::Migration
|
5
|
+
|
6
|
+
AUTHORIZED=1
|
7
|
+
COMPLETED=2
|
8
|
+
PURCHASED=3
|
9
|
+
VOIDED = 4
|
10
|
+
CREDITED =5
|
11
|
+
|
12
|
+
PAYMENT_COMPLETE = 'completed'
|
13
|
+
PAYMENT_VOID = 'void'
|
14
|
+
PAYMENT_PENDING = 'pending'
|
15
|
+
|
16
|
+
# Temporarily set the table back to payments
|
17
|
+
Spree::Payment.table_name = 'payments'
|
18
|
+
|
19
|
+
def up
|
20
|
+
migrate_authorized_only_transactions
|
21
|
+
migrate_voided_transactions
|
22
|
+
migrate_completed_transactions
|
23
|
+
migrate_purchased_transactions
|
24
|
+
migrate_credited_transactions
|
25
|
+
|
26
|
+
Spree::Payment.table_name = 'spree_payments'
|
27
|
+
end
|
28
|
+
|
29
|
+
def migrate_credited_transactions
|
30
|
+
credited = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{CREDITED}")
|
31
|
+
credited.each do |tx|
|
32
|
+
payment = Spree::Payment.find(tx)
|
33
|
+
order = payment.order
|
34
|
+
order.create_payment(
|
35
|
+
:amount => tx.amount,
|
36
|
+
:source_id => payment.source_id, :source_type => 'Creditcard',
|
37
|
+
:payment_method_id => payment.payment_method_id, :state => PAYMENT_COMPLETE,
|
38
|
+
:avs_response => tx.avs_response, :response_code => tx.response_code
|
39
|
+
)
|
40
|
+
end
|
41
|
+
credited.each { |rec| rec.destroy }
|
42
|
+
end
|
43
|
+
|
44
|
+
def migrate_voided_transactions
|
45
|
+
voided = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{VOIDED}")
|
46
|
+
voided.each do |tx|
|
47
|
+
update_payment(tx, PAYMENT_VOID)
|
48
|
+
end
|
49
|
+
unless voided.empty?
|
50
|
+
all_but_credited = [AUTHORIZED, COMPLETED, PURCHASED, VOIDED]
|
51
|
+
voided_and_subsequent_transactions = Transaction.find_by_sql("SELECT * FROM transactions WHERE payment_id IN (#{voided.map(&:payment_id).join(',')}) AND txn_type IN (#{all_but_credited.join(',')})")
|
52
|
+
voided_and_subsequent_transactions.each { |rec| rec.destroy }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def migrate_purchased_transactions
|
57
|
+
migrate_transactions(PURCHASED)
|
58
|
+
end
|
59
|
+
|
60
|
+
def migrate_completed_transactions
|
61
|
+
migrate_transactions(COMPLETED)
|
62
|
+
end
|
63
|
+
|
64
|
+
def migrate_transactions(type)
|
65
|
+
txs = Transaction.find_by_sql("SELECT * FROM transactions WHERE txn_type = #{type}")
|
66
|
+
txs.each do |tx|
|
67
|
+
update_payment(tx, PAYMENT_COMPLETE)
|
68
|
+
end
|
69
|
+
txs.each { |rec| rec.destroy }
|
70
|
+
end
|
71
|
+
|
72
|
+
def migrate_authorized_only_transactions
|
73
|
+
if (ActiveRecord::Base.connection.adapter_name == 'PostgreSQL')
|
74
|
+
group_by_clause = 'GROUP BY transactions.' + Transaction.column_names.join(', transactions.')
|
75
|
+
else
|
76
|
+
group_by_clause = 'GROUP BY payment_id'
|
77
|
+
end
|
78
|
+
authorized_only = Transaction.find_by_sql("SELECT * FROM transactions #{group_by_clause} HAVING COUNT(payment_id) = 1 AND txn_type = #{AUTHORIZED}")
|
79
|
+
authorized_only.each do |tx|
|
80
|
+
update_payment(tx, PAYMENT_PENDING)
|
81
|
+
end
|
82
|
+
authorized_only.each { |rec| rec.destroy }
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_payment(tx, state)
|
86
|
+
payment = Spree::Payment.find(tx.payment_id)
|
87
|
+
payment.update_attributes_without_callbacks({
|
88
|
+
:state => state,
|
89
|
+
:source_type => 'Creditcard',
|
90
|
+
:amount => tx.amount,
|
91
|
+
:response_code => tx.response_code,
|
92
|
+
:avs_response => tx.avs_response
|
93
|
+
})
|
94
|
+
end
|
95
|
+
|
96
|
+
def down
|
97
|
+
end
|
98
|
+
end
|