Class: Plaid::Paystub

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/plaid/models/paystub.rb

Overview

An object representing data extracted from the end user’s paystub.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(employer:, employee:, pay_period_details:, income_breakdown:, ytd_earnings:, deductions: SKIP, doc_id: SKIP, earnings: SKIP, employment_details: SKIP, net_pay: SKIP, paystub_details: SKIP, additional_properties: nil) ⇒ Paystub

Returns a new instance of Paystub.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/plaid/models/paystub.rb', line 93

def initialize(employer:, employee:, pay_period_details:, income_breakdown:,
               ytd_earnings:, deductions: SKIP, doc_id: SKIP,
               earnings: SKIP, employment_details: SKIP, net_pay: SKIP,
               paystub_details: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @deductions = deductions unless deductions == SKIP
  @doc_id = doc_id unless doc_id == SKIP
  @earnings = earnings unless earnings == SKIP
  @employer = employer
  @employee = employee
  @employment_details = employment_details unless employment_details == SKIP
  @net_pay = net_pay unless net_pay == SKIP
  @pay_period_details = pay_period_details
  @paystub_details = paystub_details unless paystub_details == SKIP
  @income_breakdown = income_breakdown
  @ytd_earnings = ytd_earnings
  @additional_properties = additional_properties
end

Instance Attribute Details

#deductionsDeductions

An object with the deduction information found on a paystub.

Returns:



14
15
16
# File 'lib/plaid/models/paystub.rb', line 14

def deductions
  @deductions
end

#doc_idString

An identifier of the document referenced by the document metadata.

Returns:

  • (String)


18
19
20
# File 'lib/plaid/models/paystub.rb', line 18

def doc_id
  @doc_id
end

#earningsEarnings

An object representing both a breakdown of earnings on a paystub and the total earnings.

Returns:



23
24
25
# File 'lib/plaid/models/paystub.rb', line 23

def earnings
  @earnings
end

#employeeEmployee

Data about the employee.

Returns:



32
33
34
# File 'lib/plaid/models/paystub.rb', line 32

def employee
  @employee
end

#employerEmployer2

An object representing both a breakdown of earnings on a paystub and the total earnings.

Returns:



28
29
30
# File 'lib/plaid/models/paystub.rb', line 28

def employer
  @employer
end

#employment_detailsEmploymentDetails

An object representing employment details found on a paystub.

Returns:



36
37
38
# File 'lib/plaid/models/paystub.rb', line 36

def employment_details
  @employment_details
end

#income_breakdownArray[IncomeBreakdown]

An object representing details that can be found on the paystub.

Returns:



53
54
55
# File 'lib/plaid/models/paystub.rb', line 53

def income_breakdown
  @income_breakdown
end

#net_payNetPay

An object representing information about the net pay amount on the paystub.

Returns:



41
42
43
# File 'lib/plaid/models/paystub.rb', line 41

def net_pay
  @net_pay
end

#pay_period_detailsPayPeriodDetails

Details about the pay period.

Returns:



45
46
47
# File 'lib/plaid/models/paystub.rb', line 45

def pay_period_details
  @pay_period_details
end

#paystub_detailsPaystubDetails

An object representing details that can be found on the paystub.

Returns:



49
50
51
# File 'lib/plaid/models/paystub.rb', line 49

def paystub_details
  @paystub_details
end

#ytd_earningsPaystubYtdDetails

The amount of income earned year to date, as based on paystub data.

Returns:



57
58
59
# File 'lib/plaid/models/paystub.rb', line 57

def ytd_earnings
  @ytd_earnings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/plaid/models/paystub.rb', line 115

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  employer = Employer2.from_hash(hash['employer']) if hash['employer']
  employee = Employee.from_hash(hash['employee']) if hash['employee']
  pay_period_details = PayPeriodDetails.from_hash(hash['pay_period_details']) if
    hash['pay_period_details']
  # Parameter is an array, so we need to iterate through it
  income_breakdown = nil
  unless hash['income_breakdown'].nil?
    income_breakdown = []
    hash['income_breakdown'].each do |structure|
      income_breakdown << (IncomeBreakdown.from_hash(structure) if structure)
    end
  end

  income_breakdown = nil unless hash.key?('income_breakdown')
  ytd_earnings = PaystubYtdDetails.from_hash(hash['ytd_earnings']) if hash['ytd_earnings']
  deductions = Deductions.from_hash(hash['deductions']) if hash['deductions']
  doc_id = hash.key?('doc_id') ? hash['doc_id'] : SKIP
  earnings = Earnings.from_hash(hash['earnings']) if hash['earnings']
  employment_details = EmploymentDetails.from_hash(hash['employment_details']) if
    hash['employment_details']
  net_pay = NetPay.from_hash(hash['net_pay']) if hash['net_pay']
  paystub_details = PaystubDetails.from_hash(hash['paystub_details']) if
    hash['paystub_details']

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Paystub.new(employer: employer,
              employee: employee,
              pay_period_details: pay_period_details,
              income_breakdown: income_breakdown,
              ytd_earnings: ytd_earnings,
              deductions: deductions,
              doc_id: doc_id,
              earnings: earnings,
              employment_details: employment_details,
              net_pay: net_pay,
              paystub_details: paystub_details,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/plaid/models/paystub.rb', line 60

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['deductions'] = 'deductions'
  @_hash['doc_id'] = 'doc_id'
  @_hash['earnings'] = 'earnings'
  @_hash['employer'] = 'employer'
  @_hash['employee'] = 'employee'
  @_hash['employment_details'] = 'employment_details'
  @_hash['net_pay'] = 'net_pay'
  @_hash['pay_period_details'] = 'pay_period_details'
  @_hash['paystub_details'] = 'paystub_details'
  @_hash['income_breakdown'] = 'income_breakdown'
  @_hash['ytd_earnings'] = 'ytd_earnings'
  @_hash
end

.nullablesObject

An array for nullable fields



89
90
91
# File 'lib/plaid/models/paystub.rb', line 89

def self.nullables
  []
end

.optionalsObject

An array for optional fields



77
78
79
80
81
82
83
84
85
86
# File 'lib/plaid/models/paystub.rb', line 77

def self.optionals
  %w[
    deductions
    doc_id
    earnings
    employment_details
    net_pay
    paystub_details
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



176
177
178
179
180
181
182
183
184
# File 'lib/plaid/models/paystub.rb', line 176

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} deductions: #{@deductions.inspect}, doc_id: #{@doc_id.inspect}, earnings:"\
  " #{@earnings.inspect}, employer: #{@employer.inspect}, employee: #{@employee.inspect},"\
  " employment_details: #{@employment_details.inspect}, net_pay: #{@net_pay.inspect},"\
  " pay_period_details: #{@pay_period_details.inspect}, paystub_details:"\
  " #{@paystub_details.inspect}, income_breakdown: #{@income_breakdown.inspect}, ytd_earnings:"\
  " #{@ytd_earnings.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



166
167
168
169
170
171
172
173
# File 'lib/plaid/models/paystub.rb', line 166

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} deductions: #{@deductions}, doc_id: #{@doc_id}, earnings: #{@earnings},"\
  " employer: #{@employer}, employee: #{@employee}, employment_details:"\
  " #{@employment_details}, net_pay: #{@net_pay}, pay_period_details: #{@pay_period_details},"\
  " paystub_details: #{@paystub_details}, income_breakdown: #{@income_breakdown},"\
  " ytd_earnings: #{@ytd_earnings}, additional_properties: #{@additional_properties}>"
end