zip_money 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +69 -0
- data/README.md +128 -0
- data/Rakefile +8 -0
- data/docs/Address.md +15 -0
- data/docs/Authority.md +9 -0
- data/docs/CaptureChargeRequest.md +8 -0
- data/docs/Charge.md +17 -0
- data/docs/ChargeCollection.md +8 -0
- data/docs/ChargeOrder.md +11 -0
- data/docs/ChargesApi.md +307 -0
- data/docs/Checkout.md +18 -0
- data/docs/CheckoutConfiguration.md +8 -0
- data/docs/CheckoutFeatures.md +8 -0
- data/docs/CheckoutFeaturesTokenisation.md +8 -0
- data/docs/CheckoutOrder.md +13 -0
- data/docs/CheckoutsApi.md +119 -0
- data/docs/CreateChargeRequest.md +14 -0
- data/docs/CreateCheckoutRequest.md +13 -0
- data/docs/CreateCheckoutRequestFeatures.md +8 -0
- data/docs/CreateCheckoutRequestFeaturesTokenisation.md +8 -0
- data/docs/CreateRefundRequest.md +11 -0
- data/docs/CreateTokenRequest.md +8 -0
- data/docs/Customer.md +15 -0
- data/docs/CustomersApi.md +96 -0
- data/docs/ErrorResponse.md +8 -0
- data/docs/ErrorResponseError.md +10 -0
- data/docs/ErrorResponseErrorDetails.md +9 -0
- data/docs/InlineResponse200.md +8 -0
- data/docs/Metadata.md +7 -0
- data/docs/OrderItem.md +16 -0
- data/docs/OrderShipping.md +10 -0
- data/docs/OrderShippingTracking.md +10 -0
- data/docs/Refund.md +13 -0
- data/docs/RefundsApi.md +181 -0
- data/docs/SettlementsApi.md +96 -0
- data/docs/Shopper.md +17 -0
- data/docs/ShopperStatistics.md +16 -0
- data/docs/Token.md +11 -0
- data/docs/TokensApi.md +66 -0
- data/lib/zip_money.rb +68 -0
- data/lib/zip_money/api/charges_api.rb +301 -0
- data/lib/zip_money/api/checkouts_api.rb +120 -0
- data/lib/zip_money/api/customers_api.rb +116 -0
- data/lib/zip_money/api/refunds_api.rb +181 -0
- data/lib/zip_money/api/settlements_api.rb +116 -0
- data/lib/zip_money/api/tokens_api.rb +70 -0
- data/lib/zip_money/api_client.rb +386 -0
- data/lib/zip_money/api_error.rb +31 -0
- data/lib/zip_money/configuration.rb +238 -0
- data/lib/zip_money/models/address.rb +413 -0
- data/lib/zip_money/models/authority.rb +235 -0
- data/lib/zip_money/models/capture_charge_request.rb +206 -0
- data/lib/zip_money/models/charge.rb +369 -0
- data/lib/zip_money/models/charge_collection.rb +188 -0
- data/lib/zip_money/models/charge_order.rb +250 -0
- data/lib/zip_money/models/checkout.rb +344 -0
- data/lib/zip_money/models/checkout_configuration.rb +187 -0
- data/lib/zip_money/models/checkout_features.rb +181 -0
- data/lib/zip_money/models/checkout_features_tokenisation.rb +184 -0
- data/lib/zip_money/models/checkout_order.rb +299 -0
- data/lib/zip_money/models/create_charge_request.rb +289 -0
- data/lib/zip_money/models/create_checkout_request.rb +272 -0
- data/lib/zip_money/models/create_checkout_request_features.rb +181 -0
- data/lib/zip_money/models/create_checkout_request_features_tokenisation.rb +189 -0
- data/lib/zip_money/models/create_refund_request.rb +246 -0
- data/lib/zip_money/models/create_token_request.rb +186 -0
- data/lib/zip_money/models/customer.rb +310 -0
- data/lib/zip_money/models/error_response.rb +181 -0
- data/lib/zip_money/models/error_response_error.rb +211 -0
- data/lib/zip_money/models/error_response_error_details.rb +190 -0
- data/lib/zip_money/models/inline_response_200.rb +188 -0
- data/lib/zip_money/models/metadata.rb +172 -0
- data/lib/zip_money/models/order_item.rb +333 -0
- data/lib/zip_money/models/order_shipping.rb +200 -0
- data/lib/zip_money/models/order_shipping_tracking.rb +247 -0
- data/lib/zip_money/models/refund.rb +252 -0
- data/lib/zip_money/models/shopper.rb +339 -0
- data/lib/zip_money/models/shopper_statistics.rb +295 -0
- data/lib/zip_money/models/token.rb +228 -0
- data/lib/zip_money/version.rb +8 -0
- data/spec/api/charges_api_spec.rb +114 -0
- data/spec/api/checkouts_api_spec.rb +54 -0
- data/spec/api/customers_api_spec.rb +51 -0
- data/spec/api/refunds_api_spec.rb +67 -0
- data/spec/api/settlements_api_spec.rb +51 -0
- data/spec/api/tokens_api_spec.rb +41 -0
- data/spec/api_client_spec.rb +219 -0
- data/spec/configuration_spec.rb +50 -0
- data/spec/models/address_spec.rb +77 -0
- data/spec/models/authority_spec.rb +45 -0
- data/spec/models/capture_charge_request_spec.rb +35 -0
- data/spec/models/charge_collection_spec.rb +35 -0
- data/spec/models/charge_order_spec.rb +53 -0
- data/spec/models/charge_spec.rb +93 -0
- data/spec/models/checkout_configuration_spec.rb +35 -0
- data/spec/models/checkout_features_spec.rb +35 -0
- data/spec/models/checkout_features_tokenisation_spec.rb +35 -0
- data/spec/models/checkout_order_spec.rb +65 -0
- data/spec/models/checkout_spec.rb +103 -0
- data/spec/models/create_charge_request_spec.rb +75 -0
- data/spec/models/create_checkout_request_features_spec.rb +35 -0
- data/spec/models/create_checkout_request_features_tokenisation_spec.rb +35 -0
- data/spec/models/create_checkout_request_spec.rb +69 -0
- data/spec/models/create_refund_request_spec.rb +53 -0
- data/spec/models/create_token_request_spec.rb +35 -0
- data/spec/models/customer_spec.rb +81 -0
- data/spec/models/error_response_error_details_spec.rb +41 -0
- data/spec/models/error_response_error_spec.rb +47 -0
- data/spec/models/error_response_spec.rb +35 -0
- data/spec/models/inline_response_200_spec.rb +35 -0
- data/spec/models/metadata_spec.rb +29 -0
- data/spec/models/order_item_spec.rb +87 -0
- data/spec/models/order_shipping_spec.rb +47 -0
- data/spec/models/order_shipping_tracking_spec.rb +47 -0
- data/spec/models/refund_spec.rb +65 -0
- data/spec/models/shopper_spec.rb +92 -0
- data/spec/models/shopper_statistics_spec.rb +86 -0
- data/spec/models/token_spec.rb +52 -0
- data/spec/payload_helper.rb +96 -0
- data/spec/spec_helper.rb +104 -0
- data/zip_money.gemspec +38 -0
- metadata +380 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
#Merchant API
|
2
|
+
#ZipMoney Merchant API Initial build
|
3
|
+
#zipMoney Merchant API version: 2017-03-01
|
4
|
+
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
module ZipMoney
|
9
|
+
|
10
|
+
class Authority
|
11
|
+
# The type of authority (checkout_id, account_token, store_code)
|
12
|
+
attr_accessor :type
|
13
|
+
|
14
|
+
# The authority value/token
|
15
|
+
attr_accessor :value
|
16
|
+
|
17
|
+
class EnumAttributeValidator
|
18
|
+
attr_reader :datatype
|
19
|
+
attr_reader :allowable_values
|
20
|
+
|
21
|
+
def initialize(datatype, allowable_values)
|
22
|
+
@allowable_values = allowable_values.map do |value|
|
23
|
+
case datatype.to_s
|
24
|
+
when /Integer/i
|
25
|
+
value.to_i
|
26
|
+
when /Float/i
|
27
|
+
value.to_f
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid?(value)
|
35
|
+
!value || allowable_values.include?(value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
40
|
+
def self.attribute_map
|
41
|
+
{
|
42
|
+
:'type' => :'type',
|
43
|
+
:'value' => :'value'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Attribute type mapping.
|
48
|
+
def self.zip_types
|
49
|
+
{
|
50
|
+
:'type' => :'String',
|
51
|
+
:'value' => :'String'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# Initializes the object
|
56
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
57
|
+
def initialize(attributes = {})
|
58
|
+
return unless attributes.is_a?(Hash)
|
59
|
+
|
60
|
+
# convert string to symbol for hash key
|
61
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
62
|
+
|
63
|
+
if attributes.has_key?(:'type')
|
64
|
+
self.type = attributes[:'type']
|
65
|
+
end
|
66
|
+
|
67
|
+
if attributes.has_key?(:'value')
|
68
|
+
self.value = attributes[:'value']
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
74
|
+
# @return Array for valid properies with the reasons
|
75
|
+
def list_invalid_properties
|
76
|
+
invalid_properties = Array.new
|
77
|
+
if @type.nil?
|
78
|
+
invalid_properties.push("invalid value for 'type', type cannot be nil.")
|
79
|
+
end
|
80
|
+
|
81
|
+
if @value.nil?
|
82
|
+
invalid_properties.push("invalid value for 'value', value cannot be nil.")
|
83
|
+
end
|
84
|
+
|
85
|
+
return invalid_properties
|
86
|
+
end
|
87
|
+
|
88
|
+
# Check to see if the all the properties in the model are valid
|
89
|
+
# @return true if the model is valid
|
90
|
+
def valid?
|
91
|
+
return false if @type.nil?
|
92
|
+
type_validator = EnumAttributeValidator.new('String', ["checkout_id", "store_code", "account_token"])
|
93
|
+
return false unless type_validator.valid?(@type)
|
94
|
+
return false if @value.nil?
|
95
|
+
return true
|
96
|
+
end
|
97
|
+
|
98
|
+
# Custom attribute writer method checking allowed values (enum).
|
99
|
+
# @param [Object] type Object to be assigned
|
100
|
+
def type=(type)
|
101
|
+
validator = EnumAttributeValidator.new('String', ["checkout_id", "store_code", "account_token"])
|
102
|
+
unless validator.valid?(type)
|
103
|
+
fail ArgumentError, "invalid value for 'type', must be one of #{validator.allowable_values}."
|
104
|
+
end
|
105
|
+
@type = type
|
106
|
+
end
|
107
|
+
|
108
|
+
# Checks equality by comparing each attribute.
|
109
|
+
# @param [Object] Object to be compared
|
110
|
+
def ==(o)
|
111
|
+
return true if self.equal?(o)
|
112
|
+
self.class == o.class &&
|
113
|
+
type == o.type &&
|
114
|
+
value == o.value
|
115
|
+
end
|
116
|
+
|
117
|
+
# @see the `==` method
|
118
|
+
# @param [Object] Object to be compared
|
119
|
+
def eql?(o)
|
120
|
+
self == o
|
121
|
+
end
|
122
|
+
|
123
|
+
# Calculates hash code according to all attributes.
|
124
|
+
# @return [Fixnum] Hash code
|
125
|
+
def hash
|
126
|
+
[type, value].hash
|
127
|
+
end
|
128
|
+
|
129
|
+
# Builds the object from hash
|
130
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
131
|
+
# @return [Object] Returns the model itself
|
132
|
+
def build_from_hash(attributes)
|
133
|
+
return nil unless attributes.is_a?(Hash)
|
134
|
+
self.class.zip_types.each_pair do |key, type|
|
135
|
+
if type =~ /\AArray<(.*)>/i
|
136
|
+
# check to ensure the input is an array given that the the attribute
|
137
|
+
# is documented as an array but the input is not
|
138
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
139
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
140
|
+
end
|
141
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
142
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
143
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
144
|
+
end
|
145
|
+
|
146
|
+
self
|
147
|
+
end
|
148
|
+
|
149
|
+
# Deserializes the data based on type
|
150
|
+
# @param string type Data type
|
151
|
+
# @param string value Value to be deserialized
|
152
|
+
# @return [Object] Deserialized data
|
153
|
+
def _deserialize(type, value)
|
154
|
+
case type.to_sym
|
155
|
+
when :DateTime
|
156
|
+
DateTime.parse(value)
|
157
|
+
when :Date
|
158
|
+
Date.parse(value)
|
159
|
+
when :String
|
160
|
+
value.to_s
|
161
|
+
when :Integer
|
162
|
+
value.to_i
|
163
|
+
when :Float
|
164
|
+
value.to_f
|
165
|
+
when :BOOLEAN
|
166
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
167
|
+
true
|
168
|
+
else
|
169
|
+
false
|
170
|
+
end
|
171
|
+
when :Object
|
172
|
+
# generic object (usually a Hash), return directly
|
173
|
+
value
|
174
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
175
|
+
inner_type = Regexp.last_match[:inner_type]
|
176
|
+
value.map { |v| _deserialize(inner_type, v) }
|
177
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
178
|
+
k_type = Regexp.last_match[:k_type]
|
179
|
+
v_type = Regexp.last_match[:v_type]
|
180
|
+
{}.tap do |hash|
|
181
|
+
value.each do |k, v|
|
182
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
else # model
|
186
|
+
temp_model = ZipMoney.const_get(type).new
|
187
|
+
temp_model.build_from_hash(value)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Returns the string representation of the object
|
192
|
+
# @return [String] String presentation of the object
|
193
|
+
def to_s
|
194
|
+
to_hash.to_s
|
195
|
+
end
|
196
|
+
|
197
|
+
# to_body is an alias to to_hash (backward compatibility)
|
198
|
+
# @return [Hash] Returns the object in the form of hash
|
199
|
+
def to_body
|
200
|
+
to_hash
|
201
|
+
end
|
202
|
+
|
203
|
+
# Returns the object in the form of hash
|
204
|
+
# @return [Hash] Returns the object in the form of hash
|
205
|
+
def to_hash
|
206
|
+
hash = {}
|
207
|
+
self.class.attribute_map.each_pair do |attr, param|
|
208
|
+
value = self.send(attr)
|
209
|
+
next if value.nil?
|
210
|
+
hash[param] = _to_hash(value)
|
211
|
+
end
|
212
|
+
hash
|
213
|
+
end
|
214
|
+
|
215
|
+
# Outputs non-array value in the form of hash
|
216
|
+
# For object, use to_hash. Otherwise, just return the value
|
217
|
+
# @param [Object] value Any valid value
|
218
|
+
# @return [Hash] Returns the value in the form of hash
|
219
|
+
def _to_hash(value)
|
220
|
+
if value.is_a?(Array)
|
221
|
+
value.compact.map{ |v| _to_hash(v) }
|
222
|
+
elsif value.is_a?(Hash)
|
223
|
+
{}.tap do |hash|
|
224
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
225
|
+
end
|
226
|
+
elsif value.respond_to? :to_hash
|
227
|
+
value.to_hash
|
228
|
+
else
|
229
|
+
value
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
#Merchant API
|
2
|
+
#ZipMoney Merchant API Initial build
|
3
|
+
#zipMoney Merchant API version: 2017-03-01
|
4
|
+
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
module ZipMoney
|
9
|
+
|
10
|
+
class CaptureChargeRequest
|
11
|
+
# Amount can be less than or equal to the previously authorised amount
|
12
|
+
attr_accessor :amount
|
13
|
+
|
14
|
+
|
15
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
16
|
+
def self.attribute_map
|
17
|
+
{
|
18
|
+
:'amount' => :'amount'
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# Attribute type mapping.
|
23
|
+
def self.zip_types
|
24
|
+
{
|
25
|
+
:'amount' => :'Float'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Initializes the object
|
30
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
31
|
+
def initialize(attributes = {})
|
32
|
+
return unless attributes.is_a?(Hash)
|
33
|
+
|
34
|
+
# convert string to symbol for hash key
|
35
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
36
|
+
|
37
|
+
if attributes.has_key?(:'amount')
|
38
|
+
self.amount = attributes[:'amount']
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
44
|
+
# @return Array for valid properies with the reasons
|
45
|
+
def list_invalid_properties
|
46
|
+
invalid_properties = Array.new
|
47
|
+
if @amount.nil?
|
48
|
+
invalid_properties.push("invalid value for 'amount', amount cannot be nil.")
|
49
|
+
end
|
50
|
+
|
51
|
+
if @amount < 0
|
52
|
+
invalid_properties.push("invalid value for 'amount', must be greater than or equal to 0.")
|
53
|
+
end
|
54
|
+
|
55
|
+
return invalid_properties
|
56
|
+
end
|
57
|
+
|
58
|
+
# Check to see if the all the properties in the model are valid
|
59
|
+
# @return true if the model is valid
|
60
|
+
def valid?
|
61
|
+
return false if @amount.nil?
|
62
|
+
return false if @amount < 0
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
|
66
|
+
# Custom attribute writer method with validation
|
67
|
+
# @param [Object] amount Value to be assigned
|
68
|
+
def amount=(amount)
|
69
|
+
if amount.nil?
|
70
|
+
fail ArgumentError, "amount cannot be nil"
|
71
|
+
end
|
72
|
+
|
73
|
+
if amount < 0
|
74
|
+
fail ArgumentError, "invalid value for 'amount', must be greater than or equal to 0."
|
75
|
+
end
|
76
|
+
|
77
|
+
@amount = amount
|
78
|
+
end
|
79
|
+
|
80
|
+
# Checks equality by comparing each attribute.
|
81
|
+
# @param [Object] Object to be compared
|
82
|
+
def ==(o)
|
83
|
+
return true if self.equal?(o)
|
84
|
+
self.class == o.class &&
|
85
|
+
amount == o.amount
|
86
|
+
end
|
87
|
+
|
88
|
+
# @see the `==` method
|
89
|
+
# @param [Object] Object to be compared
|
90
|
+
def eql?(o)
|
91
|
+
self == o
|
92
|
+
end
|
93
|
+
|
94
|
+
# Calculates hash code according to all attributes.
|
95
|
+
# @return [Fixnum] Hash code
|
96
|
+
def hash
|
97
|
+
[amount].hash
|
98
|
+
end
|
99
|
+
|
100
|
+
# Builds the object from hash
|
101
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
102
|
+
# @return [Object] Returns the model itself
|
103
|
+
def build_from_hash(attributes)
|
104
|
+
return nil unless attributes.is_a?(Hash)
|
105
|
+
self.class.zip_types.each_pair do |key, type|
|
106
|
+
if type =~ /\AArray<(.*)>/i
|
107
|
+
# check to ensure the input is an array given that the the attribute
|
108
|
+
# is documented as an array but the input is not
|
109
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
110
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
111
|
+
end
|
112
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
113
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
114
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
115
|
+
end
|
116
|
+
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
# Deserializes the data based on type
|
121
|
+
# @param string type Data type
|
122
|
+
# @param string value Value to be deserialized
|
123
|
+
# @return [Object] Deserialized data
|
124
|
+
def _deserialize(type, value)
|
125
|
+
case type.to_sym
|
126
|
+
when :DateTime
|
127
|
+
DateTime.parse(value)
|
128
|
+
when :Date
|
129
|
+
Date.parse(value)
|
130
|
+
when :String
|
131
|
+
value.to_s
|
132
|
+
when :Integer
|
133
|
+
value.to_i
|
134
|
+
when :Float
|
135
|
+
value.to_f
|
136
|
+
when :BOOLEAN
|
137
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
138
|
+
true
|
139
|
+
else
|
140
|
+
false
|
141
|
+
end
|
142
|
+
when :Object
|
143
|
+
# generic object (usually a Hash), return directly
|
144
|
+
value
|
145
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
146
|
+
inner_type = Regexp.last_match[:inner_type]
|
147
|
+
value.map { |v| _deserialize(inner_type, v) }
|
148
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
149
|
+
k_type = Regexp.last_match[:k_type]
|
150
|
+
v_type = Regexp.last_match[:v_type]
|
151
|
+
{}.tap do |hash|
|
152
|
+
value.each do |k, v|
|
153
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
else # model
|
157
|
+
temp_model = ZipMoney.const_get(type).new
|
158
|
+
temp_model.build_from_hash(value)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns the string representation of the object
|
163
|
+
# @return [String] String presentation of the object
|
164
|
+
def to_s
|
165
|
+
to_hash.to_s
|
166
|
+
end
|
167
|
+
|
168
|
+
# to_body is an alias to to_hash (backward compatibility)
|
169
|
+
# @return [Hash] Returns the object in the form of hash
|
170
|
+
def to_body
|
171
|
+
to_hash
|
172
|
+
end
|
173
|
+
|
174
|
+
# Returns the object in the form of hash
|
175
|
+
# @return [Hash] Returns the object in the form of hash
|
176
|
+
def to_hash
|
177
|
+
hash = {}
|
178
|
+
self.class.attribute_map.each_pair do |attr, param|
|
179
|
+
value = self.send(attr)
|
180
|
+
next if value.nil?
|
181
|
+
hash[param] = _to_hash(value)
|
182
|
+
end
|
183
|
+
hash
|
184
|
+
end
|
185
|
+
|
186
|
+
# Outputs non-array value in the form of hash
|
187
|
+
# For object, use to_hash. Otherwise, just return the value
|
188
|
+
# @param [Object] value Any valid value
|
189
|
+
# @return [Hash] Returns the value in the form of hash
|
190
|
+
def _to_hash(value)
|
191
|
+
if value.is_a?(Array)
|
192
|
+
value.compact.map{ |v| _to_hash(v) }
|
193
|
+
elsif value.is_a?(Hash)
|
194
|
+
{}.tap do |hash|
|
195
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
196
|
+
end
|
197
|
+
elsif value.respond_to? :to_hash
|
198
|
+
value.to_hash
|
199
|
+
else
|
200
|
+
value
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
@@ -0,0 +1,369 @@
|
|
1
|
+
#Merchant API
|
2
|
+
#ZipMoney Merchant API Initial build
|
3
|
+
#zipMoney Merchant API version: 2017-03-01
|
4
|
+
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
module ZipMoney
|
9
|
+
|
10
|
+
class Charge
|
11
|
+
attr_accessor :id
|
12
|
+
|
13
|
+
attr_accessor :reference
|
14
|
+
|
15
|
+
attr_accessor :amount
|
16
|
+
|
17
|
+
attr_accessor :currency
|
18
|
+
|
19
|
+
attr_accessor :state
|
20
|
+
|
21
|
+
attr_accessor :captured_amount
|
22
|
+
|
23
|
+
# The amount of the charge that has been refunded
|
24
|
+
attr_accessor :refunded_amount
|
25
|
+
|
26
|
+
attr_accessor :created_date
|
27
|
+
|
28
|
+
attr_accessor :order
|
29
|
+
|
30
|
+
attr_accessor :metadata
|
31
|
+
|
32
|
+
class EnumAttributeValidator
|
33
|
+
attr_reader :datatype
|
34
|
+
attr_reader :allowable_values
|
35
|
+
|
36
|
+
def initialize(datatype, allowable_values)
|
37
|
+
@allowable_values = allowable_values.map do |value|
|
38
|
+
case datatype.to_s
|
39
|
+
when /Integer/i
|
40
|
+
value.to_i
|
41
|
+
when /Float/i
|
42
|
+
value.to_f
|
43
|
+
else
|
44
|
+
value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid?(value)
|
50
|
+
!value || allowable_values.include?(value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
55
|
+
def self.attribute_map
|
56
|
+
{
|
57
|
+
:'id' => :'id',
|
58
|
+
:'reference' => :'reference',
|
59
|
+
:'amount' => :'amount',
|
60
|
+
:'currency' => :'currency',
|
61
|
+
:'state' => :'state',
|
62
|
+
:'captured_amount' => :'captured_amount',
|
63
|
+
:'refunded_amount' => :'refunded_amount',
|
64
|
+
:'created_date' => :'created_date',
|
65
|
+
:'order' => :'order',
|
66
|
+
:'metadata' => :'metadata'
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
# Attribute type mapping.
|
71
|
+
def self.zip_types
|
72
|
+
{
|
73
|
+
:'id' => :'String',
|
74
|
+
:'reference' => :'String',
|
75
|
+
:'amount' => :'Float',
|
76
|
+
:'currency' => :'String',
|
77
|
+
:'state' => :'String',
|
78
|
+
:'captured_amount' => :'Float',
|
79
|
+
:'refunded_amount' => :'Float',
|
80
|
+
:'created_date' => :'DateTime',
|
81
|
+
:'order' => :'ChargeOrder',
|
82
|
+
:'metadata' => :'Object'
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
# Initializes the object
|
87
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
88
|
+
def initialize(attributes = {})
|
89
|
+
return unless attributes.is_a?(Hash)
|
90
|
+
|
91
|
+
# convert string to symbol for hash key
|
92
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
93
|
+
|
94
|
+
if attributes.has_key?(:'id')
|
95
|
+
self.id = attributes[:'id']
|
96
|
+
end
|
97
|
+
|
98
|
+
if attributes.has_key?(:'reference')
|
99
|
+
self.reference = attributes[:'reference']
|
100
|
+
end
|
101
|
+
|
102
|
+
if attributes.has_key?(:'amount')
|
103
|
+
self.amount = attributes[:'amount']
|
104
|
+
end
|
105
|
+
|
106
|
+
if attributes.has_key?(:'currency')
|
107
|
+
self.currency = attributes[:'currency']
|
108
|
+
end
|
109
|
+
|
110
|
+
if attributes.has_key?(:'state')
|
111
|
+
self.state = attributes[:'state']
|
112
|
+
end
|
113
|
+
|
114
|
+
if attributes.has_key?(:'captured_amount')
|
115
|
+
self.captured_amount = attributes[:'captured_amount']
|
116
|
+
end
|
117
|
+
|
118
|
+
if attributes.has_key?(:'refunded_amount')
|
119
|
+
self.refunded_amount = attributes[:'refunded_amount']
|
120
|
+
end
|
121
|
+
|
122
|
+
if attributes.has_key?(:'created_date')
|
123
|
+
self.created_date = attributes[:'created_date']
|
124
|
+
end
|
125
|
+
|
126
|
+
if attributes.has_key?(:'order')
|
127
|
+
self.order = attributes[:'order']
|
128
|
+
end
|
129
|
+
|
130
|
+
if attributes.has_key?(:'metadata')
|
131
|
+
self.metadata = attributes[:'metadata']
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
137
|
+
# @return Array for valid properies with the reasons
|
138
|
+
def list_invalid_properties
|
139
|
+
invalid_properties = Array.new
|
140
|
+
if @id.nil?
|
141
|
+
invalid_properties.push("invalid value for 'id', id cannot be nil.")
|
142
|
+
end
|
143
|
+
|
144
|
+
if @amount.nil?
|
145
|
+
invalid_properties.push("invalid value for 'amount', amount cannot be nil.")
|
146
|
+
end
|
147
|
+
|
148
|
+
if @currency.nil?
|
149
|
+
invalid_properties.push("invalid value for 'currency', currency cannot be nil.")
|
150
|
+
end
|
151
|
+
|
152
|
+
if @state.nil?
|
153
|
+
invalid_properties.push("invalid value for 'state', state cannot be nil.")
|
154
|
+
end
|
155
|
+
|
156
|
+
if @captured_amount.nil?
|
157
|
+
invalid_properties.push("invalid value for 'captured_amount', captured_amount cannot be nil.")
|
158
|
+
end
|
159
|
+
|
160
|
+
if @captured_amount < 0
|
161
|
+
invalid_properties.push("invalid value for 'captured_amount', must be greater than or equal to 0.")
|
162
|
+
end
|
163
|
+
|
164
|
+
if @refunded_amount.nil?
|
165
|
+
invalid_properties.push("invalid value for 'refunded_amount', refunded_amount cannot be nil.")
|
166
|
+
end
|
167
|
+
|
168
|
+
if @refunded_amount < 0
|
169
|
+
invalid_properties.push("invalid value for 'refunded_amount', must be greater than or equal to 0.")
|
170
|
+
end
|
171
|
+
|
172
|
+
if @created_date.nil?
|
173
|
+
invalid_properties.push("invalid value for 'created_date', created_date cannot be nil.")
|
174
|
+
end
|
175
|
+
|
176
|
+
return invalid_properties
|
177
|
+
end
|
178
|
+
|
179
|
+
# Check to see if the all the properties in the model are valid
|
180
|
+
# @return true if the model is valid
|
181
|
+
def valid?
|
182
|
+
return false if @id.nil?
|
183
|
+
return false if @amount.nil?
|
184
|
+
return false if @currency.nil?
|
185
|
+
return false if @state.nil?
|
186
|
+
state_validator = EnumAttributeValidator.new('String', ["authorised", "captured", "cancelled", "refunded"])
|
187
|
+
return false unless state_validator.valid?(@state)
|
188
|
+
return false if @captured_amount.nil?
|
189
|
+
return false if @captured_amount < 0
|
190
|
+
return false if @refunded_amount.nil?
|
191
|
+
return false if @refunded_amount < 0
|
192
|
+
return false if @created_date.nil?
|
193
|
+
return true
|
194
|
+
end
|
195
|
+
|
196
|
+
# Custom attribute writer method checking allowed values (enum).
|
197
|
+
# @param [Object] state Object to be assigned
|
198
|
+
def state=(state)
|
199
|
+
validator = EnumAttributeValidator.new('String', ["authorised", "captured", "cancelled", "refunded"])
|
200
|
+
unless validator.valid?(state)
|
201
|
+
fail ArgumentError, "invalid value for 'state', must be one of #{validator.allowable_values}."
|
202
|
+
end
|
203
|
+
@state = state
|
204
|
+
end
|
205
|
+
|
206
|
+
# Custom attribute writer method with validation
|
207
|
+
# @param [Object] captured_amount Value to be assigned
|
208
|
+
def captured_amount=(captured_amount)
|
209
|
+
if captured_amount.nil?
|
210
|
+
fail ArgumentError, "captured_amount cannot be nil"
|
211
|
+
end
|
212
|
+
|
213
|
+
if captured_amount < 0
|
214
|
+
fail ArgumentError, "invalid value for 'captured_amount', must be greater than or equal to 0."
|
215
|
+
end
|
216
|
+
|
217
|
+
@captured_amount = captured_amount
|
218
|
+
end
|
219
|
+
|
220
|
+
# Custom attribute writer method with validation
|
221
|
+
# @param [Object] refunded_amount Value to be assigned
|
222
|
+
def refunded_amount=(refunded_amount)
|
223
|
+
if refunded_amount.nil?
|
224
|
+
fail ArgumentError, "refunded_amount cannot be nil"
|
225
|
+
end
|
226
|
+
|
227
|
+
if refunded_amount < 0
|
228
|
+
fail ArgumentError, "invalid value for 'refunded_amount', must be greater than or equal to 0."
|
229
|
+
end
|
230
|
+
|
231
|
+
@refunded_amount = refunded_amount
|
232
|
+
end
|
233
|
+
|
234
|
+
# Checks equality by comparing each attribute.
|
235
|
+
# @param [Object] Object to be compared
|
236
|
+
def ==(o)
|
237
|
+
return true if self.equal?(o)
|
238
|
+
self.class == o.class &&
|
239
|
+
id == o.id &&
|
240
|
+
reference == o.reference &&
|
241
|
+
amount == o.amount &&
|
242
|
+
currency == o.currency &&
|
243
|
+
state == o.state &&
|
244
|
+
captured_amount == o.captured_amount &&
|
245
|
+
refunded_amount == o.refunded_amount &&
|
246
|
+
created_date == o.created_date &&
|
247
|
+
order == o.order &&
|
248
|
+
metadata == o.metadata
|
249
|
+
end
|
250
|
+
|
251
|
+
# @see the `==` method
|
252
|
+
# @param [Object] Object to be compared
|
253
|
+
def eql?(o)
|
254
|
+
self == o
|
255
|
+
end
|
256
|
+
|
257
|
+
# Calculates hash code according to all attributes.
|
258
|
+
# @return [Fixnum] Hash code
|
259
|
+
def hash
|
260
|
+
[id, reference, amount, currency, state, captured_amount, refunded_amount, created_date, order, metadata].hash
|
261
|
+
end
|
262
|
+
|
263
|
+
# Builds the object from hash
|
264
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
265
|
+
# @return [Object] Returns the model itself
|
266
|
+
def build_from_hash(attributes)
|
267
|
+
return nil unless attributes.is_a?(Hash)
|
268
|
+
self.class.zip_types.each_pair do |key, type|
|
269
|
+
if type =~ /\AArray<(.*)>/i
|
270
|
+
# check to ensure the input is an array given that the the attribute
|
271
|
+
# is documented as an array but the input is not
|
272
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
273
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
274
|
+
end
|
275
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
276
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
277
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
278
|
+
end
|
279
|
+
|
280
|
+
self
|
281
|
+
end
|
282
|
+
|
283
|
+
# Deserializes the data based on type
|
284
|
+
# @param string type Data type
|
285
|
+
# @param string value Value to be deserialized
|
286
|
+
# @return [Object] Deserialized data
|
287
|
+
def _deserialize(type, value)
|
288
|
+
case type.to_sym
|
289
|
+
when :DateTime
|
290
|
+
DateTime.parse(value)
|
291
|
+
when :Date
|
292
|
+
Date.parse(value)
|
293
|
+
when :String
|
294
|
+
value.to_s
|
295
|
+
when :Integer
|
296
|
+
value.to_i
|
297
|
+
when :Float
|
298
|
+
value.to_f
|
299
|
+
when :BOOLEAN
|
300
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
301
|
+
true
|
302
|
+
else
|
303
|
+
false
|
304
|
+
end
|
305
|
+
when :Object
|
306
|
+
# generic object (usually a Hash), return directly
|
307
|
+
value
|
308
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
309
|
+
inner_type = Regexp.last_match[:inner_type]
|
310
|
+
value.map { |v| _deserialize(inner_type, v) }
|
311
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
312
|
+
k_type = Regexp.last_match[:k_type]
|
313
|
+
v_type = Regexp.last_match[:v_type]
|
314
|
+
{}.tap do |hash|
|
315
|
+
value.each do |k, v|
|
316
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
else # model
|
320
|
+
temp_model = ZipMoney.const_get(type).new
|
321
|
+
temp_model.build_from_hash(value)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
# Returns the string representation of the object
|
326
|
+
# @return [String] String presentation of the object
|
327
|
+
def to_s
|
328
|
+
to_hash.to_s
|
329
|
+
end
|
330
|
+
|
331
|
+
# to_body is an alias to to_hash (backward compatibility)
|
332
|
+
# @return [Hash] Returns the object in the form of hash
|
333
|
+
def to_body
|
334
|
+
to_hash
|
335
|
+
end
|
336
|
+
|
337
|
+
# Returns the object in the form of hash
|
338
|
+
# @return [Hash] Returns the object in the form of hash
|
339
|
+
def to_hash
|
340
|
+
hash = {}
|
341
|
+
self.class.attribute_map.each_pair do |attr, param|
|
342
|
+
value = self.send(attr)
|
343
|
+
next if value.nil?
|
344
|
+
hash[param] = _to_hash(value)
|
345
|
+
end
|
346
|
+
hash
|
347
|
+
end
|
348
|
+
|
349
|
+
# Outputs non-array value in the form of hash
|
350
|
+
# For object, use to_hash. Otherwise, just return the value
|
351
|
+
# @param [Object] value Any valid value
|
352
|
+
# @return [Hash] Returns the value in the form of hash
|
353
|
+
def _to_hash(value)
|
354
|
+
if value.is_a?(Array)
|
355
|
+
value.compact.map{ |v| _to_hash(v) }
|
356
|
+
elsif value.is_a?(Hash)
|
357
|
+
{}.tap do |hash|
|
358
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
359
|
+
end
|
360
|
+
elsif value.respond_to? :to_hash
|
361
|
+
value.to_hash
|
362
|
+
else
|
363
|
+
value
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|