square_connect 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +5 -0
  3. data/CONTRIBUTING.md +5 -0
  4. data/LICENSE.txt +202 -0
  5. data/README.md +47 -0
  6. data/lib/square_connect.rb +88 -0
  7. data/lib/square_connect/api/customer_api.rb +354 -0
  8. data/lib/square_connect/api/customer_card_api.rb +163 -0
  9. data/lib/square_connect/api/location_api.rb +82 -0
  10. data/lib/square_connect/api/refund_api.rb +179 -0
  11. data/lib/square_connect/api/transaction_api.rb +387 -0
  12. data/lib/square_connect/api_client.rb +337 -0
  13. data/lib/square_connect/api_error.rb +31 -0
  14. data/lib/square_connect/configuration.rb +163 -0
  15. data/lib/square_connect/models/address.rb +288 -0
  16. data/lib/square_connect/models/capture_transaction_response.rb +160 -0
  17. data/lib/square_connect/models/card.rb +233 -0
  18. data/lib/square_connect/models/card_brand.rb +147 -0
  19. data/lib/square_connect/models/charge_request.rb +257 -0
  20. data/lib/square_connect/models/charge_response.rb +171 -0
  21. data/lib/square_connect/models/country.rb +147 -0
  22. data/lib/square_connect/models/create_customer_card_request.rb +180 -0
  23. data/lib/square_connect/models/create_customer_card_response.rb +171 -0
  24. data/lib/square_connect/models/create_customer_request.rb +246 -0
  25. data/lib/square_connect/models/create_customer_response.rb +171 -0
  26. data/lib/square_connect/models/create_refund_request.rb +191 -0
  27. data/lib/square_connect/models/create_refund_response.rb +171 -0
  28. data/lib/square_connect/models/currency.rb +147 -0
  29. data/lib/square_connect/models/customer.rb +292 -0
  30. data/lib/square_connect/models/delete_customer_card_response.rb +160 -0
  31. data/lib/square_connect/models/delete_customer_response.rb +160 -0
  32. data/lib/square_connect/models/error.rb +209 -0
  33. data/lib/square_connect/models/error_category.rb +147 -0
  34. data/lib/square_connect/models/error_code.rb +147 -0
  35. data/lib/square_connect/models/list_customers_request.rb +158 -0
  36. data/lib/square_connect/models/list_customers_response.rb +184 -0
  37. data/lib/square_connect/models/list_locations_response.rb +173 -0
  38. data/lib/square_connect/models/list_refunds_request.rb +200 -0
  39. data/lib/square_connect/models/list_refunds_response.rb +184 -0
  40. data/lib/square_connect/models/list_transactions_request.rb +200 -0
  41. data/lib/square_connect/models/list_transactions_response.rb +184 -0
  42. data/lib/square_connect/models/location.rb +204 -0
  43. data/lib/square_connect/models/location_capability.rb +147 -0
  44. data/lib/square_connect/models/money.rb +178 -0
  45. data/lib/square_connect/models/refund.rb +255 -0
  46. data/lib/square_connect/models/refund_status.rb +147 -0
  47. data/lib/square_connect/models/retrieve_customer_response.rb +171 -0
  48. data/lib/square_connect/models/retrieve_transaction_response.rb +171 -0
  49. data/lib/square_connect/models/sort_order.rb +147 -0
  50. data/lib/square_connect/models/tender.rb +277 -0
  51. data/lib/square_connect/models/tender_card_details.rb +198 -0
  52. data/lib/square_connect/models/tender_card_details_entry_method.rb +147 -0
  53. data/lib/square_connect/models/tender_card_details_status.rb +147 -0
  54. data/lib/square_connect/models/tender_cash_details.rb +169 -0
  55. data/lib/square_connect/models/tender_type.rb +147 -0
  56. data/lib/square_connect/models/transaction.rb +237 -0
  57. data/lib/square_connect/models/transaction_product.rb +147 -0
  58. data/lib/square_connect/models/update_customer_request.rb +246 -0
  59. data/lib/square_connect/models/update_customer_response.rb +171 -0
  60. data/lib/square_connect/models/void_transaction_response.rb +160 -0
  61. data/lib/square_connect/version.rb +13 -0
  62. data/square_connect.gemspec +32 -0
  63. metadata +286 -0
