Sha256: 973a99afc9a1c3bb4d1cfd9729683825e0b7799da4c8f6eea6d2a147dae22ab1

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cardflex-ruby-0.1.2 lib/cardflex/three_step_gateway.rb
cardflex-ruby-0.1.1 lib/cardflex/three_step_gateway.rb