module Cardflex class ThreeStepGateway attr_reader :config def initialize(gateway) @gateway = gateway @config = gateway.config end # Three Step API def get_form_url(attributes) root = attributes.keys[0] raise ArgumentError, 'missing :redirect_url' unless attributes[root][:redirect_url] res = @config.http.post(attributes) _handle_intermediate_response(res) end def complete(token_id) raise ArgumentError, 'you must provide a token_id' unless token_id res = @config.http.post(:complete_action => { :token_id => token_id }) _handle_response(res) end def _handle_response(res) if res[:response][:result] == '1' SuccessResponse.new(:transaction => Transaction.new(@gateway, res[:response])) else ErrorResponse.new(@gateway, res[:response]) end end def _handle_intermediate_response(res) if res[:response][:result] == '1' SuccessResponse.new(:three_step => ThreeStep.new(@gateway, res[:response])) else ErrorResponse.new(@gateway, res[:response]) end end end end