require File.dirname(__FILE__) + '/../remote_helper' class RemoteOrderTransactionTest < ActiveSupport::TestCase context "Remote Order Transaction" do setup do MuckCommerce::Configure.enable_live_test_gateway @amount = rand(10000) # This helps prevent 'duplicate transaction' errors from the live gateway @user, @billing_information = setup_live_user_and_billing @options = { :order_id => ActiveMerchant::Utils.generate_unique_id, :description => 'A store purchase', :ip => '127.0.0.1' } end teardown do MuckCommerce::Configure.disable_live_test_gateway end context "authorize credit card" do should "successfully authorize the user's card" do @authorization = OrderTransaction.authorize(@amount, @billing_information, @options) assert @authorization.success?, @authorization.message end context "invalid credit card" do setup do @invalid_billing = Factory.build(:live_billing_information, :credit_card_number => '4111111111111211') end should "raise invalid card exception" do assert_raise(MuckCommerce::Exceptions::PaymentGatewayError) { OrderTransaction.authorize(@amount, @invalid_billing, @options) } end end end context 'purchase' do should "successfully charge the user's credit card" do payment = OrderTransaction.purchase(@amount, @billing_information, @options) assert payment.success?, payment.message assert_equal I18n.translate('muck.commerce.first_time_purchase'), payment.action assert_equal 'This transaction has been approved', payment.message end end context "purchase with credit card" do should "be successful" do payment = OrderTransaction.purchase(@amount, @billing_information, @options) assert payment.success?, payment.message assert_equal I18n.translate('muck.commerce.first_time_purchase'), payment.action end end context "transfer money" do setup do enable_test_paypal_gateway end teardown do MuckCommerce::Configure.enable_live_test_gateway end should "send money via paypal" do payment = OrderTransaction.purchase(@amount, @billing_information, @options) assert payment.success?, payment.message options = { :subject => "The money I owe you", :note => "Sorry it's so late" } result = OrderTransaction.send_money_via_paypal(@amount, 'test@example.com', options) # Paypal won't let you transfer money out of a test account :-) # Keep this here to make sure send_money_via_paypal is functioning assert !result.success?, result.message assert_equal "Account is restricted", result.message end end # # context "purchase with vault id" do # # setup do # @user, @billing = setup_live_user_and_billing # @first_payment = OrderTransaction.purchase(@amount, @billing, @options) # this should give us a vault id # @billing.vault_id = @first_payment.params['customer_vault_id'] # @billing.save! # assert @first_payment.success? # @options = { :order_id => generate_unique_id, :description => 'A second store purchase' } # need a new order id # end # # should "be successful" do # payment = OrderTransaction.purchase(@amount, @billing, false, @options) # assert payment.success? # assert_equal 'purchase using vault', payment.action # assert_equal 'This transaction has been approved', payment.message # #assert_equal @amount.to_s, payment.params['paid_amount'] # #{"response"=>"1", "avsresponse"=>nil, "orderid"=>"0616adec4e9fb02ddddf692ae56db61e", "responsetext"=>"SUCCESS", "authcode"=>"123456", "transactionid"=>"858635334", "type"=>"sale", "response_code"=>"100", "cvvresponse"=>nil} nil # end # # end # context "purchase and update vault id" do # # setup do # @user, @billing = setup_live_user_and_billing # @first_payment = OrderTransaction.purchase(@amount, @billing, @options) # this should give us a vault id # @billing.vault_id = @first_payment.params['customer_vault_id'] # @billing.save! # assert @first_payment.success?, 'first payment to setup for vault id test failed' # @options = { :order_id => generate_unique_id, :description => 'A second store purchase' } # need a new order id # @billing.credit_card_type = 'master' # @billing.credit_card_number = MuckCommerceTestDefinitions::BRAIN_MASTERCARD # @billing.verification_value = '999' # # @billing.save! # end # # should "be successful" do # payment = OrderTransaction.purchase(@amount, @billing, @options) # assert payment.success? # assert_equal 'purchase using vault', payment.action # assert_equal 'This transaction has been approved', payment.message # #assert_equal @amount.to_s, payment.params['paid_amount'] # end # # end context "decline credit card" do should "be decline" do payment = OrderTransaction.purchase(0, @billing_information, @options) assert !payment.success? assert_equal I18n.translate('muck.commerce.first_time_purchase'), payment.action end end context "authorize.net cim" do setup do @options = { :order_id => ActiveMerchant::Utils.generate_unique_id, :description => 'A second store purchase' } # need a new order id end context "management actions" do should " create and delete cim entry" do # create entry response = OrderTransaction.cim_create(@billing_information) puts response.message if !response.success? assert response.success? assert_equal @billing_information.customer_profile_id, response.reference assert_equal @billing_information.customer_payment_profile_id, response.params["customer_payment_profile_id_list"]["numeric_string"] # delete entry response = OrderTransaction.cim_delete(@billing_information) assert response.success?, response.message end context "cim entry actions" do setup do response = OrderTransaction.cim_create(@billing_information) assert response.success?, response.message end teardown do response = OrderTransaction.cim_delete(@billing_information) end should "update cim" do # update entry @billing_information.first_name = 'something' @billing_information.last_name = 'else' response = OrderTransaction.cim_update(@billing_information) assert response.success?, response.message end should "validate user cim profile" do response = OrderTransaction.cim_validate_user(@billing_information) puts response.message if !response.success? assert response.success?, response.message end end should "determine whether to create or update entry" do # create entry response = OrderTransaction.cim_create_update(@billing_information) assert response.success? # update entry @billing_information.first_name = 'something' @billing_information.last_name = 'else' response = OrderTransaction.cim_create_update(@billing_information) assert response.success?, response.message end end context "payment actions" do setup do response = OrderTransaction.cim_create(@billing_information) end teardown do response = OrderTransaction.cim_delete(@billing_information) end should "purchase" do payment = OrderTransaction.cim_purchase(1234, @billing_information, @options) assert payment.success?, payment.message assert_equal I18n.translate('muck.commerce.purchase_cim'), payment.action end should "authorize" do payment = OrderTransaction.cim_authorize(1235, @billing_information, @options) assert payment.success?, payment.message assert_equal I18n.translate('muck.commerce.authorization_cim'), payment.action end end context "validation" do setup do response = OrderTransaction.cim_create(@billing_information) end teardown do response = OrderTransaction.cim_delete(@billing_information) end should "validate the user" do response = OrderTransaction.cim_validate_user(@billing_information) assert response.success? assert_equal I18n.translate('muck.commerce.cim_validate_profile'), response.action end end end end end