@@ -0,0 +1,288 @@
1
+ =begin
2
+ Square Connect API
3
+
4
+ OpenAPI spec version: 2.0
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ require 'date'
12
+
13
+ module SquareConnect
14
+ #
15
+ class Address
16
+ #
17
+ attr_accessor :address_line_1
18
+
19
+ #
20
+ attr_accessor :address_line_2
21
+
22
+ #
23
+ attr_accessor :address_line_3
24
+
25
+ #
26
+ attr_accessor :locality
27
+
28
+ #
29
+ attr_accessor :sublocality
30
+
31
+ #
32
+ attr_accessor :sublocality_2
33
+
34
+ #
35
+ attr_accessor :sublocality_3
36
+
37
+ #
38
+ attr_accessor :administrative_district_level_1
39
+
40
+ #
41
+ attr_accessor :administrative_district_level_2
42
+
43
+ #
44
+ attr_accessor :administrative_district_level_3
45
+
46
+ #
47
+ attr_accessor :postal_code
48
+
49
+ #
50
+ attr_accessor :country
51
+
52
+ # Attribute mapping from ruby-style variable name to JSON key.
53
+ def self.attribute_map
54
+ {
55
+
56
+ :'address_line_1' => :'address_line_1',
57
+
58
+ :'address_line_2' => :'address_line_2',
59
+
60
+ :'address_line_3' => :'address_line_3',
61
+
62
+ :'locality' => :'locality',
63
+
64
+ :'sublocality' => :'sublocality',
65
+
66
+ :'sublocality_2' => :'sublocality_2',
67
+
68
+ :'sublocality_3' => :'sublocality_3',
69
+
70
+ :'administrative_district_level_1' => :'administrative_district_level_1',
71
+
72
+ :'administrative_district_level_2' => :'administrative_district_level_2',
73
+
74
+ :'administrative_district_level_3' => :'administrative_district_level_3',
75
+
76
+ :'postal_code' => :'postal_code',
77
+
78
+ :'country' => :'country'
79
+
80
+ }
81
+ end
82
+
83
+ # Attribute type mapping.
84
+ def self.swagger_types
85
+ {
86
+ :'address_line_1' => :'String',
87
+ :'address_line_2' => :'String',
88
+ :'address_line_3' => :'String',
89
+ :'locality' => :'String',
90
+ :'sublocality' => :'String',
91
+ :'sublocality_2' => :'String',
92
+ :'sublocality_3' => :'String',
93
+ :'administrative_district_level_1' => :'String',
94
+ :'administrative_district_level_2' => :'String',
95
+ :'administrative_district_level_3' => :'String',
96
+ :'postal_code' => :'String',
97
+ :'country' => :'String'
98
+
99
+ }
100
+ end
101
+
102
+ def initialize(attributes = {})
103
+ return unless attributes.is_a?(Hash)
104
+
105
+ # convert string to symbol for hash key
106
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
107
+
108
+
109
+ if attributes[:'address_line_1']
110
+ self.address_line_1 = attributes[:'address_line_1']
111
+ end
112
+
113
+ if attributes[:'address_line_2']
114
+ self.address_line_2 = attributes[:'address_line_2']
115
+ end
116
+
117
+ if attributes[:'address_line_3']
118
+ self.address_line_3 = attributes[:'address_line_3']
119
+ end
120
+
121
+ if attributes[:'locality']
122
+ self.locality = attributes[:'locality']
123
+ end
124
+
125
+ if attributes[:'sublocality']
126
+ self.sublocality = attributes[:'sublocality']
127
+ end
128
+
129
+ if attributes[:'sublocality_2']
130
+ self.sublocality_2 = attributes[:'sublocality_2']
131
+ end
132
+
133
+ if attributes[:'sublocality_3']
134
+ self.sublocality_3 = attributes[:'sublocality_3']
135
+ end
136
+
137
+ if attributes[:'administrative_district_level_1']
138
+ self.administrative_district_level_1 = attributes[:'administrative_district_level_1']
139
+ end
140
+
141
+ if attributes[:'administrative_district_level_2']
142
+ self.administrative_district_level_2 = attributes[:'administrative_district_level_2']
143
+ end
144
+
145
+ if attributes[:'administrative_district_level_3']
146
+ self.administrative_district_level_3 = attributes[:'administrative_district_level_3']
147
+ end
148
+
149
+ if attributes[:'postal_code']
150
+ self.postal_code = attributes[:'postal_code']
151
+ end
152
+
153
+ if attributes[:'country']
154
+ self.country = attributes[:'country']
155
+ end
156
+
157
+ end
158
+
159
+ # Custom attribute writer method checking allowed values (enum).
160
+ def country=(country)
161
+ allowed_values = ["ZZ", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]
162
+ if country && !allowed_values.include?(country)
163
+ fail "invalid value for 'country', must be one of #{allowed_values}"
164
+ end
165
+ @country = country
166
+ end
167
+
168
+ # Check equality by comparing each attribute.
169
+ def ==(o)
170
+ return true if self.equal?(o)
171
+ self.class == o.class &&
172
+ address_line_1 == o.address_line_1 &&
173
+ address_line_2 == o.address_line_2 &&
174
+ address_line_3 == o.address_line_3 &&
175
+ locality == o.locality &&
176
+ sublocality == o.sublocality &&
177
+ sublocality_2 == o.sublocality_2 &&
178
+ sublocality_3 == o.sublocality_3 &&
179
+ administrative_district_level_1 == o.administrative_district_level_1 &&
180
+ administrative_district_level_2 == o.administrative_district_level_2 &&
181
+ administrative_district_level_3 == o.administrative_district_level_3 &&
182
+ postal_code == o.postal_code &&
183
+ country == o.country
184
+ end
185
+
186
+ # @see the `==` method
187
+ def eql?(o)
188
+ self == o
189
+ end
190
+
191
+ # Calculate hash code according to all attributes.
192
+ def hash
193
+ [address_line_1, address_line_2, address_line_3, locality, sublocality, sublocality_2, sublocality_3, administrative_district_level_1, administrative_district_level_2, administrative_district_level_3, postal_code, country].hash
194
+ end
195
+
196
+ # build the object from hash
197
+ def build_from_hash(attributes)
198
+ return nil unless attributes.is_a?(Hash)
199
+ self.class.swagger_types.each_pair do |key, type|
200
+ if type =~ /^Array<(.*)>/i
201
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
202
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
203
+ else
204
+ #TODO show warning in debug mode
205
+ end
206
+ elsif !attributes[self.class.attribute_map[key]].nil?
207
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
208
+ else
209
+ # data not found in attributes(hash), not an issue as the data can be optional
210
+ end
211
+ end
212
+
213
+ self
214
+ end
215
+
216
+ def _deserialize(type, value)
217
+ case type.to_sym
218
+ when :DateTime
219
+ DateTime.parse(value)
220
+ when :Date
221
+ Date.parse(value)
222
+ when :String
223
+ value.to_s
224
+ when :Integer
225
+ value.to_i
226
+ when :Float
227
+ value.to_f
228
+ when :BOOLEAN
229
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
230
+ true
231
+ else
232
+ false
233
+ end
234
+ when /\AArray<(?<inner_type>.+)>\z/
235
+ inner_type = Regexp.last_match[:inner_type]
236
+ value.map { |v| _deserialize(inner_type, v) }
237
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
238
+ k_type = Regexp.last_match[:k_type]
239
+ v_type = Regexp.last_match[:v_type]
240
+ {}.tap do |hash|
241
+ value.each do |k, v|
242
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
243
+ end
244
+ end
245
+ else # model
246
+ _model = SquareConnect.const_get(type).new
247
+ _model.build_from_hash(value)
248
+ end
249
+ end
250
+
251
+ def to_s
252
+ to_hash.to_s
253
+ end
254
+
255
+ # to_body is an alias to to_body (backward compatibility))
256
+ def to_body
257
+ to_hash
258
+ end
259
+
260
+ # return the object in the form of hash
261
+ def to_hash
262
+ hash = {}
263
+ self.class.attribute_map.each_pair do |attr, param|
264
+ value = self.send(attr)
265
+ next if value.nil?
266
+ hash[param] = _to_hash(value)
267
+ end
268
+ hash
269
+ end
270
+
271
+ # Method to output non-array value in the form of hash
272
+ # For object, use to_hash. Otherwise, just return the value
273
+ def _to_hash(value)
274
+ if value.is_a?(Array)
275
+ value.compact.map{ |v| _to_hash(v) }
276
+ elsif value.is_a?(Hash)
277
+ {}.tap do |hash|
278
+ value.each { |k, v| hash[k] = _to_hash(v) }
279
+ end
280
+ elsif value.respond_to? :to_hash
281
+ value.to_hash
282
+ else
283
+ value
284
+ end
285
+ end
286
+
287
+ end
288
+ end
@@ -0,0 +1,160 @@
1
+ =begin
2
+ Square Connect API
3
+
4
+ OpenAPI spec version: 2.0
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ require 'date'
12
+
13
+ module SquareConnect
14
+ # Defines the fields that are included in the response body of\na request to the **CaptureTransaction** endpoint.
15
+ class CaptureTransactionResponse
16
+ # Any errors that occurred during the request.
17
+ attr_accessor :errors
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+
23
+ :'errors' => :'errors'
24
+
25
+ }
26
+ end
27
+
28
+ # Attribute type mapping.
29
+ def self.swagger_types
30
+ {
31
+ :'errors' => :'Array<Error>'
32
+
33
+ }
34
+ end
35
+
36
+ def initialize(attributes = {})
37
+ return unless attributes.is_a?(Hash)
38
+
39
+ # convert string to symbol for hash key
40
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
41
+
42
+
43
+ if attributes[:'errors']
44
+ if (value = attributes[:'errors']).is_a?(Array)
45
+ self.errors = value
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ # Check equality by comparing each attribute.
52
+ def ==(o)
53
+ return true if self.equal?(o)
54
+ self.class == o.class &&
55
+ errors == o.errors
56
+ end
57
+
58
+ # @see the `==` method
59
+ def eql?(o)
60
+ self == o
61
+ end
62
+
63
+ # Calculate hash code according to all attributes.
64
+ def hash
65
+ [errors].hash
66
+ end
67
+
68
+ # build the object from hash
69
+ def build_from_hash(attributes)
70
+ return nil unless attributes.is_a?(Hash)
71
+ self.class.swagger_types.each_pair do |key, type|
72
+ if type =~ /^Array<(.*)>/i
73
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
74
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
75
+ else
76
+ #TODO show warning in debug mode
77
+ end
78
+ elsif !attributes[self.class.attribute_map[key]].nil?
79
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
80
+ else
81
+ # data not found in attributes(hash), not an issue as the data can be optional
82
+ end
83
+ end
84
+
85
+ self
86
+ end
87
+
88
+ def _deserialize(type, value)
89
+ case type.to_sym
90
+ when :DateTime
91
+ DateTime.parse(value)
92
+ when :Date
93
+ Date.parse(value)
94
+ when :String
95
+ value.to_s
96
+ when :Integer
97
+ value.to_i
98
+ when :Float
99
+ value.to_f
100
+ when :BOOLEAN
101
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
102
+ true
103
+ else
104
+ false
105
+ end
106
+ when /\AArray<(?<inner_type>.+)>\z/
107
+ inner_type = Regexp.last_match[:inner_type]
108
+ value.map { |v| _deserialize(inner_type, v) }
109
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
110
+ k_type = Regexp.last_match[:k_type]
111
+ v_type = Regexp.last_match[:v_type]
112
+ {}.tap do |hash|
113
+ value.each do |k, v|
114
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
115
+ end
116
+ end
117
+ else # model
118
+ _model = SquareConnect.const_get(type).new
119
+ _model.build_from_hash(value)
120
+ end
121
+ end
122
+
123
+ def to_s
124
+ to_hash.to_s
125
+ end
126
+
127
+ # to_body is an alias to to_body (backward compatibility))
128
+ def to_body
129
+ to_hash
130
+ end
131
+
132
+ # return the object in the form of hash
133
+ def to_hash
134
+ hash = {}
135
+ self.class.attribute_map.each_pair do |attr, param|
136
+ value = self.send(attr)
137
+ next if value.nil?
138
+ hash[param] = _to_hash(value)
139
+ end
140
+ hash
141
+ end
142
+
143
+ # Method to output non-array value in the form of hash
144
+ # For object, use to_hash. Otherwise, just return the value
145
+ def _to_hash(value)
146
+ if value.is_a?(Array)
147
+ value.compact.map{ |v| _to_hash(v) }
148
+ elsif value.is_a?(Hash)
149
+ {}.tap do |hash|
150
+ value.each { |k, v| hash[k] = _to_hash(v) }
151
+ end
152
+ elsif value.respond_to? :to_hash
153
+ value.to_hash
154
+ else
155
+ value
156
+ end
157
+ end
158
+
159
+ end
160
+ end
@@ -0,0 +1,233 @@
1
+ =begin
2
+ Square Connect API
3
+
4
+ OpenAPI spec version: 2.0
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ require 'date'
12
+
13
+ module SquareConnect
14
+ # Represents a credit card.
15
+ class Card
16
+ # The card's unique ID, if any.
17
+ attr_accessor :id
18
+
19
+ # The card's brand (such as `VISA`).
20
+ attr_accessor :card_brand
21
+
22
+ # The last 4 digits of the card's number.
23
+ attr_accessor :last_4
24
+
25
+ # The month of the card's expiration date, which must be between 1-12.
26
+ attr_accessor :exp_month
27
+
28
+ # The year of the card's expiration date, which must be a 4-digit year.
29
+ attr_accessor :exp_year
30
+
31
+ # The cardholder name for the card on file.
32
+ attr_accessor :cardholder_name
33
+
34
+ # The billing address for the card on file.
35
+ attr_accessor :billing_address
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+
41
+ :'id' => :'id',
42
+
43
+ :'card_brand' => :'card_brand',
44
+
45
+ :'last_4' => :'last_4',
46
+
47
+ :'exp_month' => :'exp_month',
48
+
49
+ :'exp_year' => :'exp_year',
50
+
51
+ :'cardholder_name' => :'cardholder_name',
52
+
53
+ :'billing_address' => :'billing_address'
54
+
55
+ }
56
+ end
57
+
58
+ # Attribute type mapping.
59
+ def self.swagger_types
60
+ {
61
+ :'id' => :'String',
62
+ :'card_brand' => :'String',
63
+ :'last_4' => :'String',
64
+ :'exp_month' => :'Integer',
65
+ :'exp_year' => :'Integer',
66
+ :'cardholder_name' => :'String',
67
+ :'billing_address' => :'Address'
68
+
69
+ }
70
+ end
71
+
72
+ def initialize(attributes = {})
73
+ return unless attributes.is_a?(Hash)
74
+
75
+ # convert string to symbol for hash key
76
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
77
+
78
+
79
+ if attributes[:'id']
80
+ self.id = attributes[:'id']
81
+ end
82
+
83
+ if attributes[:'card_brand']
84
+ self.card_brand = attributes[:'card_brand']
85
+ end
86
+
87
+ if attributes[:'last_4']
88
+ self.last_4 = attributes[:'last_4']
89
+ end
90
+
91
+ if attributes[:'exp_month']
92
+ self.exp_month = attributes[:'exp_month']
93
+ end
94
+
95
+ if attributes[:'exp_year']
96
+ self.exp_year = attributes[:'exp_year']
97
+ end
98
+
99
+ if attributes[:'cardholder_name']
100
+ self.cardholder_name = attributes[:'cardholder_name']
101
+ end
102
+
103
+ if attributes[:'billing_address']
104
+ self.billing_address = attributes[:'billing_address']
105
+ end
106
+
107
+ end
108
+
109
+ # Custom attribute writer method checking allowed values (enum).
110
+ def card_brand=(card_brand)
111
+ allowed_values = ["OTHER_BRAND", "VISA", "MASTERCARD", "AMERICAN_EXPRESS", "DISCOVER", "DISCOVER_DINERS", "JCB", "CHINA_UNIONPAY", "SQUARE_GIFT_CARD"]
112
+ if card_brand && !allowed_values.include?(card_brand)
113
+ fail "invalid value for 'card_brand', must be one of #{allowed_values}"
114
+ end
115
+ @card_brand = card_brand
116
+ end
117
+
118
+ # Check equality by comparing each attribute.
119
+ def ==(o)
120
+ return true if self.equal?(o)
121
+ self.class == o.class &&
122
+ id == o.id &&
123
+ card_brand == o.card_brand &&
124
+ last_4 == o.last_4 &&
125
+ exp_month == o.exp_month &&
126
+ exp_year == o.exp_year &&
127
+ cardholder_name == o.cardholder_name &&
128
+ billing_address == o.billing_address
129
+ end
130
+
131
+ # @see the `==` method
132
+ def eql?(o)
133
+ self == o
134
+ end
135
+
136
+ # Calculate hash code according to all attributes.
137
+ def hash
138
+ [id, card_brand, last_4, exp_month, exp_year, cardholder_name, billing_address].hash
139
+ end
140
+
141
+ # build the object from hash
142
+ def build_from_hash(attributes)
143
+ return nil unless attributes.is_a?(Hash)
144
+ self.class.swagger_types.each_pair do |key, type|
145
+ if type =~ /^Array<(.*)>/i
146
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
147
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
148
+ else
149
+ #TODO show warning in debug mode
150
+ end
151
+ elsif !attributes[self.class.attribute_map[key]].nil?
152
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
153
+ else
154
+ # data not found in attributes(hash), not an issue as the data can be optional
155
+ end
156
+ end
157
+
158
+ self
159
+ end
160
+
161
+ def _deserialize(type, value)
162
+ case type.to_sym
163
+ when :DateTime
164
+ DateTime.parse(value)
165
+ when :Date
166
+ Date.parse(value)
167
+ when :String
168
+ value.to_s
169
+ when :Integer
170
+ value.to_i
171
+ when :Float
172
+ value.to_f
173
+ when :BOOLEAN
174
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
175
+ true
176
+ else
177
+ false
178
+ end
179
+ when /\AArray<(?<inner_type>.+)>\z/
180
+ inner_type = Regexp.last_match[:inner_type]
181
+ value.map { |v| _deserialize(inner_type, v) }
182
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
183
+ k_type = Regexp.last_match[:k_type]
184
+ v_type = Regexp.last_match[:v_type]
185
+ {}.tap do |hash|
186
+ value.each do |k, v|
187
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
188
+ end
189
+ end
190
+ else # model
191
+ _model = SquareConnect.const_get(type).new
192
+ _model.build_from_hash(value)
193
+ end
194
+ end
195
+
196
+ def to_s
197
+ to_hash.to_s
198
+ end
199
+
200
+ # to_body is an alias to to_body (backward compatibility))
201
+ def to_body
202
+ to_hash
203
+ end
204
+
205
+ # return the object in the form of hash
206
+ def to_hash
207
+ hash = {}
208
+ self.class.attribute_map.each_pair do |attr, param|
209
+ value = self.send(attr)
210
+ next if value.nil?
211
+ hash[param] = _to_hash(value)
212
+ end
213
+ hash
214
+ end
215
+
216
+ # Method to output non-array value in the form of hash
217
+ # For object, use to_hash. Otherwise, just return the value
218
+ def _to_hash(value)
219
+ if value.is_a?(Array)
220
+ value.compact.map{ |v| _to_hash(v) }
221
+ elsif value.is_a?(Hash)
222
+ {}.tap do |hash|
223
+ value.each { |k, v| hash[k] = _to_hash(v) }
224
+ end
225
+ elsif value.respond_to? :to_hash
226
+ value.to_hash
227
+ else
228
+ value
229
+ end
230
+ end
231
+
232
+ end
233
+ end