Sha256: 157cc2bab456617e9bc185219fb5d40b1f02ac8d6aacada2182792fb86e98df3

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

module Workarea
  module Forter
    class BogusGateway
      attr_reader :options

      def initialize(options = {})
        @options = options
      end

      def create_decision(order_id, hsh = {})
        response_json = if hsh[:accountOwner][:email] == "decline@workarea.com"
          response_body(order_id, "decline")
        elsif hsh[:accountOwner][:email] == "notreviewed@workarea.com"
          response_body(order_id, "not reviewed")
        elsif hsh[:accountOwner][:email] == "error@workarea.com"
          error_body(order_id)
        else
          response_body(order_id, "approve")
        end

        response = Faraday.new do |builder|
          builder.adapter :test do |stub|
            stub.get('/rest/bogus.json') { |env| [ 200, {}, response_json ] }
          end
        end
        response.get('/rest/bogus.json')
      end

      def method_missing(method, *args)
        generic_response
      end

      private

        def generic_response
          response = Faraday.new do |builder|
            builder.adapter :test do |stub|
              stub.get('/rest/bogus.json') { |env| [ 200, {}, nil ] }
            end
          end
          response.get('/rest/bogus.json')
        end

        def response_body(id, action)
          {
            status: "success",
            transaction: "#{id}",
            action: "#{action}",
            message: "Transaction #{id}"
          }.to_json
        end

        def error_body(id)
          {
            status: "failure",
            action: "",
            errors: [{ "path" => "#/payment/", "message" => "Forced Gateway Error" }]
          }.to_json
        end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
workarea-forter-1.3.2 lib/workarea/forter/bogus_gateway.rb
workarea-forter-1.3.1 lib/workarea/forter/bogus_gateway.rb
workarea-forter-1.3.0 lib/workarea/forter/bogus_gateway.rb
workarea-forter-1.2.4 lib/workarea/forter/bogus_gateway.rb
workarea-forter-1.2.3 lib/workarea/forter/bogus_gateway.rb
workarea-forter-1.2.2 lib/workarea/forter/bogus_gateway.rb