require 'spec_helper' describe Datatrans::XML::Transaction::AuthorizeRequest do before do @successful_response = { "authorizationService" => { "body" => { "transaction" => { "request" => { "amount" => "1000", "currency" => "CHF", "aliasCC" => "70323122544311173", "expm" => "12", "expy" => "15", "sign" => "1d236349b97fac15b267becb0792d185", "reqtype" => "NOA" }, "response" => { "responseCode" => "01", "responseMessage" => "Authorized", "uppTransactionId" => "110808142256858007", "authorizationCode" => "257128012", "acqAuthorizationCode" => "142257", "maskedCC" => "520000xxxxxx0007", "returnCustomerCountry" => "CHE" }, "refno" => "ABCDEF", "trxStatus" => "response" }, "merchantId" => "1100001872", "status" => "accepted" }, "version" => "1" } } @failed_response = { "authorizationService" => { "body" => { "transaction" => { "request" => { "amount" => "1000", "currency" => "CHF", "aliasCC" => "70323122544311173", "expm" => "12", "expy" => "15", "sign" => "1d236349b97fac15b267becb0792d185", "reqtype" => "NOA" }, "error" => { "errorCode" => "2021", "errorMessage" => "missing value", "errorDetail" => "CC-alias" }, "refno" => "ABCDEF", "trxStatus" => "response" }, "merchantId" => "1100001872", "status" => "accepted" }, "version" => "1" } } @valid_params = { :refno => 'ABCDEF', :amount => 1000, :currency => 'CHF', :aliasCC => '3784982984234', :expm => 12, :expy => 15 } end context "successful response" do before do Datatrans::XML::Transaction::AuthorizeRequest.any_instance.stub(:process).and_return(@successful_response) end context "build_authorize_request" do it "generates a valid datatrans authorize xml" do @request = Datatrans::XML::Transaction::AuthorizeRequest.new(@datatrans, @valid_params) @request.send(:build_authorize_request).should == "1000CHF378498298423412150402fb3fba8c6fcb40df9b7756e7e637" end end context "process" do it "handles a valid datatrans authorize response" do @transaction = Datatrans::XML::Transaction.new(@datatrans, @valid_params) @transaction.authorize.should be_true end end end context "failed response" do before do Datatrans::XML::Transaction::AuthorizeRequest.any_instance.stub(:process).and_return(@failed_response) @transaction = Datatrans::XML::Transaction.new(@datatrans, @valid_params) end context "process" do it "handles a failed datatrans authorize response" do @transaction.authorize.should be_false end it "returns error details" do @transaction.authorize @transaction.error_code.length.should > 0 @transaction.error_message.length.should > 0 @transaction.error_detail.length.should > 0 end end end end