Class: Suretax::Api::Request

Inherits:
Object
  • Object
show all
Includes:
Concerns::Validatable
Defined in:
lib/suretax/api/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Validatable

#errors, included

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/suretax/api/request.rb', line 36

def initialize(options = {})
  self.return_file_code = "0"
  self.client_number    = options.delete(:client_number)  || configuration.client_number
  self.validation_key   = options.delete(:validation_key) || configuration.validation_key

  default_data_date(options)

  options.each_pair do |key, value|
    send("#{key}=", value.to_s)
  end

  initialize_items(options)

  validate!
end

Instance Attribute Details

#business_unitObject

Returns the value of attribute business_unit.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def business_unit
  @business_unit
end

#client_numberObject

Returns the value of attribute client_number.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def client_number
  @client_number
end

#client_trackingObject

Returns the value of attribute client_tracking.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def client_tracking
  @client_tracking
end

#data_monthObject

Returns the value of attribute data_month.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def data_month
  @data_month
end

#data_yearObject

Returns the value of attribute data_year.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def data_year
  @data_year
end

#industry_exemptionObject

Returns the value of attribute industry_exemption.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def industry_exemption
  @industry_exemption
end

#itemsObject

Returns the value of attribute items.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def items
  @items
end

#responseObject (readonly)

Returns the value of attribute response.



22
23
24
# File 'lib/suretax/api/request.rb', line 22

def response
  @response
end

#response_groupObject

Returns the value of attribute response_group.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def response_group
  @response_group
end

#response_typeObject

Returns the value of attribute response_type.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def response_type
  @response_type
end

#return_file_codeObject

Returns the value of attribute return_file_code.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def return_file_code
  @return_file_code
end

#stanObject

Returns the value of attribute stan.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def stan
  @stan
end

#total_revenueObject

Returns the value of attribute total_revenue.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def total_revenue
  @total_revenue
end

#validation_keyObject

Returns the value of attribute validation_key.



8
9
10
# File 'lib/suretax/api/request.rb', line 8

def validation_key
  @validation_key
end

Instance Method Details

#paramsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/suretax/api/request.rb', line 74

def params
  {
    "ClientNumber"             => client_number,
    "BusinessUnit"             => business_unit || "",
    "ValidationKey"            => validation_key,
    "DataYear"                 => data_year,
    "DataMonth"                => data_month,
    "TotalRevenue"             => total_revenue.to_f,
    "ReturnFileCode"           => return_file_code,
    "ClientTracking"           => client_tracking || "",
    "IndustryExemption"        => industry_exemption,
    "ResponseType"             => response_type,
    "ResponseGroup"            => response_group,
    "STAN"                     => stan || "",
    "ItemList"                 => items.map(&:params)
  }
end

#rollbackObject



66
67
68
69
70
71
72
# File 'lib/suretax/api/request.rb', line 66

def rollback
  if response
    CancelRequest.new(transaction: response.transaction,
      client_number: client_number, validation_key: validation_key,
      client_tracking: client_tracking).submit
  end
end

#submitObject



52
53
54
55
56
57
58
59
60
# File 'lib/suretax/api/request.rb', line 52

def submit
  if valid?
    log_request
    suretax_response = connection.post(params)
    @response = Suretax::Api::Response.new(suretax_response.body)
  else
    raise(ValidationError, errors.messages.join(", "))
  end
end

#valid?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/suretax/api/request.rb', line 62

def valid?
  errors.none?
end