solidus_core 1.0.7 → 1.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/spree/base_controller.rb +1 -2
- data/app/helpers/spree/base_helper.rb +4 -5
- data/app/helpers/spree/products_helper.rb +0 -8
- data/app/mailers/spree/carton_mailer.rb +17 -5
- data/app/mailers/spree/order_mailer.rb +12 -4
- data/app/models/concerns/spree/adjustment_source.rb +7 -8
- data/app/models/concerns/spree/default_price.rb +8 -2
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/ordered_property_value_list.rb +28 -0
- data/app/models/concerns/spree/user_address_book.rb +125 -0
- data/app/models/concerns/spree/user_api_authentication.rb +6 -2
- data/app/models/concerns/spree/user_methods.rb +5 -6
- data/app/models/spree/ability.rb +1 -38
- data/app/models/spree/address.rb +79 -36
- data/app/models/spree/adjustment.rb +74 -25
- data/app/models/spree/adjustment_reason.rb +1 -1
- data/app/models/spree/app_configuration.rb +35 -0
- data/app/models/spree/carton.rb +3 -3
- data/app/models/spree/country.rb +7 -1
- data/app/models/spree/credit_card.rb +5 -1
- data/app/models/spree/gateway.rb +0 -8
- data/app/models/spree/inventory_unit.rb +1 -1
- data/app/models/spree/item_adjustments.rb +1 -1
- data/app/models/spree/line_item_action.rb +1 -1
- data/app/models/spree/option_type.rb +3 -2
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/option_values_variant.rb +1 -1
- data/app/models/spree/order.rb +28 -56
- data/app/models/spree/order/checkout.rb +18 -20
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -12
- data/app/models/spree/order_stock_location.rb +1 -1
- data/app/models/spree/payment.rb +3 -14
- data/app/models/spree/payment/processing.rb +7 -14
- data/app/models/spree/payment_method.rb +5 -5
- data/app/models/spree/permission_sets/default_customer.rb +31 -0
- data/app/models/spree/permission_sets/order_display.rb +4 -0
- data/app/models/spree/permission_sets/order_management.rb +3 -0
- data/app/models/spree/permission_sets/promotion_display.rb +2 -1
- data/app/models/spree/permission_sets/restricted_stock_display.rb +16 -0
- data/app/models/spree/permission_sets/restricted_stock_management.rb +16 -0
- data/app/models/spree/permission_sets/restricted_stock_transfer_display.rb +17 -0
- data/app/models/spree/permission_sets/restricted_stock_transfer_management.rb +51 -0
- data/app/models/spree/permission_sets/stock_display.rb +1 -1
- data/app/models/spree/permission_sets/stock_management.rb +1 -2
- data/app/models/spree/permission_sets/stock_transfer_display.rb +10 -0
- data/app/models/spree/permission_sets/stock_transfer_management.rb +11 -0
- data/app/models/spree/permission_sets/super_user.rb +9 -0
- data/app/models/spree/product.rb +66 -28
- data/app/models/spree/product/scopes.rb +7 -22
- data/app/models/spree/product_option_type.rb +1 -1
- data/app/models/spree/product_promotion_rule.rb +6 -0
- data/app/models/spree/product_property.rb +2 -20
- data/app/models/spree/promotion/rules/product.rb +2 -1
- data/app/models/spree/refund.rb +0 -10
- data/app/models/spree/reimbursement.rb +1 -1
- data/app/models/spree/return_item.rb +5 -3
- data/app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb +13 -4
- data/app/models/spree/return_item/exchange_variant_eligibility/same_product.rb +2 -2
- data/app/models/spree/return_reason.rb +1 -1
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/role_user.rb +1 -1
- data/app/models/spree/shipment.rb +13 -4
- data/app/models/spree/shipping_manifest.rb +9 -3
- data/app/models/spree/shipping_method.rb +2 -3
- data/app/models/spree/shipping_method_zone.rb +6 -0
- data/app/models/spree/state.rb +1 -1
- data/app/models/spree/stock_item.rb +15 -3
- data/app/models/spree/stock_movement.rb +1 -1
- data/app/models/spree/store.rb +3 -0
- data/app/models/spree/store_credit.rb +1 -1
- data/app/models/spree/store_credit_category.rb +1 -1
- data/app/models/spree/store_credit_event.rb +1 -1
- data/app/models/spree/store_credit_type.rb +1 -1
- data/app/models/spree/store_credit_update_reason.rb +1 -1
- data/app/models/spree/store_payment_method.rb +6 -0
- data/app/models/spree/tax_rate.rb +3 -10
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/transfer_item.rb +1 -1
- data/app/models/spree/unit_cancel.rb +2 -2
- data/app/models/spree/user_address.rb +21 -0
- data/app/models/spree/user_stock_location.rb +1 -1
- data/app/models/spree/variant.rb +28 -13
- data/app/models/spree/variant_property_rule.rb +42 -0
- data/app/models/spree/variant_property_rule_condition.rb +8 -0
- data/app/models/spree/variant_property_rule_value.rb +8 -0
- data/app/models/spree/zone.rb +4 -2
- data/app/views/spree/carton_mailer/shipped_email.text.erb +1 -1
- data/config/locales/en.yml +13 -0
- data/db/default/spree/store_credit.rb +0 -1
- data/db/default/spree/zones.rb +1 -1
- data/db/migrate/20130228210442_create_shipping_method_zone.rb +1 -1
- data/db/migrate/20150121022521_remove_environment_from_payment_method.rb +6 -0
- data/db/migrate/20150506181611_create_spree_store_credit_payment_method.rb +9 -5
- data/db/migrate/20150731201146_add_spree_user_addresses.rb +16 -0
- data/db/migrate/20150811210350_remove_mandatory_from_adjustments.rb +5 -0
- data/db/migrate/20150811211025_add_finalized_to_spree_adjustments.rb +11 -0
- data/db/migrate/20150820160821_add_store_payment_methods.rb +10 -0
- data/db/migrate/20150824213633_convert_habtm_to_hmt_for_shipping_methods_zones.rb +17 -0
- data/db/migrate/20150824214129_convert_habtm_to_hmt_for_products_promotion_rules.rb +17 -0
- data/db/migrate/20150825204216_drop_spree_gateways.rb +20 -0
- data/db/migrate/20150909123605_create_variant_properties_and_rules.rb +28 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +4 -3
- data/lib/spree/core.rb +4 -0
- data/lib/spree/core/controller_helpers/payment_parameters.rb +67 -0
- data/lib/spree/core/delegate_belongs_to.rb +1 -0
- data/lib/spree/core/engine.rb +9 -1
- data/lib/spree/core/importer/order.rb +1 -1
- data/lib/spree/core/role_configuration.rb +1 -1
- data/lib/spree/core/search/variant.rb +20 -2
- data/lib/spree/core/unreturned_item_charger.rb +21 -16
- data/lib/spree/i18n.rb +6 -24
- data/lib/spree/mailer_previews/carton_preview.rb +10 -0
- data/lib/spree/mailer_previews/order_preview.rb +18 -0
- data/lib/spree/permitted_attributes.rb +4 -1
- data/lib/spree/testing_support/capybara_ext.rb +2 -1
- data/lib/spree/testing_support/factories/address_factory.rb +9 -1
- data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -0
- data/lib/spree/testing_support/factories/image_factory.rb +5 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +4 -8
- data/lib/spree/testing_support/factories/user_factory.rb +8 -2
- data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +6 -0
- data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +16 -0
- data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +6 -0
- data/lib/tasks/migrations/migrate_user_addresses.rake +29 -0
- data/vendor/assets/javascripts/jquery-migrate-1.0.0.js +498 -0
- metadata +40 -238
- data/CHANGELOG.md +0 -1
- data/Gemfile +0 -3
- data/Rakefile +0 -16
- data/app/models/concerns/spree/user_address.rb +0 -30
- data/app/models/spree/permission_sets/restricted_transfer_management.rb +0 -35
- data/app/views/spree/admin/orders/customer_details/_autocomplete.js.erb +0 -19
- data/lib/spree/i18n/base.rb +0 -17
- data/lib/spree/i18n/initializer.rb +0 -1
- data/lib/spree/testing_support/mail.rb +0 -20
- data/script/rails +0 -9
- data/solidus_core.gemspec +0 -48
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +0 -173
- data/spec/helpers/order_helper_spec.rb +0 -12
- data/spec/helpers/products_helper_spec.rb +0 -220
- data/spec/helpers/taxons_helper_spec.rb +0 -17
- data/spec/lib/calculated_adjustments_spec.rb +0 -7
- data/spec/lib/i18n_spec.rb +0 -123
- data/spec/lib/search/base_spec.rb +0 -86
- data/spec/lib/search/variant_spec.rb +0 -92
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -66
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -92
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -16
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
- data/spec/lib/spree/core/current_store_spec.rb +0 -36
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
- data/spec/lib/spree/core/importer/order_spec.rb +0 -431
- data/spec/lib/spree/core/role_configuration_spec.rb +0 -138
- data/spec/lib/spree/core/validators/email_spec.rb +0 -48
- data/spec/lib/spree/localized_number_spec.rb +0 -38
- data/spec/lib/spree/migrations_spec.rb +0 -36
- data/spec/lib/spree/money_spec.rb +0 -127
- data/spec/lib/tasks/exchanges_spec.rb +0 -231
- data/spec/lib/tasks/migrations/copy_shipped_shipments_to_cartons_spec.rb +0 -115
- data/spec/lib/tasks/order_capturing_spec.rb +0 -56
- data/spec/mailers/carton_mailer_spec.rb +0 -43
- data/spec/mailers/order_mailer_spec.rb +0 -122
- data/spec/mailers/reimbursement_mailer_spec.rb +0 -40
- data/spec/mailers/test_mailer_spec.rb +0 -15
- data/spec/models/spree/ability_spec.rb +0 -276
- data/spec/models/spree/address_spec.rb +0 -250
- data/spec/models/spree/adjustment_reason_spec.rb +0 -13
- data/spec/models/spree/adjustment_spec.rb +0 -177
- data/spec/models/spree/app_configuration_spec.rb +0 -20
- data/spec/models/spree/asset_spec.rb +0 -24
- data/spec/models/spree/calculator/default_tax_spec.rb +0 -127
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
- data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
- data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
- data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -51
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -30
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -36
- data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -47
- data/spec/models/spree/calculator_spec.rb +0 -36
- data/spec/models/spree/carton_spec.rb +0 -133
- data/spec/models/spree/classification_spec.rb +0 -15
- data/spec/models/spree/concerns/display_money_spec.rb +0 -43
- data/spec/models/spree/concerns/user_methods_spec.rb +0 -41
- data/spec/models/spree/credit_card_spec.rb +0 -334
- data/spec/models/spree/customer_return_spec.rb +0 -276
- data/spec/models/spree/exchange_spec.rb +0 -79
- data/spec/models/spree/gateway/bogus_simple.rb +0 -20
- data/spec/models/spree/gateway/bogus_spec.rb +0 -13
- data/spec/models/spree/gateway_spec.rb +0 -82
- data/spec/models/spree/inventory_unit_spec.rb +0 -307
- data/spec/models/spree/item_adjustments_spec.rb +0 -256
- data/spec/models/spree/line_item_spec.rb +0 -191
- data/spec/models/spree/option_type_spec.rb +0 -14
- data/spec/models/spree/option_value_spec.rb +0 -22
- data/spec/models/spree/order/address_spec.rb +0 -50
- data/spec/models/spree/order/adjustments_spec.rb +0 -39
- data/spec/models/spree/order/callbacks_spec.rb +0 -42
- data/spec/models/spree/order/checkout_spec.rb +0 -902
- data/spec/models/spree/order/currency_updater_spec.rb +0 -32
- data/spec/models/spree/order/finalizing_spec.rb +0 -111
- data/spec/models/spree/order/payment_spec.rb +0 -210
- data/spec/models/spree/order/risk_assessment_spec.rb +0 -68
- data/spec/models/spree/order/state_machine_spec.rb +0 -221
- data/spec/models/spree/order/tax_spec.rb +0 -84
- data/spec/models/spree/order/totals_spec.rb +0 -24
- data/spec/models/spree/order/updating_spec.rb +0 -18
- data/spec/models/spree/order/validations_spec.rb +0 -15
- data/spec/models/spree/order_cancellations_spec.rb +0 -120
- data/spec/models/spree/order_capturing_spec.rb +0 -116
- data/spec/models/spree/order_contents_spec.rb +0 -265
- data/spec/models/spree/order_inventory_spec.rb +0 -228
- data/spec/models/spree/order_mutex_spec.rb +0 -85
- data/spec/models/spree/order_promotion_spec.rb +0 -31
- data/spec/models/spree/order_shipping_spec.rb +0 -247
- data/spec/models/spree/order_spec.rb +0 -1464
- data/spec/models/spree/order_stock_location_spec.rb +0 -18
- data/spec/models/spree/order_updater_spec.rb +0 -299
- data/spec/models/spree/payment_method/store_credit_spec.rb +0 -294
- data/spec/models/spree/payment_method_spec.rb +0 -96
- data/spec/models/spree/payment_spec.rb +0 -1045
- data/spec/models/spree/permission_sets/base_spec.rb +0 -12
- data/spec/models/spree/permission_sets/configuration_display.rb +0 -82
- data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -50
- data/spec/models/spree/permission_sets/dashboard_display_spec.rb +0 -22
- data/spec/models/spree/permission_sets/order_display_spec.rb +0 -49
- data/spec/models/spree/permission_sets/order_management_spec.rb +0 -36
- data/spec/models/spree/permission_sets/product_display_spec.rb +0 -60
- data/spec/models/spree/permission_sets/product_management_spec.rb +0 -40
- data/spec/models/spree/permission_sets/promotion_display_spec.rb +0 -34
- data/spec/models/spree/permission_sets/promotion_management_spec.rb +0 -26
- data/spec/models/spree/permission_sets/report_display_spec.rb +0 -24
- data/spec/models/spree/permission_sets/restricted_transfer_management_spec.rb +0 -132
- data/spec/models/spree/permission_sets/stock_display_spec.rb +0 -26
- data/spec/models/spree/permission_sets/stock_management_spec.rb +0 -24
- data/spec/models/spree/permission_sets/user_display_spec.rb +0 -36
- data/spec/models/spree/permission_sets/user_management_spec.rb +0 -28
- data/spec/models/spree/preference_spec.rb +0 -80
- data/spec/models/spree/preferences/configuration_spec.rb +0 -30
- data/spec/models/spree/preferences/preferable_spec.rb +0 -294
- data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
- data/spec/models/spree/preferences/static_model_preferences_spec.rb +0 -78
- data/spec/models/spree/preferences/statically_configurable_spec.rb +0 -60
- data/spec/models/spree/preferences/store_spec.rb +0 -39
- data/spec/models/spree/price_spec.rb +0 -42
- data/spec/models/spree/product/scopes_spec.rb +0 -148
- data/spec/models/spree/product_duplicator_spec.rb +0 -103
- data/spec/models/spree/product_filter_spec.rb +0 -26
- data/spec/models/spree/product_property_spec.rb +0 -20
- data/spec/models/spree/product_spec.rb +0 -437
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -96
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -165
- data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +0 -115
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -40
- data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
- data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -67
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +0 -70
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
- data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -94
- data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
- data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
- data/spec/models/spree/promotion/rules/user_spec.rb +0 -37
- data/spec/models/spree/promotion_builder_spec.rb +0 -118
- data/spec/models/spree/promotion_category_spec.rb +0 -17
- data/spec/models/spree/promotion_code/code_builder_spec.rb +0 -79
- data/spec/models/spree/promotion_code_spec.rb +0 -187
- data/spec/models/spree/promotion_handler/cart_spec.rb +0 -114
- data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -335
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -47
- data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
- data/spec/models/spree/promotion_rule_spec.rb +0 -28
- data/spec/models/spree/promotion_spec.rb +0 -767
- data/spec/models/spree/refund_spec.rb +0 -204
- data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
- data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
- data/spec/models/spree/reimbursement_spec.rb +0 -231
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -51
- data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -107
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -97
- data/spec/models/spree/return_authorization_spec.rb +0 -290
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -85
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
- data/spec/models/spree/return_item_spec.rb +0 -775
- data/spec/models/spree/returns_calculator_spec.rb +0 -14
- data/spec/models/spree/shipment_spec.rb +0 -709
- data/spec/models/spree/shipping_calculator_spec.rb +0 -45
- data/spec/models/spree/shipping_method_spec.rb +0 -88
- data/spec/models/spree/shipping_rate_spec.rb +0 -142
- data/spec/models/spree/state_spec.rb +0 -14
- data/spec/models/spree/stock/availability_validator_spec.rb +0 -83
- data/spec/models/spree/stock/coordinator_spec.rb +0 -116
- data/spec/models/spree/stock/differentiator_spec.rb +0 -39
- data/spec/models/spree/stock/estimator_spec.rb +0 -146
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
- data/spec/models/spree/stock/package_spec.rb +0 -163
- data/spec/models/spree/stock/packer_spec.rb +0 -91
- data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
- data/spec/models/spree/stock/quantifier_spec.rb +0 -115
- data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
- data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -50
- data/spec/models/spree/stock/splitter/weight_spec.rb +0 -29
- data/spec/models/spree/stock_item_spec.rb +0 -426
- data/spec/models/spree/stock_location_spec.rb +0 -279
- data/spec/models/spree/stock_movement_spec.rb +0 -56
- data/spec/models/spree/stock_transfer_spec.rb +0 -290
- data/spec/models/spree/store_credit_category_spec.rb +0 -17
- data/spec/models/spree/store_credit_event_spec.rb +0 -314
- data/spec/models/spree/store_credit_spec.rb +0 -876
- data/spec/models/spree/store_spec.rb +0 -55
- data/spec/models/spree/tax_category_spec.rb +0 -27
- data/spec/models/spree/tax_rate_spec.rb +0 -378
- data/spec/models/spree/taxon_spec.rb +0 -74
- data/spec/models/spree/taxonomy_spec.rb +0 -18
- data/spec/models/spree/tracker_spec.rb +0 -21
- data/spec/models/spree/transfer_item_spec.rb +0 -264
- data/spec/models/spree/unit_cancel_spec.rb +0 -148
- data/spec/models/spree/user_spec.rb +0 -223
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +0 -23
- data/spec/models/spree/variant/scopes_spec.rb +0 -55
- data/spec/models/spree/variant_spec.rb +0 -546
- data/spec/models/spree/zone_spec.rb +0 -305
- data/spec/spec_helper.rb +0 -78
- data/spec/support/big_decimal.rb +0 -5
- data/spec/support/concerns/default_price.rb +0 -34
- data/spec/support/dummy_ability.rb +0 -4
- data/spec/support/test_gateway.rb +0 -2
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::PaymentMethod, :type => :model do
|
4
|
-
describe "#available" do
|
5
|
-
before do
|
6
|
-
[nil, 'both', 'front_end', 'back_end'].each do |display_on|
|
7
|
-
Spree::Gateway::Test.create(
|
8
|
-
:name => 'Display Both',
|
9
|
-
:display_on => display_on,
|
10
|
-
:active => true,
|
11
|
-
:environment => 'test',
|
12
|
-
:description => 'foofah'
|
13
|
-
)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have 4 total methods" do
|
18
|
-
expect(Spree::PaymentMethod.all.size).to eq(4)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return all methods available to front-end/back-end when no parameter is passed" do
|
22
|
-
expect(Spree::PaymentMethod.available.size).to eq(2)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should return all methods available to front-end/back-end when display_on = :both" do
|
26
|
-
expect(Spree::PaymentMethod.available(:both).size).to eq(2)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should return all methods available to front-end when display_on = :front_end" do
|
30
|
-
expect(Spree::PaymentMethod.available(:front_end).size).to eq(2)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should return all methods available to back-end when display_on = :back_end" do
|
34
|
-
expect(Spree::PaymentMethod.available(:back_end).size).to eq(2)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#auto_capture?' do
|
39
|
-
class TestGateway < Spree::Gateway
|
40
|
-
def provider_class
|
41
|
-
Provider
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:gateway) { TestGateway.new }
|
46
|
-
|
47
|
-
subject { gateway.auto_capture? }
|
48
|
-
|
49
|
-
context 'when auto_capture is nil' do
|
50
|
-
before(:each) do
|
51
|
-
expect(Spree::Config).to receive('[]').with(:auto_capture).and_return(auto_capture)
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'and when Spree::Config[:auto_capture] is false' do
|
55
|
-
let(:auto_capture) { false }
|
56
|
-
|
57
|
-
it 'should be false' do
|
58
|
-
expect(gateway.auto_capture).to be_nil
|
59
|
-
expect(subject).to be false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'and when Spree::Config[:auto_capture] is true' do
|
64
|
-
let(:auto_capture) { true }
|
65
|
-
|
66
|
-
it 'should be true' do
|
67
|
-
expect(gateway.auto_capture).to be_nil
|
68
|
-
expect(subject).to be true
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'when auto_capture is not nil' do
|
74
|
-
before(:each) do
|
75
|
-
gateway.auto_capture = auto_capture
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'and is true' do
|
79
|
-
let(:auto_capture) { true }
|
80
|
-
|
81
|
-
it 'should be true' do
|
82
|
-
expect(subject).to be true
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'and is false' do
|
87
|
-
let(:auto_capture) { false }
|
88
|
-
|
89
|
-
it 'should be true' do
|
90
|
-
expect(subject).to be false
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
@@ -1,1045 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Payment, :type => :model do
|
4
|
-
let(:order) { Spree::Order.create }
|
5
|
-
let(:refund_reason) { create(:refund_reason) }
|
6
|
-
|
7
|
-
let(:gateway) do
|
8
|
-
gateway = Spree::Gateway::Bogus.new(:environment => 'test', :active => true, :name => 'Bogus gateway')
|
9
|
-
allow(gateway).to receive_messages :source_required => true
|
10
|
-
gateway
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:avs_code) { 'D' }
|
14
|
-
let(:cvv_code) { 'M' }
|
15
|
-
|
16
|
-
let(:card) { create :credit_card }
|
17
|
-
|
18
|
-
let(:payment) do
|
19
|
-
payment = Spree::Payment.new
|
20
|
-
payment.source = card
|
21
|
-
payment.order = order
|
22
|
-
payment.payment_method = gateway
|
23
|
-
payment.amount = 5
|
24
|
-
payment
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:amount_in_cents) { (payment.amount * 100).round }
|
28
|
-
|
29
|
-
let!(:success_response) do
|
30
|
-
ActiveMerchant::Billing::Response.new(true, '', {}, {
|
31
|
-
authorization: '123',
|
32
|
-
cvv_result: cvv_code,
|
33
|
-
avs_result: { code: avs_code }
|
34
|
-
})
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:failed_response) do
|
38
|
-
ActiveMerchant::Billing::Response.new(false, '', {}, {})
|
39
|
-
end
|
40
|
-
|
41
|
-
before(:each) do
|
42
|
-
# So it doesn't create log entries every time a processing method is called
|
43
|
-
allow(payment.log_entries).to receive(:create!)
|
44
|
-
end
|
45
|
-
|
46
|
-
context '.risky' do
|
47
|
-
|
48
|
-
let!(:payment_1) { create(:payment, avs_response: 'Y', cvv_response_code: 'M', cvv_response_message: 'Match') }
|
49
|
-
let!(:payment_2) { create(:payment, avs_response: 'Y', cvv_response_code: 'M', cvv_response_message: '') }
|
50
|
-
let!(:payment_3) { create(:payment, avs_response: 'A', cvv_response_code: 'M', cvv_response_message: 'Match') }
|
51
|
-
let!(:payment_4) { create(:payment, avs_response: 'Y', cvv_response_code: 'N', cvv_response_message: 'No Match') }
|
52
|
-
|
53
|
-
it 'should not return successful responses' do
|
54
|
-
expect(subject.class.risky.to_a).to match_array([payment_3, payment_4])
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
context "#captured_amount" do
|
60
|
-
context "calculates based on capture events" do
|
61
|
-
it "with 0 capture events" do
|
62
|
-
expect(payment.captured_amount).to eq(0)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "with some capture events" do
|
66
|
-
payment.save
|
67
|
-
payment.capture_events.create!(amount: 2.0)
|
68
|
-
payment.capture_events.create!(amount: 3.0)
|
69
|
-
expect(payment.captured_amount).to eq(5)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context '#uncaptured_amount' do
|
75
|
-
context "calculates based on capture events" do
|
76
|
-
it "with 0 capture events" do
|
77
|
-
expect(payment.uncaptured_amount).to eq(5.0)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "with some capture events" do
|
81
|
-
payment.save
|
82
|
-
payment.capture_events.create!(amount: 2.0)
|
83
|
-
payment.capture_events.create!(amount: 3.0)
|
84
|
-
expect(payment.uncaptured_amount).to eq(0)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'validations' do
|
90
|
-
it "returns useful error messages when source is invalid" do
|
91
|
-
payment.source = Spree::CreditCard.new
|
92
|
-
expect(payment).not_to be_valid
|
93
|
-
cc_errors = payment.errors['Credit Card']
|
94
|
-
expect(cc_errors).to include("Number can't be blank")
|
95
|
-
expect(cc_errors).to include("Month is not a number")
|
96
|
-
expect(cc_errors).to include("Year is not a number")
|
97
|
-
expect(cc_errors).to include("Verification Value can't be blank")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# Regression test for https://github.com/spree/spree/pull/2224
|
102
|
-
context 'failure' do
|
103
|
-
it 'should transition to failed from pending state' do
|
104
|
-
payment.state = 'pending'
|
105
|
-
payment.failure
|
106
|
-
expect(payment.state).to eql('failed')
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should transition to failed from processing state' do
|
110
|
-
payment.state = 'processing'
|
111
|
-
payment.failure
|
112
|
-
expect(payment.state).to eql('failed')
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'invalidate' do
|
118
|
-
it 'should transition from checkout to invalid' do
|
119
|
-
payment.state = 'checkout'
|
120
|
-
payment.invalidate
|
121
|
-
expect(payment.state).to eq('invalid')
|
122
|
-
end
|
123
|
-
|
124
|
-
context "the payment's source is invalid" do
|
125
|
-
|
126
|
-
before(:each) do
|
127
|
-
card.year = 2014
|
128
|
-
payment.source = card
|
129
|
-
end
|
130
|
-
|
131
|
-
it "transitions to invalid" do
|
132
|
-
payment.state = 'checkout'
|
133
|
-
payment.invalidate
|
134
|
-
expect(payment.state).to eq ('invalid')
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "processing" do
|
140
|
-
describe "#process!" do
|
141
|
-
context 'with autocapture' do
|
142
|
-
before do
|
143
|
-
payment.payment_method.update_attributes!(auto_capture: true)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should purchase" do
|
147
|
-
payment.process!
|
148
|
-
expect(payment).to be_completed
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'without autocapture' do
|
153
|
-
before do
|
154
|
-
payment.payment_method.update_attributes!(auto_capture: false)
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'when in the checkout state' do
|
158
|
-
before { payment.update_attributes!(state: 'checkout') }
|
159
|
-
|
160
|
-
it "authorizes" do
|
161
|
-
payment.process!
|
162
|
-
expect(payment).to be_pending
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context 'when in the processing state' do
|
167
|
-
before { payment.update_attributes!(state: 'processing') }
|
168
|
-
|
169
|
-
it "does not authorize" do
|
170
|
-
payment.process!
|
171
|
-
expect(payment).to be_processing
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'when in the pending state' do
|
176
|
-
before { payment.update_attributes!(state: 'pending') }
|
177
|
-
|
178
|
-
it "does not re-authorize" do
|
179
|
-
expect(payment).to_not receive(:authorize!)
|
180
|
-
payment.process!
|
181
|
-
expect(payment).to be_pending
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context 'when in a failed state' do
|
186
|
-
before { payment.update_attributes!(state: 'failed') }
|
187
|
-
|
188
|
-
it "raises an exception" do
|
189
|
-
expect {
|
190
|
-
payment.process!
|
191
|
-
}.to raise_error(StateMachines::InvalidTransition, /Cannot transition/)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'when in the completed state' do
|
196
|
-
before { payment.update_attributes!(state: 'completed') }
|
197
|
-
|
198
|
-
it "authorizes" do
|
199
|
-
payment.process!
|
200
|
-
# TODO: Is this really what we want to happen in this case?
|
201
|
-
expect(payment).to be_pending
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should make the state 'processing'" do
|
207
|
-
expect(payment).to receive(:started_processing!)
|
208
|
-
payment.process!
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should invalidate if payment method doesnt support source" do
|
212
|
-
expect(payment.payment_method).to receive(:supports?).with(payment.source).and_return(false)
|
213
|
-
expect { payment.process!}.to raise_error(Spree::Core::GatewayError)
|
214
|
-
expect(payment.state).to eq('invalid')
|
215
|
-
end
|
216
|
-
|
217
|
-
# Regression test for #4598
|
218
|
-
it "should allow payments with a gateway_customer_profile_id" do
|
219
|
-
allow(payment.source).to receive_messages :gateway_customer_profile_id => "customer_1"
|
220
|
-
expect(payment.payment_method).to receive(:supports?).with(payment.source).and_return(false)
|
221
|
-
expect(payment).to receive(:started_processing!)
|
222
|
-
payment.process!
|
223
|
-
end
|
224
|
-
|
225
|
-
# Another regression test for #4598
|
226
|
-
it "should allow payments with a gateway_payment_profile_id" do
|
227
|
-
allow(payment.source).to receive_messages :gateway_payment_profile_id => "customer_1"
|
228
|
-
expect(payment.payment_method).to receive(:supports?).with(payment.source).and_return(false)
|
229
|
-
expect(payment).to receive(:started_processing!)
|
230
|
-
payment.process!
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "#authorize!" do
|
235
|
-
it "should call authorize on the gateway with the payment amount" do
|
236
|
-
expect(payment.payment_method).to receive(:authorize).with(amount_in_cents,
|
237
|
-
card,
|
238
|
-
anything).and_return(success_response)
|
239
|
-
payment.authorize!
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should call authorize on the gateway with the currency code" do
|
243
|
-
allow(payment).to receive_messages :currency => 'GBP'
|
244
|
-
expect(payment.payment_method).to receive(:authorize).with(amount_in_cents,
|
245
|
-
card,
|
246
|
-
hash_including({:currency => "GBP"})).and_return(success_response)
|
247
|
-
payment.authorize!
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should log the response" do
|
251
|
-
payment.save!
|
252
|
-
expect(payment.log_entries).to receive(:create!).with(details: anything)
|
253
|
-
payment.authorize!
|
254
|
-
end
|
255
|
-
|
256
|
-
context "when gateway does not match the environment" do
|
257
|
-
it "should raise an exception" do
|
258
|
-
allow(gateway).to receive_messages :environment => "foo"
|
259
|
-
expect { payment.authorize! }.to raise_error(Spree::Core::GatewayError)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "if successful" do
|
264
|
-
before do
|
265
|
-
expect(payment.payment_method).to receive(:authorize).with(amount_in_cents,
|
266
|
-
card,
|
267
|
-
anything).and_return(success_response)
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should store the response_code, avs_response and cvv_response fields" do
|
271
|
-
payment.authorize!
|
272
|
-
expect(payment.response_code).to eq('123')
|
273
|
-
expect(payment.avs_response).to eq(avs_code)
|
274
|
-
expect(payment.cvv_response_code).to eq(cvv_code)
|
275
|
-
expect(payment.cvv_response_message).to eq(ActiveMerchant::Billing::CVVResult::MESSAGES[cvv_code])
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should make payment pending" do
|
279
|
-
expect(payment).to receive(:pend!)
|
280
|
-
payment.authorize!
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
context "if unsuccessful" do
|
285
|
-
it "should mark payment as failed" do
|
286
|
-
allow(gateway).to receive(:authorize).and_return(failed_response)
|
287
|
-
expect(payment).to receive(:failure)
|
288
|
-
expect(payment).not_to receive(:pend)
|
289
|
-
expect {
|
290
|
-
payment.authorize!
|
291
|
-
}.to raise_error(Spree::Core::GatewayError)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
describe "#purchase!" do
|
297
|
-
it "should call purchase on the gateway with the payment amount" do
|
298
|
-
expect(gateway).to receive(:purchase).with(amount_in_cents, card, anything).and_return(success_response)
|
299
|
-
payment.purchase!
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should log the response" do
|
303
|
-
payment.save!
|
304
|
-
expect(payment.log_entries).to receive(:create!).with(details: anything)
|
305
|
-
payment.purchase!
|
306
|
-
end
|
307
|
-
|
308
|
-
context "when gateway does not match the environment" do
|
309
|
-
it "should raise an exception" do
|
310
|
-
allow(gateway).to receive_messages :environment => "foo"
|
311
|
-
expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError)
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
context "if successful" do
|
316
|
-
before do
|
317
|
-
expect(payment.payment_method).to receive(:purchase).with(amount_in_cents,
|
318
|
-
card,
|
319
|
-
anything).and_return(success_response)
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should store the response_code and avs_response" do
|
323
|
-
payment.purchase!
|
324
|
-
expect(payment.response_code).to eq('123')
|
325
|
-
expect(payment.avs_response).to eq(avs_code)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should make payment complete" do
|
329
|
-
expect(payment).to receive(:complete!)
|
330
|
-
payment.purchase!
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should log a capture event" do
|
334
|
-
payment.purchase!
|
335
|
-
expect(payment.capture_events.count).to eq(1)
|
336
|
-
expect(payment.capture_events.first.amount).to eq(payment.amount)
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should set the uncaptured amount to 0" do
|
340
|
-
payment.purchase!
|
341
|
-
expect(payment.uncaptured_amount).to eq(0)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
context "if unsuccessful" do
|
346
|
-
before do
|
347
|
-
allow(gateway).to receive(:purchase).and_return(failed_response)
|
348
|
-
expect(payment).to receive(:failure)
|
349
|
-
expect(payment).not_to receive(:pend)
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should make payment failed" do
|
353
|
-
expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError)
|
354
|
-
end
|
355
|
-
|
356
|
-
it "should not log a capture event" do
|
357
|
-
expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError)
|
358
|
-
expect(payment.capture_events.count).to eq(0)
|
359
|
-
end
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
describe "#capture!" do
|
364
|
-
context "when payment is pending" do
|
365
|
-
before do
|
366
|
-
payment.amount = 100
|
367
|
-
payment.state = 'pending'
|
368
|
-
payment.response_code = '12345'
|
369
|
-
end
|
370
|
-
|
371
|
-
context "if successful" do
|
372
|
-
context 'for entire amount' do
|
373
|
-
before do
|
374
|
-
expect(payment.payment_method).to receive(:capture).with(payment.display_amount.money.cents, payment.response_code, anything).and_return(success_response)
|
375
|
-
end
|
376
|
-
|
377
|
-
it "should make payment complete" do
|
378
|
-
expect(payment).to receive(:complete!)
|
379
|
-
payment.capture!
|
380
|
-
end
|
381
|
-
|
382
|
-
it "logs capture events" do
|
383
|
-
payment.capture!
|
384
|
-
expect(payment.capture_events.count).to eq(1)
|
385
|
-
expect(payment.capture_events.first.amount).to eq(payment.amount)
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
it "logs capture events" do
|
390
|
-
payment.capture!
|
391
|
-
expect(payment.capture_events.count).to eq(1)
|
392
|
-
expect(payment.capture_events.first.amount).to eq(payment.amount)
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
context "capturing a partial amount" do
|
397
|
-
it "logs capture events" do
|
398
|
-
payment.capture!(5000)
|
399
|
-
expect(payment.capture_events.count).to eq(1)
|
400
|
-
expect(payment.capture_events.first.amount).to eq(50)
|
401
|
-
end
|
402
|
-
|
403
|
-
it "stores the captured amount on the payment" do
|
404
|
-
payment.capture!(6000)
|
405
|
-
expect(payment.captured_amount).to eq(60)
|
406
|
-
end
|
407
|
-
|
408
|
-
it "updates the amount of the payment" do
|
409
|
-
payment.capture!(6000)
|
410
|
-
expect(payment.reload.amount).to eq(60)
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
context "if unsuccessful" do
|
415
|
-
it "should not make payment complete" do
|
416
|
-
allow(gateway).to receive_messages :capture => failed_response
|
417
|
-
expect(payment).to receive(:failure)
|
418
|
-
expect(payment).not_to receive(:complete)
|
419
|
-
expect { payment.capture! }.to raise_error(Spree::Core::GatewayError)
|
420
|
-
end
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
# Regression test for #2119
|
425
|
-
context "when payment is completed" do
|
426
|
-
before do
|
427
|
-
payment.state = 'completed'
|
428
|
-
end
|
429
|
-
|
430
|
-
it "should do nothing" do
|
431
|
-
expect(payment).not_to receive(:complete)
|
432
|
-
expect(payment.payment_method).not_to receive(:capture)
|
433
|
-
expect(payment.log_entries).not_to receive(:create!)
|
434
|
-
payment.capture!
|
435
|
-
end
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
describe "#cancel!" do
|
440
|
-
before do
|
441
|
-
payment.response_code = 'abc'
|
442
|
-
payment.state = 'pending'
|
443
|
-
end
|
444
|
-
|
445
|
-
context "if successful" do
|
446
|
-
it "should update the response_code with the authorization from the gateway" do
|
447
|
-
# Change it to something different
|
448
|
-
allow(gateway).to receive_messages :cancel => success_response
|
449
|
-
payment.cancel!
|
450
|
-
expect(payment.state).to eq('void')
|
451
|
-
expect(payment.response_code).to eq('123')
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
context "if unsuccessful" do
|
456
|
-
it "should not void the payment" do
|
457
|
-
allow(gateway).to receive_messages :cancel => failed_response
|
458
|
-
expect { payment.cancel! }.to raise_error(Spree::Core::GatewayError)
|
459
|
-
expect(payment.state).to eq('pending')
|
460
|
-
expect(payment.response_code).to eq('abc')
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
end
|
465
|
-
|
466
|
-
|
467
|
-
describe "#void_transaction!" do
|
468
|
-
before do
|
469
|
-
payment.response_code = '123'
|
470
|
-
payment.state = 'pending'
|
471
|
-
end
|
472
|
-
|
473
|
-
context "when profiles are supported" do
|
474
|
-
it "should call payment_gateway.void with the payment's response_code" do
|
475
|
-
allow(gateway).to receive_messages :payment_profiles_supported? => true
|
476
|
-
expect(gateway).to receive(:void).with('123', card, anything).and_return(success_response)
|
477
|
-
payment.void_transaction!
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
context "when profiles are not supported" do
|
482
|
-
it "should call payment_gateway.void with the payment's response_code" do
|
483
|
-
allow(gateway).to receive_messages :payment_profiles_supported? => false
|
484
|
-
expect(gateway).to receive(:void).with('123', anything).and_return(success_response)
|
485
|
-
payment.void_transaction!
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
|
-
it "should log the response" do
|
490
|
-
expect(payment.log_entries).to receive(:create!).with(:details => anything)
|
491
|
-
payment.void_transaction!
|
492
|
-
end
|
493
|
-
|
494
|
-
context "when gateway does not match the environment" do
|
495
|
-
it "should raise an exception" do
|
496
|
-
allow(gateway).to receive_messages :environment => "foo"
|
497
|
-
expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError)
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
context "if successful" do
|
502
|
-
it "should update the response_code with the authorization from the gateway" do
|
503
|
-
# Change it to something different
|
504
|
-
payment.response_code = 'abc'
|
505
|
-
payment.void_transaction!
|
506
|
-
expect(payment.response_code).to eq('12345')
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
context "if unsuccessful" do
|
511
|
-
it "should not void the payment" do
|
512
|
-
allow(gateway).to receive_messages :void => failed_response
|
513
|
-
expect(payment).not_to receive(:void)
|
514
|
-
expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError)
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
|
-
# Regression test for #2119
|
519
|
-
context "if payment is already voided" do
|
520
|
-
before do
|
521
|
-
payment.state = 'void'
|
522
|
-
end
|
523
|
-
|
524
|
-
it "should not void the payment" do
|
525
|
-
expect(payment.payment_method).not_to receive(:void)
|
526
|
-
payment.void_transaction!
|
527
|
-
end
|
528
|
-
end
|
529
|
-
end
|
530
|
-
|
531
|
-
end
|
532
|
-
|
533
|
-
context "when already processing" do
|
534
|
-
it "should return nil without trying to process the source" do
|
535
|
-
payment.state = 'processing'
|
536
|
-
|
537
|
-
expect(payment.process!).to be_nil
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
context "with source required" do
|
542
|
-
context "raises an error if no source is specified" do
|
543
|
-
before do
|
544
|
-
payment.source = nil
|
545
|
-
end
|
546
|
-
|
547
|
-
specify do
|
548
|
-
expect { payment.process! }.to raise_error(Spree::Core::GatewayError, Spree.t(:payment_processing_failed))
|
549
|
-
end
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
context "with source optional" do
|
554
|
-
context "raises no error if source is not specified" do
|
555
|
-
before do
|
556
|
-
payment.source = nil
|
557
|
-
allow(payment.payment_method).to receive_messages(:source_required? => false)
|
558
|
-
end
|
559
|
-
|
560
|
-
specify do
|
561
|
-
expect { payment.process! }.not_to raise_error
|
562
|
-
end
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
describe "#credit_allowed" do
|
567
|
-
# Regression test for #4403 & #4407
|
568
|
-
it "is the difference between offsets total and payment amount" do
|
569
|
-
payment.amount = 100
|
570
|
-
allow(payment).to receive(:offsets_total).and_return(0)
|
571
|
-
expect(payment.credit_allowed).to eq(100)
|
572
|
-
allow(payment).to receive(:offsets_total).and_return(-80)
|
573
|
-
expect(payment.credit_allowed).to eq(20)
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
describe "#can_credit?" do
|
578
|
-
it "is true if credit_allowed > 0" do
|
579
|
-
allow(payment).to receive(:credit_allowed).and_return(100)
|
580
|
-
expect(payment.can_credit?).to be true
|
581
|
-
end
|
582
|
-
|
583
|
-
it "is false if credit_allowed is 0" do
|
584
|
-
allow(payment).to receive(:credit_allowed).and_return(0)
|
585
|
-
expect(payment.can_credit?).to be false
|
586
|
-
end
|
587
|
-
end
|
588
|
-
|
589
|
-
describe "#save" do
|
590
|
-
context "captured payments" do
|
591
|
-
it "update order payment total" do
|
592
|
-
payment = create(:payment, order: order, state: 'completed')
|
593
|
-
expect(order.payment_total).to eq payment.amount
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
context "not completed payments" do
|
598
|
-
it "doesn't update order payment total" do
|
599
|
-
expect {
|
600
|
-
Spree::Payment.create(:amount => 100, :order => order)
|
601
|
-
}.not_to change { order.payment_total }
|
602
|
-
end
|
603
|
-
end
|
604
|
-
|
605
|
-
context 'when the payment was completed but now void' do
|
606
|
-
let(:payment) do
|
607
|
-
Spree::Payment.create(
|
608
|
-
amount: 100,
|
609
|
-
order: order,
|
610
|
-
state: 'completed'
|
611
|
-
)
|
612
|
-
end
|
613
|
-
|
614
|
-
it 'updates order payment total' do
|
615
|
-
payment.void
|
616
|
-
expect(order.payment_total).to eq 0
|
617
|
-
end
|
618
|
-
end
|
619
|
-
|
620
|
-
context "completed orders" do
|
621
|
-
let(:payment_method) { create(:check_payment_method) }
|
622
|
-
before { allow(order).to receive_messages completed?: true }
|
623
|
-
|
624
|
-
it "updates payment_state and shipments" do
|
625
|
-
expect(order.updater).to receive(:update_payment_state)
|
626
|
-
expect(order.updater).to receive(:update_shipment_state)
|
627
|
-
Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
|
628
|
-
end
|
629
|
-
end
|
630
|
-
|
631
|
-
context "when profiles are supported" do
|
632
|
-
before do
|
633
|
-
allow(gateway).to receive_messages :payment_profiles_supported? => true
|
634
|
-
allow(payment.source).to receive_messages :has_payment_profile? => false
|
635
|
-
end
|
636
|
-
|
637
|
-
context "when there is an error connecting to the gateway" do
|
638
|
-
it "should call gateway_error " do
|
639
|
-
expect(gateway).to receive(:create_profile).and_raise(ActiveMerchant::ConnectionError.new("foo", nil))
|
640
|
-
expect do
|
641
|
-
Spree::Payment.create(
|
642
|
-
:amount => 100,
|
643
|
-
:order => order,
|
644
|
-
:source => card,
|
645
|
-
:payment_method => gateway
|
646
|
-
)
|
647
|
-
end.to raise_error(Spree::Core::GatewayError)
|
648
|
-
end
|
649
|
-
end
|
650
|
-
|
651
|
-
context "with multiple payment attempts" do
|
652
|
-
let(:attributes) { attributes_for(:credit_card) }
|
653
|
-
it "should not try to create profiles on old failed payment attempts" do
|
654
|
-
allow_any_instance_of(Spree::Payment).to receive(:payment_method) { gateway }
|
655
|
-
|
656
|
-
order.payments.create!(
|
657
|
-
source_attributes: attributes,
|
658
|
-
payment_method: gateway,
|
659
|
-
amount: 100
|
660
|
-
)
|
661
|
-
expect(gateway).to receive(:create_profile).exactly :once
|
662
|
-
expect(order.payments.count).to eq(1)
|
663
|
-
order.payments.create!(
|
664
|
-
source_attributes: attributes,
|
665
|
-
payment_method: gateway,
|
666
|
-
amount: 100
|
667
|
-
)
|
668
|
-
end
|
669
|
-
|
670
|
-
end
|
671
|
-
|
672
|
-
context "when successfully connecting to the gateway" do
|
673
|
-
it "should create a payment profile" do
|
674
|
-
expect(payment.payment_method).to receive :create_profile
|
675
|
-
payment = Spree::Payment.create(
|
676
|
-
:amount => 100,
|
677
|
-
:order => order,
|
678
|
-
:source => card,
|
679
|
-
:payment_method => gateway
|
680
|
-
)
|
681
|
-
end
|
682
|
-
end
|
683
|
-
end
|
684
|
-
|
685
|
-
context "when profiles are not supported" do
|
686
|
-
before { allow(gateway).to receive_messages :payment_profiles_supported? => false }
|
687
|
-
|
688
|
-
it "should not create a payment profile" do
|
689
|
-
expect(gateway).not_to receive :create_profile
|
690
|
-
payment = Spree::Payment.create(
|
691
|
-
:amount => 100,
|
692
|
-
:order => order,
|
693
|
-
:source => card,
|
694
|
-
:payment_method => gateway
|
695
|
-
)
|
696
|
-
end
|
697
|
-
end
|
698
|
-
end
|
699
|
-
|
700
|
-
describe '#invalidate_old_payments' do
|
701
|
-
it 'should not invalidate other payments if not valid' do
|
702
|
-
payment.save
|
703
|
-
invalid_payment = Spree::Payment.new(:amount => 100, :order => order, :state => 'invalid', :payment_method => gateway)
|
704
|
-
invalid_payment.save
|
705
|
-
expect(payment.reload.state).to eq('checkout')
|
706
|
-
end
|
707
|
-
end
|
708
|
-
|
709
|
-
describe "#build_source" do
|
710
|
-
let(:params) do
|
711
|
-
{
|
712
|
-
:amount => 100,
|
713
|
-
:payment_method => gateway,
|
714
|
-
:source_attributes => {
|
715
|
-
:expiry =>"01 / 99",
|
716
|
-
:number => '1234567890123',
|
717
|
-
:verification_value => '123',
|
718
|
-
:name => 'Spree Commerce'
|
719
|
-
}
|
720
|
-
}
|
721
|
-
end
|
722
|
-
|
723
|
-
it "should build the payment's source" do
|
724
|
-
payment = Spree::Payment.new(params)
|
725
|
-
expect(payment).to be_valid
|
726
|
-
expect(payment.source).not_to be_nil
|
727
|
-
end
|
728
|
-
|
729
|
-
it "assigns user and gateway to payment source" do
|
730
|
-
order = create(:order)
|
731
|
-
source = order.payments.new(params).source
|
732
|
-
|
733
|
-
expect(source.user_id).to eq order.user_id
|
734
|
-
expect(source.payment_method_id).to eq gateway.id
|
735
|
-
end
|
736
|
-
|
737
|
-
it "errors when payment source not valid" do
|
738
|
-
params = { :amount => 100, :payment_method => gateway,
|
739
|
-
:source_attributes => {:expiry => "1 / 12" }}
|
740
|
-
|
741
|
-
payment = Spree::Payment.new(params)
|
742
|
-
expect(payment).not_to be_valid
|
743
|
-
expect(payment.source).not_to be_nil
|
744
|
-
expect(payment.source.error_on(:number).size).to eq(1)
|
745
|
-
expect(payment.source.error_on(:verification_value).size).to eq(1)
|
746
|
-
end
|
747
|
-
|
748
|
-
it "does not build a new source when duplicating the model with source_attributes set" do
|
749
|
-
payment = create(:payment)
|
750
|
-
payment.source_attributes = params[:source_attributes]
|
751
|
-
expect { payment.dup }.to_not change { payment.source }
|
752
|
-
end
|
753
|
-
end
|
754
|
-
|
755
|
-
describe "#currency" do
|
756
|
-
before { allow(order).to receive(:currency) { "ABC" } }
|
757
|
-
it "returns the order currency" do
|
758
|
-
expect(payment.currency).to eq("ABC")
|
759
|
-
end
|
760
|
-
end
|
761
|
-
|
762
|
-
describe "#display_amount" do
|
763
|
-
it "returns a Spree::Money for this amount" do
|
764
|
-
expect(payment.display_amount).to eq(Spree::Money.new(payment.amount))
|
765
|
-
end
|
766
|
-
end
|
767
|
-
|
768
|
-
# Regression test for #2216
|
769
|
-
describe "#gateway_options" do
|
770
|
-
before { allow(order).to receive_messages(:last_ip_address => "192.168.1.1") }
|
771
|
-
|
772
|
-
it "contains an IP" do
|
773
|
-
expect(payment.gateway_options[:ip]).to eq(order.last_ip_address)
|
774
|
-
end
|
775
|
-
|
776
|
-
it "contains the email address from a persisted order" do
|
777
|
-
# Sets the payment's order to a different Ruby object entirely
|
778
|
-
payment.order = Spree::Order.find(payment.order_id)
|
779
|
-
email = 'foo@example.com'
|
780
|
-
order.update_attributes(:email => email)
|
781
|
-
expect(payment.gateway_options[:email]).to eq(email)
|
782
|
-
end
|
783
|
-
end
|
784
|
-
|
785
|
-
describe "#set_unique_identifier" do
|
786
|
-
# Regression test for #1998
|
787
|
-
it "sets a unique identifier on create" do
|
788
|
-
payment.run_callbacks(:create)
|
789
|
-
expect(payment.identifier).not_to be_blank
|
790
|
-
expect(payment.identifier.size).to eq(8)
|
791
|
-
expect(payment.identifier).to be_a(String)
|
792
|
-
end
|
793
|
-
|
794
|
-
# Regression test for #3733
|
795
|
-
it "does not regenerate the identifier on re-save" do
|
796
|
-
payment.save
|
797
|
-
old_identifier = payment.identifier
|
798
|
-
payment.save
|
799
|
-
expect(payment.identifier).to eq(old_identifier)
|
800
|
-
end
|
801
|
-
|
802
|
-
context "other payment exists" do
|
803
|
-
let(:other_payment) {
|
804
|
-
payment = Spree::Payment.new
|
805
|
-
payment.source = card
|
806
|
-
payment.order = order
|
807
|
-
payment.payment_method = gateway
|
808
|
-
payment
|
809
|
-
}
|
810
|
-
|
811
|
-
before { other_payment.save! }
|
812
|
-
|
813
|
-
it "doesn't set duplicate identifier" do
|
814
|
-
expect(payment).to receive(:generate_identifier).and_return(other_payment.identifier)
|
815
|
-
expect(payment).to receive(:generate_identifier).and_call_original
|
816
|
-
|
817
|
-
payment.run_callbacks(:create)
|
818
|
-
|
819
|
-
expect(payment.identifier).not_to be_blank
|
820
|
-
expect(payment.identifier).not_to eq(other_payment.identifier)
|
821
|
-
end
|
822
|
-
end
|
823
|
-
end
|
824
|
-
|
825
|
-
describe "#amount=" do
|
826
|
-
before do
|
827
|
-
subject.amount = amount
|
828
|
-
end
|
829
|
-
|
830
|
-
context "when the amount is a string" do
|
831
|
-
context "amount is a decimal" do
|
832
|
-
let(:amount) { '2.99' }
|
833
|
-
|
834
|
-
it '#amount' do
|
835
|
-
expect(subject.amount).to eql(BigDecimal('2.99'))
|
836
|
-
end
|
837
|
-
end
|
838
|
-
|
839
|
-
context "amount is an integer" do
|
840
|
-
let(:amount) { '2' }
|
841
|
-
|
842
|
-
it '#amount' do
|
843
|
-
expect(subject.amount).to eql(BigDecimal('2.0'))
|
844
|
-
end
|
845
|
-
end
|
846
|
-
|
847
|
-
context "amount contains a dollar sign" do
|
848
|
-
let(:amount) { '$2.99' }
|
849
|
-
|
850
|
-
it '#amount' do
|
851
|
-
expect(subject.amount).to eql(BigDecimal('2.99'))
|
852
|
-
end
|
853
|
-
end
|
854
|
-
|
855
|
-
context "amount contains a comma" do
|
856
|
-
let(:amount) { '$2,999.99' }
|
857
|
-
|
858
|
-
it '#amount' do
|
859
|
-
expect(subject.amount).to eql(BigDecimal('2999.99'))
|
860
|
-
end
|
861
|
-
end
|
862
|
-
|
863
|
-
context "amount contains a negative sign" do
|
864
|
-
let(:amount) { '-2.99' }
|
865
|
-
|
866
|
-
it '#amount' do
|
867
|
-
expect(subject.amount).to eql(BigDecimal('-2.99'))
|
868
|
-
end
|
869
|
-
end
|
870
|
-
|
871
|
-
context "amount is invalid" do
|
872
|
-
let(:amount) { 'invalid' }
|
873
|
-
|
874
|
-
# this is a strange default for ActiveRecord
|
875
|
-
|
876
|
-
it '#amount' do
|
877
|
-
expect(subject.amount).to eql(BigDecimal('0'))
|
878
|
-
end
|
879
|
-
end
|
880
|
-
|
881
|
-
context "amount is an empty string" do
|
882
|
-
let(:amount) { '' }
|
883
|
-
|
884
|
-
it '#amount' do
|
885
|
-
expect(subject.amount).to be_nil
|
886
|
-
end
|
887
|
-
end
|
888
|
-
end
|
889
|
-
|
890
|
-
context "when the amount is a number" do
|
891
|
-
let(:amount) { 1.55 }
|
892
|
-
|
893
|
-
it '#amount' do
|
894
|
-
expect(subject.amount).to eql(BigDecimal('1.55'))
|
895
|
-
end
|
896
|
-
end
|
897
|
-
|
898
|
-
context "when the locale uses a coma as a decimal separator" do
|
899
|
-
before(:each) do
|
900
|
-
I18n.backend.store_translations(:fr, { :number => { :currency => { :format => { :delimiter => ' ', :separator => ',' } } } })
|
901
|
-
I18n.locale = :fr
|
902
|
-
subject.amount = amount
|
903
|
-
end
|
904
|
-
|
905
|
-
after do
|
906
|
-
I18n.locale = I18n.default_locale
|
907
|
-
end
|
908
|
-
|
909
|
-
context "amount is a decimal" do
|
910
|
-
let(:amount) { '2,99' }
|
911
|
-
|
912
|
-
it '#amount' do
|
913
|
-
expect(subject.amount).to eql(BigDecimal('2.99'))
|
914
|
-
end
|
915
|
-
end
|
916
|
-
|
917
|
-
context "amount contains a $ sign" do
|
918
|
-
let(:amount) { '2,99 $' }
|
919
|
-
|
920
|
-
it '#amount' do
|
921
|
-
expect(subject.amount).to eql(BigDecimal('2.99'))
|
922
|
-
end
|
923
|
-
end
|
924
|
-
|
925
|
-
context "amount is a number" do
|
926
|
-
let(:amount) { 2.99 }
|
927
|
-
|
928
|
-
it '#amount' do
|
929
|
-
expect(subject.amount).to eql(BigDecimal('2.99'))
|
930
|
-
end
|
931
|
-
end
|
932
|
-
|
933
|
-
context "amount contains a negative sign" do
|
934
|
-
let(:amount) { '-2,99 $' }
|
935
|
-
|
936
|
-
it '#amount' do
|
937
|
-
expect(subject.amount).to eql(BigDecimal('-2.99'))
|
938
|
-
end
|
939
|
-
end
|
940
|
-
|
941
|
-
context "amount uses a dot as a decimal separator" do
|
942
|
-
let(:amount) { '2.99' }
|
943
|
-
|
944
|
-
it '#amount' do
|
945
|
-
expect(subject.amount).to eql(BigDecimal('2.99'))
|
946
|
-
end
|
947
|
-
end
|
948
|
-
end
|
949
|
-
end
|
950
|
-
|
951
|
-
describe "is_avs_risky?" do
|
952
|
-
it "returns false if avs_response included in NON_RISKY_AVS_CODES" do
|
953
|
-
('A'..'Z').reject{ |x| subject.class::RISKY_AVS_CODES.include?(x) }.to_a.each do |char|
|
954
|
-
payment.update_attribute(:avs_response, char)
|
955
|
-
expect(payment.is_avs_risky?).to eq false
|
956
|
-
end
|
957
|
-
end
|
958
|
-
|
959
|
-
it "returns false if avs_response.blank?" do
|
960
|
-
payment.update_attribute(:avs_response, nil)
|
961
|
-
expect(payment.is_avs_risky?).to eq false
|
962
|
-
payment.update_attribute(:avs_response, '')
|
963
|
-
expect(payment.is_avs_risky?).to eq false
|
964
|
-
end
|
965
|
-
|
966
|
-
it "returns true if avs_response in RISKY_AVS_CODES" do
|
967
|
-
# should use avs_response_code helper
|
968
|
-
('A'..'Z').reject{ |x| subject.class::NON_RISKY_AVS_CODES.include?(x) }.to_a.each do |char|
|
969
|
-
payment.update_attribute(:avs_response, char)
|
970
|
-
expect(payment.is_avs_risky?).to eq true
|
971
|
-
end
|
972
|
-
end
|
973
|
-
end
|
974
|
-
|
975
|
-
describe "is_cvv_risky?" do
|
976
|
-
it "returns false if cvv_response_code == 'M'" do
|
977
|
-
payment.update_attribute(:cvv_response_code, "M")
|
978
|
-
expect(payment.is_cvv_risky?).to eq(false)
|
979
|
-
end
|
980
|
-
|
981
|
-
it "returns false if cvv_response_code == nil" do
|
982
|
-
payment.update_attribute(:cvv_response_code, nil)
|
983
|
-
expect(payment.is_cvv_risky?).to eq(false)
|
984
|
-
end
|
985
|
-
|
986
|
-
it "returns false if cvv_response_message == ''" do
|
987
|
-
payment.update_attribute(:cvv_response_message, '')
|
988
|
-
expect(payment.is_cvv_risky?).to eq(false)
|
989
|
-
end
|
990
|
-
|
991
|
-
it "returns true if cvv_response_code == [A-Z], omitting D" do
|
992
|
-
# should use cvv_response_code helper
|
993
|
-
(%w{N P S U} << "").each do |char|
|
994
|
-
payment.update_attribute(:cvv_response_code, char)
|
995
|
-
expect(payment.is_cvv_risky?).to eq(true)
|
996
|
-
end
|
997
|
-
end
|
998
|
-
end
|
999
|
-
|
1000
|
-
# Regression test for #4072 (kinda)
|
1001
|
-
# The need for this was discovered in the research for #4072
|
1002
|
-
context "state changes" do
|
1003
|
-
it "are logged to the database" do
|
1004
|
-
expect(payment.state_changes).to be_empty
|
1005
|
-
expect(payment.process!).to be true
|
1006
|
-
expect(payment.state_changes.count).to eq(2)
|
1007
|
-
changes = payment.state_changes.map { |change| { change.previous_state => change.next_state} }
|
1008
|
-
expect(changes).to match_array([
|
1009
|
-
{"checkout" => "processing"},
|
1010
|
-
{ "processing" => "pending"}
|
1011
|
-
])
|
1012
|
-
end
|
1013
|
-
end
|
1014
|
-
|
1015
|
-
describe "#actions" do
|
1016
|
-
let(:source) { Spree::CreditCard.new }
|
1017
|
-
before { allow(subject).to receive(:payment_source) { source } }
|
1018
|
-
|
1019
|
-
it "includes the actions that the source can take" do
|
1020
|
-
allow(source).to receive(:can_capture?) { true }
|
1021
|
-
expect(subject.actions).to include "capture"
|
1022
|
-
end
|
1023
|
-
|
1024
|
-
it "excludes actions that the source cannot take" do
|
1025
|
-
allow(source).to receive(:can_capture?) { false }
|
1026
|
-
expect(subject.actions).not_to include "capture"
|
1027
|
-
end
|
1028
|
-
|
1029
|
-
it "does not include 'failure' by default" do
|
1030
|
-
expect(subject.actions).not_to include "failure"
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
context "payment state is processing" do
|
1034
|
-
it "includes the 'failure' action" do
|
1035
|
-
# because the processing state does not provide
|
1036
|
-
# clarity about what has happened with an external
|
1037
|
-
# payment processor, so we want to allow the ability
|
1038
|
-
# to have someone look at the what happened and determine
|
1039
|
-
# to mark the payment as having failed
|
1040
|
-
subject.state = 'processing'
|
1041
|
-
expect(subject.actions).to include "failure"
|
1042
|
-
end
|
1043
|
-
end
|
1044
|
-
end
|
1045
|
-
end
|