spree_mercado_pago 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/javascripts/spree/admin/spree_mercado_pago_payment_method.js +1 -0
- data/app/assets/javascripts/spree/frontend/spree_mercado_pago_payment_method.js +25 -0
- data/app/assets/stylesheets/admin/spree_mercado_pago_payment_method.css +3 -0
- data/app/assets/stylesheets/store/spree_mercado_pago_payment_method.css +3 -0
- data/app/controllers/spree/mercado_pago_controller.rb +69 -0
- data/app/models/mercado_pago/client/api.rb +43 -0
- data/app/models/mercado_pago/client/authentication.rb +36 -0
- data/app/models/mercado_pago/client/preferences.rb +20 -0
- data/app/models/mercado_pago/client.rb +63 -0
- data/app/models/mercado_pago/notification.rb +8 -0
- data/app/models/mercado_pago/order_preferences_builder.rb +68 -0
- data/app/models/spree/payment_method/mercado_pago.rb +46 -0
- data/app/services/mercado_pago/handle_received_notification.rb +18 -0
- data/app/services/mercado_pago/process_notification.rb +54 -0
- data/app/views/spree/admin/payments/source_forms/_mercadopago.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/_mercadopago.html.erb +1 -0
- data/app/views/spree/checkout/mercado_pago_error.html.erb +0 -0
- data/app/views/spree/checkout/payment/_mercadopago.html.erb +15 -0
- data/config/locales/en.yml +4 -0
- data/config/locales/es.yml +4 -0
- data/config/routes.rb +6 -0
- data/lib/generators/spree_mercado_pago_payment_method/install/install_generator.rb +34 -0
- data/lib/spree_mercado_pago_payment_method/engine.rb +22 -0
- data/lib/spree_mercado_pago_payment_method.rb +4 -0
- data/lib/tasks/mercado_user.rake +5 -0
- data/spec/controllers/spree/mercado_pago_controller_spec.rb +32 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -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/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +38 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +9 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/custom_user.rb +1 -0
- data/spec/dummy/config/initializers/devise.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/spree.rb +14 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spree.yml +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20141112193407_spree_one_two.spree.rb +482 -0
- data/spec/dummy/db/migrate/20141112193408_spree_promo_one_two.spree.rb +46 -0
- data/spec/dummy/db/migrate/20141112193409_add_tax_rate_label.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193410_add_toggle_tax_rate_display.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193411_remove_unused_preference_columns.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193412_add_lock_version_to_variant.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193413_add_states_required_to_countries.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193414_add_on_demand_to_product_and_variant.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193415_remove_not_null_constraint_from_products_on_hand.spree.rb +12 -0
- data/spec/dummy/db/migrate/20141112193416_split_prices_from_variants.spree.rb +32 -0
- data/spec/dummy/db/migrate/20141112193417_remove_not_null_from_spree_prices_amount.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193418_add_currency_to_line_items.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193419_add_currency_to_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193420_add_cost_currency_to_variants.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193421_remove_display_on_from_payment_methods.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193422_add_position_to_taxonomies.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193423_add_last_ip_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193424_add_state_to_spree_adjustments.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193425_add_display_on_to_spree_payment_methods.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193426_add_position_to_product_properties.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193427_add_identifier_to_spree_payments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193428_add_order_id_index_to_payments.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193429_add_primary_to_spree_products_taxons.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193430_create_spree_stock_items.spree.rb +15 -0
- data/spec/dummy/db/migrate/20141112193431_create_spree_stock_locations.spree.rb +12 -0
- data/spec/dummy/db/migrate/20141112193432_create_default_stock.spree.rb +31 -0
- data/spec/dummy/db/migrate/20141112193433_add_order_id_index_to_shipments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193434_change_meta_description_on_spree_products_to_text.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193435_add_stock_location_id_to_spree_shipments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193436_add_pending_to_inventory_unit.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193437_remove_on_demand_from_product_and_variant.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193438_create_shipping_method_zone.spree.rb +23 -0
- data/spec/dummy/db/migrate/20141112193439_remove_shipping_category_id_from_shipping_method.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193440_create_shipping_method_categories.spree.rb +14 -0
- data/spec/dummy/db/migrate/20141112193441_add_tracking_url_to_spree_shipping_methods.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193442_create_spree_shipping_rates.spree.rb +25 -0
- data/spec/dummy/db/migrate/20141112193443_remove_category_match_attributes_from_shipping_method.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193444_create_stock_movements.spree.rb +13 -0
- data/spec/dummy/db/migrate/20141112193445_add_address_fields_to_stock_location.spree.rb +23 -0
- data/spec/dummy/db/migrate/20141112193446_add_active_field_to_stock_locations.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193447_add_backorderable_to_stock_item.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193448_add_default_quantity_to_stock_movement.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193449_add_source_and_destination_to_stock_movements.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193450_change_orders_total_precision.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193451_change_spree_payments_amount_precision.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193452_change_spree_return_authorization_amount_precision.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193453_change_adjustments_amount_precision.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193454_add_originator_to_stock_movement.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193455_drop_source_and_destination_from_stock_movement.spree.rb +16 -0
- data/spec/dummy/db/migrate/20141112193456_migrate_inventory_unit_sold_to_on_hand.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193457_add_stock_location_to_rma.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193458_update_shipment_state_for_canceled_orders.spree.rb +16 -0
- data/spec/dummy/db/migrate/20141112193459_add_seo_metas_to_taxons.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193460_remove_stock_item_and_variant_lock.spree.rb +15 -0
- data/spec/dummy/db/migrate/20141112193461_add_name_to_spree_credit_cards.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193462_update_name_fields_on_spree_credit_cards.spree.rb +14 -0
- data/spec/dummy/db/migrate/20141112193463_add_index_to_source_columns_on_adjustments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193464_update_adjustment_states.spree.rb +17 -0
- data/spec/dummy/db/migrate/20141112193465_add_shipping_rates_to_shipments.spree.rb +16 -0
- data/spec/dummy/db/migrate/20141112193466_create_spree_stock_transfers.spree.rb +15 -0
- data/spec/dummy/db/migrate/20141112193467_drop_products_count_on_hand.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193468_set_default_shipping_rate_cost.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193469_add_number_to_stock_transfer.spree.rb +24 -0
- data/spec/dummy/db/migrate/20141112193470_add_sku_index_to_spree_variants.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193471_add_backorderable_default_to_spree_stock_location.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193472_add_propage_all_variants_to_spree_stock_location.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193473_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb +11 -0
- data/spec/dummy/db/migrate/20141112193474_add_user_id_index_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193475_add_updated_at_to_spree_countries.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193476_add_updated_at_to_spree_states.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193477_add_cvv_result_code_and_cvv_result_message_to_spree_payments.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193478_add_unique_index_to_permalink_on_spree_products.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193479_add_unique_index_to_orders_shipments_and_stock_transfers.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193480_add_deleted_at_to_spree_tax_rates.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193481_remove_lock_version_from_inventory_units.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193482_add_cost_price_to_line_item.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193483_set_backorderable_to_default_to_false.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193484_add_created_by_id_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193485_index_completed_at_on_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193486_add_tax_category_id_to_spree_line_items.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193487_migrate_tax_categories_to_line_items.spree.rb +11 -0
- data/spec/dummy/db/migrate/20141112193488_drop_spree_mail_methods.spree.rb +13 -0
- data/spec/dummy/db/migrate/20141112193489_set_default_stock_location_on_shipments.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193490_upgrade_adjustments.spree.rb +40 -0
- data/spec/dummy/db/migrate/20141112193491_rename_adjustment_fields.spree.rb +15 -0
- data/spec/dummy/db/migrate/20141112193492_add_admin_name_column_to_spree_shipping_methods.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193493_add_admin_name_column_to_spree_stock_locations.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193494_add_shipment_total_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193495_expand_order_number_size.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193496_rename_activators_to_promotions.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193497_add_adjustment_total_to_line_items.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193498_add_adjustment_total_to_shipments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193499_add_depth_to_spree_taxons.spree.rb +17 -0
- data/spec/dummy/db/migrate/20141112193500_add_tax_total_to_line_items_shipments_and_orders.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193501_add_shipping_category_to_shipping_methods_and_products.spree.rb +16 -0
- data/spec/dummy/db/migrate/20141112193502_migrate_old_shipping_calculators.spree.rb +20 -0
- data/spec/dummy/db/migrate/20141112193503_add_code_to_spree_promotion_rules.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193504_change_states_required_for_countries.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193505_add_deleted_at_to_spree_stock_items.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193506_remove_promotions_event_name_field.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193507_add_promo_total_to_line_items_and_shipments_and_orders.spree.rb +8 -0
- data/spec/dummy/db/migrate/20141112193508_remove_unused_credit_card_fields.spree.rb +17 -0
- data/spec/dummy/db/migrate/20141112193509_add_track_inventory_to_variant.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193510_add_tax_category_to_variants.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193511_add_channel_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193512_add_included_to_adjustments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193513_rename_tax_total_fields.spree.rb +12 -0
- data/spec/dummy/db/migrate/20141112193514_add_line_item_id_to_spree_inventory_units.spree.rb +22 -0
- data/spec/dummy/db/migrate/20141112193515_add_updated_at_to_variants.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193516_add_position_to_classifications.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193517_create_spree_orders_promotions.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193518_unique_shipping_method_categories.spree.rb +25 -0
- data/spec/dummy/db/migrate/20141112193519_add_item_count_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193520_remove_value_type_from_spree_preferences.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193521_rename_permalink_to_slug_for_products.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193522_add_index_to_variant_id_and_currency_on_prices.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193523_rename_activator_id_in_rules_and_actions_to_promotion_id.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193524_add_deleted_at_to_spree_prices.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193525_add_approver_id_and_approved_at_to_orders.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193526_add_confirmation_delivered_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193527_add_auto_capture_to_payment_methods.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193528_create_spree_payment_capture_events.spree.rb +13 -0
- data/spec/dummy/db/migrate/20141112193529_add_uncaptured_amount_to_payments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193530_default_variant_weight_to_zero.spree.rb +12 -0
- data/spec/dummy/db/migrate/20141112193531_add_tax_category_id_to_shipping_methods.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193532_add_tax_rate_id_to_shipping_rates.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193533_add_pre_tax_amount_to_line_items_and_shipments.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193534_add_more_indexes.spree.rb +14 -0
- data/spec/dummy/db/migrate/20141112193535_add_considered_risky_to_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193536_add_preference_store_to_everything.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193537_add_user_id_to_spree_credit_cards.spree.rb +14 -0
- data/spec/dummy/db/migrate/20141112193538_migrate_old_preferences.spree.rb +24 -0
- data/spec/dummy/db/migrate/20141112193539_create_spree_stores.spree.rb +26 -0
- data/spec/dummy/db/migrate/20141112193540_create_store_from_preferences.spree.rb +31 -0
- data/spec/dummy/db/migrate/20141112193541_add_timestamps_to_spree_assets.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193542_add_additional_store_fields.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193543_add_many_missing_indexes.spree.rb +19 -0
- data/spec/dummy/db/migrate/20141112193544_correct_some_polymorphic_index_and_add_more_missing.spree.rb +67 -0
- data/spec/dummy/db/migrate/20141112193545_add_user_id_created_by_id_index_to_order.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193546_change_spree_price_amount_precision.spree.rb +9 -0
- data/spec/dummy/db/migrate/20141112193547_add_token_to_spree_orders.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193548_move_order_token_from_tokenized_permission.spree.rb +30 -0
- data/spec/dummy/db/migrate/20141112193549_set_shipment_total_for_users_upgrading.spree.rb +11 -0
- data/spec/dummy/db/migrate/20141112193550_drop_credit_card_first_name_and_last_name.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193551_add_deleted_at_to_spree_promotion_actions.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193552_remove_uncaptured_amount_from_spree_payments.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193553_add_default_to_shipment_cost.spree.rb +11 -0
- data/spec/dummy/db/migrate/20141112193554_default_pre_tax_amount_should_be_zero.spree.rb +7 -0
- data/spec/dummy/db/migrate/20141112193555_add_state_lock_version_to_order.spree.rb +6 -0
- data/spec/dummy/db/migrate/20141112193556_fix_adjustment_order_presence.spree.rb +14 -0
- data/spec/dummy/db/migrate/20141112193557_update_classifications_positions.spree.rb +10 -0
- data/spec/dummy/db/migrate/20141112193558_add_api_key_to_spree_users.spree_api.rb +8 -0
- data/spec/dummy/db/migrate/20141112193559_resize_api_key_field.spree_api.rb +8 -0
- data/spec/dummy/db/migrate/20141112193560_rename_api_key_to_spree_api_key.spree_api.rb +8 -0
- data/spec/dummy/db/migrate/20141112193561_add_index_to_user_spree_api_key.spree_api.rb +8 -0
- data/spec/dummy/db/migrate/20141112193562_create_users.spree_auth.rb +30 -0
- data/spec/dummy/db/migrate/20141112193563_rename_columns_for_devise.spree_auth.rb +38 -0
- data/spec/dummy/db/migrate/20141112193564_convert_user_remember_field.spree_auth.rb +12 -0
- data/spec/dummy/db/migrate/20141112193565_add_reset_password_sent_at_to_spree_users.spree_auth.rb +9 -0
- data/spec/dummy/db/migrate/20141112193566_make_users_email_index_unique.spree_auth.rb +10 -0
- data/spec/dummy/db/migrate/20141202172111_create_spree_mercado_pago_notifications.spree_mercado_pago_payment_method_engine.rb +10 -0
- data/spec/dummy/db/schema.rb +869 -0
- data/spec/dummy/db/seeds.rb +11 -0
- data/spec/dummy/db/spree_development.sqlite3 +0 -0
- data/spec/dummy/db/spree_test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +27885 -0
- data/spec/dummy/log/test.log +87678 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/17E/D61/spree%2Fapp_configuration%2Fdefault_seo_title +1 -0
- data/spec/dummy/tmp/cache/2CC/B21/spree%2Fapp_configuration%2Frequire_master_price +1 -0
- data/spec/dummy/tmp/cache/334/AA1/spree%2Fapp_configuration%2Fdefault_meta_keywords +1 -0
- data/spec/dummy/tmp/cache/397/F31/spree%2Fapp_configuration%2Fbinary_inventory_cache +1 -0
- data/spec/dummy/tmp/cache/39C/F91/spree%2Fapp_configuration%2Ftax_using_ship_address +1 -0
- data/spec/dummy/tmp/cache/3A7/4A1/spree%2Fapp_configuration%2Faddress_requires_state +1 -0
- data/spec/dummy/tmp/cache/3B7/CD1/spree%2Fapp_configuration%2Fredirect_https_to_http +1 -0
- data/spec/dummy/tmp/cache/3BE/851/spree%2Fapp_configuration%2Ftrack_inventory_levels +1 -0
- data/spec/dummy/tmp/cache/460/D81/spree%2Fapp_configuration%2Fdefault_meta_description +1 -0
- data/spec/dummy/tmp/cache/5AE/6A1/spree%2Fapp_configuration%2Falways_include_confirm_step +1 -0
- data/spec/dummy/tmp/cache/DD9/320/spree%2Fapp_configuration%2Fsite_url +1 -0
- data/spec/dummy/tmp/cache/DDD/2D0/spree%2Fapp_configuration%2Fcurrency +1 -0
- data/spec/dummy/tmp/cache/E27/320/spree%2Fapp_configuration%2Fsite_name +1 -0
- data/spec/dummy/tmp/cache/E9B/7F0/spree%2Fapp_configuration%2Fmails_from +1 -0
- data/spec/dummy/tmp/cache/F01/FD0/spree%2Ffrontend_configuration%2Flocale +1 -0
- data/spec/dummy/vendor/assets/javascripts/spree/backend/all.js +13 -0
- data/spec/dummy/vendor/assets/javascripts/spree/frontend/all.js +13 -0
- data/spec/dummy/vendor/assets/stylesheets/spree/backend/all.css +12 -0
- data/spec/dummy/vendor/assets/stylesheets/spree/frontend/all.css +12 -0
- data/spec/fixtures/authenticated.json +7 -0
- data/spec/fixtures/preferences_created.json +41 -0
- data/spec/models/mercado_pago/client_spec.rb +138 -0
- data/spec/models/mercado_pago/notification_spec.rb +17 -0
- data/spec/models/mercado_pago/order_preferences_builder_spec.rb +66 -0
- data/spec/services/mercado_pago/process_notification_spec.rb +57 -0
- data/spec/spec_helper.rb +54 -0
- metadata +640 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2eb53fdc0027372aa67444c564b5ccc6372d8018
|
4
|
+
data.tar.gz: decbb3c087eb1ef31e0553c1eaa24c7a2ade4ffb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 731070b18f180e4b058297b0542d235a0772432f71b197e7c201e6cd61b2b5ff67d6300b7688233e5b8c11390f5bc95f964c75e8786465e543ab6cfbe5ee8229
|
7
|
+
data.tar.gz: 88d6e6f3e9b961dc36a551c1870253128a18c6ab81c98aef683de4855be3c4958a5b698f4725372aae0519f3d93ebc20e6e09fe0f0cd36bb9b301ad42dafee83
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_core
|
@@ -0,0 +1,25 @@
|
|
1
|
+
//= require spree/frontend
|
2
|
+
|
3
|
+
MercadoPago = {
|
4
|
+
hidePaymentSaveAndContinueButton: function(paymentMethod) {
|
5
|
+
if (MercadoPago.paymentMethodID && paymentMethod.val() == MercadoPago.paymentMethodID) {
|
6
|
+
$('.continue').hide();
|
7
|
+
$('[data-hook=coupon_code]').hide();
|
8
|
+
} else {
|
9
|
+
$('.continue').show();
|
10
|
+
$('[data-hook=coupon_code]').show();
|
11
|
+
}
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
$(document).ready(function() {
|
16
|
+
checkedPaymentMethod = $('div[data-hook="checkout_payment_step"] input[type="radio"]:checked');
|
17
|
+
MercadoPago.hidePaymentSaveAndContinueButton(checkedPaymentMethod);
|
18
|
+
paymentMethods = $('div[data-hook="checkout_payment_step"] input[type="radio"]').click(function (e) {
|
19
|
+
MercadoPago.hidePaymentSaveAndContinueButton($(e.target));
|
20
|
+
});
|
21
|
+
|
22
|
+
$('button.mercado_pago_button').click(function(event){
|
23
|
+
$(event.target).prop("disabled",true);
|
24
|
+
});
|
25
|
+
});
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Spree
|
2
|
+
class MercadoPagoController < StoreController
|
3
|
+
protect_from_forgery except: :ipn
|
4
|
+
skip_before_filter :set_current_order, only: :ipn
|
5
|
+
|
6
|
+
def checkout
|
7
|
+
current_order.state_name == :payment || raise(ActiveRecord::RecordNotFound)
|
8
|
+
payment_method = PaymentMethod::MercadoPago.find(params[:payment_method_id])
|
9
|
+
payment = current_order.payments.
|
10
|
+
create!({amount: current_order.total, payment_method: payment_method})
|
11
|
+
payment.started_processing!
|
12
|
+
|
13
|
+
preferences = ::MercadoPago::OrderPreferencesBuilder.
|
14
|
+
new(current_order, payment, callback_urls).
|
15
|
+
preferences_hash
|
16
|
+
|
17
|
+
provider = payment_method.provider
|
18
|
+
provider.create_preferences(preferences)
|
19
|
+
|
20
|
+
redirect_to provider.redirect_url
|
21
|
+
end
|
22
|
+
|
23
|
+
# Success/pending callbacks are currently aliases, this may change
|
24
|
+
# if required.
|
25
|
+
def success
|
26
|
+
payment.pend!
|
27
|
+
payment.order.next
|
28
|
+
flash.notice = Spree.t(:order_processed_successfully)
|
29
|
+
flash['order_completed'] = true
|
30
|
+
redirect_to spree.order_path(payment.order)
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure
|
34
|
+
payment.failure!
|
35
|
+
flash.notice = Spree.t(:payment_processing_failed)
|
36
|
+
flash['order_completed'] = true
|
37
|
+
redirect_to spree.checkout_state_path(state: :payment)
|
38
|
+
end
|
39
|
+
|
40
|
+
def ipn
|
41
|
+
notification = MercadoPago::Notification.
|
42
|
+
new(operation_id: params[:id], topic: params[:topic])
|
43
|
+
|
44
|
+
if notification.save
|
45
|
+
MercadoPago::HandleReceivedNotification.new(notification).process!
|
46
|
+
status = :ok
|
47
|
+
else
|
48
|
+
status = :bad_request
|
49
|
+
end
|
50
|
+
|
51
|
+
render nothing: true, status: status
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def payment
|
57
|
+
@payment ||= Spree::Payment.where(identifier: params[:external_reference]).
|
58
|
+
first
|
59
|
+
end
|
60
|
+
|
61
|
+
def callback_urls
|
62
|
+
@callback_urls ||= {
|
63
|
+
success: mercado_pago_success_url,
|
64
|
+
pending: mercado_pago_success_url,
|
65
|
+
failure: mercado_pago_failure_url
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class MercadoPago::Client
|
4
|
+
module API
|
5
|
+
def redirect_url
|
6
|
+
point_key = sandbox ? 'sandbox_init_point' : 'init_point'
|
7
|
+
@preferences_response[point_key]
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def notifications_url(operation_id)
|
13
|
+
sandbox_part = sandbox ? 'sandbox/' : ''
|
14
|
+
"https://api.mercadolibre.com/#{sandbox_part}collections/notifications/#{operation_id}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def search_url
|
18
|
+
sandbox_part = sandbox ? 'sandbox/' : ''
|
19
|
+
"https://api.mercadolibre.com/#{sandbox_part}collections/search"
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_url(url, params={})
|
23
|
+
uri = URI(url)
|
24
|
+
uri.query = URI.encode_www_form(params)
|
25
|
+
uri.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def preferences_url(token)
|
29
|
+
create_url('https://api.mercadolibre.com/checkout/preferences', access_token: token)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sandbox
|
33
|
+
@api_options[:sandbox]
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(url, request_options={}, options={})
|
37
|
+
response = RestClient.get(url, request_options)
|
38
|
+
JSON.parse(response)
|
39
|
+
rescue => e
|
40
|
+
raise e unless options[:quiet]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class MercadoPago::Client
|
4
|
+
module Authentication
|
5
|
+
def authenticate
|
6
|
+
response = send_authentication_request
|
7
|
+
@auth_response = JSON.parse(response)
|
8
|
+
rescue RestClient::Exception => e
|
9
|
+
@errors << I18n.t(:authentication_error, scope: :mercado_pago)
|
10
|
+
raise RuntimeError.new e.message
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def send_authentication_request
|
16
|
+
RestClient.post(
|
17
|
+
'https://api.mercadolibre.com/oauth/token',
|
18
|
+
{:grant_type => 'client_credentials', :client_id => client_id, :client_secret => client_secret},
|
19
|
+
:content_type => 'application/x-www-form-urlencoded', :accept => 'application/json'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def client_id
|
24
|
+
@payment_method.preferred_client_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def client_secret
|
28
|
+
@payment_method.preferred_client_secret
|
29
|
+
end
|
30
|
+
|
31
|
+
def access_token
|
32
|
+
authenticate unless @auth_response
|
33
|
+
@auth_response['access_token']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class MercadoPago::Client
|
4
|
+
module Preferences
|
5
|
+
def create_preferences(preferences)
|
6
|
+
response = send_preferences_request(preferences)
|
7
|
+
@preferences_response = JSON.parse(response)
|
8
|
+
rescue RestClient::Exception => e
|
9
|
+
@errors << I18n.t(:authentication_error, scope: :mercado_pago)
|
10
|
+
raise RuntimeError.new(e.message)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def send_preferences_request(preferences)
|
16
|
+
RestClient.post(preferences_url(access_token), preferences.to_json,
|
17
|
+
:content_type => 'application/json', :accept => 'application/json')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'mercado_pago/client/authentication'
|
3
|
+
require 'mercado_pago/client/preferences'
|
4
|
+
require 'mercado_pago/client/api'
|
5
|
+
|
6
|
+
module MercadoPago
|
7
|
+
class Client
|
8
|
+
# These three includes are because of the user of line_item_description from
|
9
|
+
# ProductsHelper
|
10
|
+
include Authentication
|
11
|
+
include Preferences
|
12
|
+
include API
|
13
|
+
|
14
|
+
attr_reader :errors
|
15
|
+
attr_reader :auth_response
|
16
|
+
attr_reader :preferences_response
|
17
|
+
|
18
|
+
def initialize(payment_method, options={})
|
19
|
+
@payment_method = payment_method
|
20
|
+
@api_options = options.clone
|
21
|
+
@errors = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_operation_info(operation_id)
|
25
|
+
url = create_url(notifications_url(operation_id), access_token: access_token)
|
26
|
+
options = {content_type: 'application/x-www-form-urlencoded', accept: 'application/json'}
|
27
|
+
get(url, options, quiet: true)
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# def get_external_reference(operation_id)
|
32
|
+
# response = send_notification_request(operation_id)
|
33
|
+
# if response
|
34
|
+
# response['collection']['external_reference']
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
|
38
|
+
def get_payment_status(external_reference)
|
39
|
+
response = send_search_request({external_reference: external_reference, access_token: access_token})
|
40
|
+
|
41
|
+
if response['results'].empty?
|
42
|
+
"pending"
|
43
|
+
else
|
44
|
+
response['results'][0]['collection']['status']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def log_error(msg, response, request, result)
|
51
|
+
Rails.logger.info msg
|
52
|
+
Rails.logger.info "response: #{response}."
|
53
|
+
Rails.logger.info "request args: #{request.args}."
|
54
|
+
Rails.logger.info "result #{result}."
|
55
|
+
end
|
56
|
+
|
57
|
+
def send_search_request(params, options={})
|
58
|
+
url = create_url(search_url, params)
|
59
|
+
options = {content_type: 'application/x-www-form-urlencoded', accept: 'application/json'}
|
60
|
+
get(url, options)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module MercadoPago
|
2
|
+
class Notification < ActiveRecord::Base
|
3
|
+
self.table_name = "mercado_pago_notifications"
|
4
|
+
|
5
|
+
validates :topic, presence: true, inclusion: {in: %w(payment preapproval authorized_payment merchant_order) }
|
6
|
+
validates :operation_id, presence: true
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module MercadoPago
|
2
|
+
class OrderPreferencesBuilder
|
3
|
+
include ActionView::Helpers::TextHelper
|
4
|
+
include ActionView::Helpers::SanitizeHelper
|
5
|
+
include Spree::ProductsHelper
|
6
|
+
|
7
|
+
def initialize(order, payment, callback_urls, payer_data = nil)
|
8
|
+
@order = order
|
9
|
+
@payment = payment
|
10
|
+
@callback_urls = callback_urls
|
11
|
+
@payer_data = payer_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def preferences_hash
|
15
|
+
{
|
16
|
+
external_reference: @payment.identifier,
|
17
|
+
back_urls: @callback_urls,
|
18
|
+
payer: @payer_data,
|
19
|
+
items: generate_items
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def generate_items
|
26
|
+
items = []
|
27
|
+
|
28
|
+
items += generate_items_from_line_items
|
29
|
+
items += generate_items_from_adjustments
|
30
|
+
items += generate_items_from_shipments
|
31
|
+
|
32
|
+
items
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_items_from_shipments
|
36
|
+
@order.shipments.collect do |shipment|
|
37
|
+
{
|
38
|
+
:title => shipment.shipping_method.name,
|
39
|
+
:unit_price => shipment.cost.to_f,
|
40
|
+
:quantity => 1,
|
41
|
+
:currency_id => 'ARS'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_items_from_line_items
|
47
|
+
@order.line_items.collect do |line_item|
|
48
|
+
{
|
49
|
+
:title => line_item_description_text(line_item.variant.product.name),
|
50
|
+
:unit_price => line_item.price.to_f,
|
51
|
+
:quantity => line_item.quantity,
|
52
|
+
:currency_id => 'ARS'
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def generate_items_from_adjustments
|
58
|
+
@order.adjustments.eligible.collect do |adjustment|
|
59
|
+
{
|
60
|
+
title: line_item_description_text(adjustment.label),
|
61
|
+
unit_price: adjustment.amount.to_f,
|
62
|
+
quantity: 1,
|
63
|
+
currency_id: "ARS"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Spree
|
2
|
+
class PaymentMethod::MercadoPago < PaymentMethod
|
3
|
+
preference :client_id, :integer
|
4
|
+
preference :client_secret, :string
|
5
|
+
preference :sandbox, :boolean, default: true
|
6
|
+
|
7
|
+
def payment_profiles_supported?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def provider_class
|
12
|
+
::MercadoPago::Client
|
13
|
+
end
|
14
|
+
|
15
|
+
def provider(additional_options = {})
|
16
|
+
@provider ||= begin
|
17
|
+
options = { sandbox: preferred_sandbox }
|
18
|
+
client = provider_class.new(self, options.merge(additional_options))
|
19
|
+
client.authenticate
|
20
|
+
client
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def source_required?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def auto_capture?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
## Admin options
|
33
|
+
|
34
|
+
def can_void?(payment)
|
35
|
+
payment.state != 'void'
|
36
|
+
end
|
37
|
+
|
38
|
+
def actions
|
39
|
+
%w{void}
|
40
|
+
end
|
41
|
+
|
42
|
+
def void(*args)
|
43
|
+
ActiveMerchant::Billing::Response.new(true, "", {}, {})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MercadoPago
|
2
|
+
class HandleReceivedNotification
|
3
|
+
def initialize(notification)
|
4
|
+
@notification = notification
|
5
|
+
end
|
6
|
+
|
7
|
+
# The purpose of this method is to enable async/sync processing
|
8
|
+
# of Mercado Pago IPNs. For simplicity processing is synchronous but
|
9
|
+
# if you would like to enqueue the processing via Resque/Ost/etc you
|
10
|
+
# will be able to do it.
|
11
|
+
def process!
|
12
|
+
# Sync
|
13
|
+
ProcessNotification.new(@notification).process!
|
14
|
+
# Async Will be configurable via block for example:
|
15
|
+
# Resque.enqueue(ProcessNotificationWorker, {id: @notification.id})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Process notification:
|
2
|
+
# ---------------------
|
3
|
+
# Fetch collection information
|
4
|
+
# Find payment by external reference
|
5
|
+
# If found
|
6
|
+
# Update payment status
|
7
|
+
# Notify user
|
8
|
+
# If not found
|
9
|
+
# Ignore notification (maybe payment from outside Spree)
|
10
|
+
module MercadoPago
|
11
|
+
class ProcessNotification
|
12
|
+
# Equivalent payment states
|
13
|
+
# MP state => Spree state
|
14
|
+
# =======================
|
15
|
+
#
|
16
|
+
# approved => complete
|
17
|
+
# pending => pend
|
18
|
+
# in_process => pend
|
19
|
+
# rejected => failed
|
20
|
+
# refunded => void
|
21
|
+
# cancelled => void
|
22
|
+
# in_mediation => pend
|
23
|
+
# charged_back => void
|
24
|
+
STATES = {
|
25
|
+
complete: %w(approved),
|
26
|
+
failure: %w(rejected),
|
27
|
+
void: %w(refunded cancelled charged_back)
|
28
|
+
}
|
29
|
+
|
30
|
+
attr_reader :notification
|
31
|
+
|
32
|
+
def initialize(notification)
|
33
|
+
@notification = notification
|
34
|
+
end
|
35
|
+
|
36
|
+
def process!
|
37
|
+
client = ::Spree::PaymentMethod::MercadoPago.provider
|
38
|
+
op_info = client.get_operation_info(notification.operation_id)["collection"]
|
39
|
+
|
40
|
+
if payment = Spree::Payment.where(identifier: op_info["external_reference"]).first
|
41
|
+
if STATES[:complete].include?(op_info["status"])
|
42
|
+
payment.complete
|
43
|
+
elsif STATES[:failure].include?(op_info["status"])
|
44
|
+
payment.failure
|
45
|
+
elsif STATES[:void].include?(op_info["status"])
|
46
|
+
payment.void
|
47
|
+
end
|
48
|
+
|
49
|
+
# When Spree issue #5246 is fixed we can remove this line
|
50
|
+
payment.order.updater.update
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<!-- Source form -->
|
@@ -0,0 +1 @@
|
|
1
|
+
<!-- Source view -->
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<script>
|
2
|
+
MercadoPago.paymentMethodID = "<%= payment_method.id %>";
|
3
|
+
</script>
|
4
|
+
|
5
|
+
<div class="row">
|
6
|
+
<div class="twelve rows alpha omega">
|
7
|
+
<img src="http://imgmp.mlstatic.com/org-img/banners/ar/medios/575X40.jpg" title="MercadoPago - Medios de pago" alt="MercadoPago - Medios de pago" width="575" height="40"/>
|
8
|
+
</div>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="row">
|
12
|
+
<div class="twelve rows alpha omega">
|
13
|
+
<%= link_to I18n.t(:make_payment, scope: :mercado_pago), mercado_pago_checkout_path(payment_method_id: payment_method.id), method: :post, class: "button primary" %>
|
14
|
+
</div>
|
15
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Spree::Core::Engine.add_routes do
|
2
|
+
post '/mercado_pago/checkout', to: "mercado_pago#checkout", as: :mercado_pago_checkout
|
3
|
+
get '/mercado_pago/success', to: "mercado_pago#success", as: :mercado_pago_success
|
4
|
+
get '/mercado_pago/failure', to: "mercado_pago#failure", as: :mercado_pago_failure
|
5
|
+
post '/mercado_pago/ipn', to: "mercado_pago#ipn", as: :mercado_pago_ipn
|
6
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SpreeMercadoPagoPaymentMethod
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def add_javascripts
|
6
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_mercado_pago_payment_method\n"
|
7
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_mercado_pago_payment_method\n"
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_stylesheets
|
11
|
+
frontend_css_file = "vendor/assets/stylesheets/spree/frontend/all.css"
|
12
|
+
backend_css_file = "vendor/assets/stylesheets/spree/backend/all.css"
|
13
|
+
|
14
|
+
if File.exist?(backend_css_file) && File.exist?(frontend_css_file)
|
15
|
+
inject_into_file frontend_css_file, " *= require spree/frontend/spree_mercado_pago_payment_method\n", :before => /\*\//, :verbose => true
|
16
|
+
inject_into_file backend_css_file, " *= require spree/backend/spree_mercado_pago_payment_method\n", :before => /\*\//, :verbose => true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_migrations
|
21
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_mercado_pago_payment_method'
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_migrations
|
25
|
+
res = ask 'Would you like to run the migrations now? [Y/n]'
|
26
|
+
if res == '' || res.downcase == 'y'
|
27
|
+
run 'bundle exec rake db:migrate'
|
28
|
+
else
|
29
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
|
3
|
+
module SpreeMercadoPagoPaymentMethod
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
|
6
|
+
def self.activate
|
7
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
|
8
|
+
Rails.application.config.cache_classes ? require(c) : load(c)
|
9
|
+
end
|
10
|
+
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
|
12
|
+
Rails.application.config.cache_classes ? require(c) : load(c)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer "spree_payment_network.register.payment_methods" do |app|
|
17
|
+
app.config.spree.payment_methods += [Spree::PaymentMethod::MercadoPago]
|
18
|
+
end
|
19
|
+
|
20
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe MercadoPagoController do
|
5
|
+
describe "#ipn" do
|
6
|
+
let(:operation_id) { "op123" }
|
7
|
+
|
8
|
+
describe "for valid notifications" do
|
9
|
+
let(:use_case) { double("use_case") }
|
10
|
+
|
11
|
+
it "handles notification and returns success" do
|
12
|
+
MercadoPago::HandleReceivedNotification.should_receive(:new).and_return(use_case)
|
13
|
+
use_case.should_receive(:process!)
|
14
|
+
|
15
|
+
spree_post :ipn, { id: operation_id, topic: "payment" }
|
16
|
+
response.should be_success
|
17
|
+
|
18
|
+
notification = ::MercadoPago::Notification.order(:created_at).last
|
19
|
+
notification.topic.should eq("payment")
|
20
|
+
notification.operation_id.should eq(operation_id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "for invalid notification" do
|
25
|
+
it "responds with invalid request" do
|
26
|
+
spree_post :ipn, { id: operation_id, topic: "nonexistent_topic" }
|
27
|
+
response.should be_bad_request
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED