require 'test_helper' class RemotePurchaseTest < Test::Unit::TestCase def setup @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret) end def test_invalid_login assert_invalid_login do |environment| environment.purchase_on_gateway('gtoken', 'ptoken', 100) end end def test_payment_method_not_found assert_raise_with_message(Spreedly::TransactionCreationError, "There is no payment method corresponding to the specified payment method token.") do @environment.purchase_on_gateway('gateway_token', 'unknown_payment_method', 100) end end def test_gateway_not_found card_token = create_card_on(@environment).token assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified gateway.") do @environment.purchase_on_gateway('unknown_gateway', card_token, 100) end end def test_successful_purchase gateway_token = @environment.add_gateway(:test).token card_token = create_card_on(@environment).token transaction = @environment.purchase_on_gateway(gateway_token, card_token, 144) assert transaction.succeeded? assert_equal card_token, transaction.payment_method.token assert_equal 144, transaction.amount end def test_successful_purchase_with_stored_credentials gateway_token = @environment.add_gateway(:test).token card_token = create_card_on(@environment).token transaction = @environment.purchase_on_gateway( gateway_token, card_token, 899, stored_credential_initiator: :merchant, stored_credential_reason_type: :installment ) assert transaction.succeeded? assert_equal 'merchant', transaction.stored_credential_initiator assert_equal 'installment', transaction.stored_credential_reason_type end def test_failed_purchase gateway_token = @environment.add_gateway(:test).token card_token = create_failed_card_on(@environment).token transaction = @environment.purchase_on_gateway(gateway_token, card_token, 144) assert !transaction.succeeded? assert_equal "Unable to process the purchase transaction.", transaction.message assert_equal gateway_token, transaction.gateway_token end def test_offsite_transaction_arguments gateway_token = @environment.add_gateway(:test).token sprel_token = create_sprel_on(@environment) transaction = @environment.purchase_on_gateway(gateway_token, sprel_token, 344, order_id: "8675", description: "SuperDuper", ip: "183.128.100.103", email: "fred@example.com", merchant_name_descriptor: "Real Stuff", merchant_location_descriptor: "Raleigh", retain_on_success: true, redirect_url: "https://example.com/redirect", callback_url: "https://example.com/callback") assert_equal "pending", transaction.state assert "https://example.com/callback", transaction.callback_url assert "https://example.com/redirect", transaction.redirect_url assert transaction.checkout_url end def test_3d_secure_attempt_transaction_arguments gateway_token = @environment.add_gateway(:test).token card_token = create_card_on(@environment, number: '4556761029983886', retained: false).token transaction = @environment.purchase_on_gateway(gateway_token, card_token, 344, order_id: "8675", description: "SuperDuper", ip: "183.128.100.103", email: "fred@example.com", merchant_name_descriptor: "Real Stuff", merchant_location_descriptor: "Raleigh", retain_on_success: true, redirect_url: "https://example.com/redirect", callback_url: "https://example.com/callback", attempt_3dsecure: true) assert_equal "pending", transaction.state assert "https://example.com/callback", transaction.callback_url assert "https://example.com/redirect", transaction.redirect_url assert_equal '', transaction.checkout_url assert transaction.checkout_form.include?("