paypal-sdk-rest 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,23 @@
1
- require 'paypal-sdk-core'
2
-
3
- module PayPal
4
- module SDK
5
- module REST
6
- class API < Core::API::REST
7
- # include Services
8
-
9
- def initialize(environment = nil, options = {})
10
- super("", environment, options)
11
- end
12
-
13
- class << self
14
- def user_agent
15
- @user_agent ||= "PayPalSDK/rest-sdk-ruby #{VERSION} (#{sdk_library_details})"
16
- end
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
23
-
1
+ require 'paypal-sdk-core'
2
+
3
+ module PayPal
4
+ module SDK
5
+ module REST
6
+ class API < Core::API::REST
7
+ # include Services
8
+
9
+ def initialize(environment = nil, options = {})
10
+ super("", environment, options)
11
+ end
12
+
13
+ class << self
14
+ def user_agent
15
+ @user_agent ||= "PayPalSDK/rest-sdk-ruby #{VERSION} (#{sdk_library_details})"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -1,459 +1,878 @@
1
- require 'paypal-sdk-core'
2
- require 'uuidtools'
3
-
4
- module PayPal::SDK
5
- module REST
6
- module DataTypes
7
- class Base < Core::API::DataTypes::Base
8
- attr_accessor :error
9
- attr_writer :header, :request_id
10
-
11
- def header
12
- @header ||= {}
13
- end
14
-
15
- def request_id
16
- @request_id ||= UUIDTools::UUID.random_create.to_s
17
- end
18
-
19
- def http_header
20
- { "PayPal-Request-Id" => request_id.to_s }.merge(header)
21
- end
22
-
23
- def success?
24
- @error.nil?
25
- end
26
-
27
- def merge!(values)
28
- @error = nil
29
- super
30
- end
31
-
32
- def self.load_members
33
- end
34
- end
35
-
36
- class Payment < Base
37
-
38
- def self.load_members
39
- object_of :id, String
40
- object_of :create_time, DateTime
41
- object_of :update_time, DateTime
42
- object_of :intent, String
43
- object_of :payer, Payer
44
- array_of :transactions, Transaction
45
- object_of :state, String
46
- object_of :redirect_urls, RedirectUrls
47
- array_of :links, Links
48
- end
49
-
50
- include RequestDataType
51
-
52
- def create()
53
- path = "v1/payments/payment"
54
- response = api.post(path, self.to_hash, http_header)
55
- self.merge!(response)
56
- success?
57
- end
58
-
59
- class << self
60
- def find(resource_id)
61
- raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
62
- path = "v1/payments/payment/#{resource_id}"
63
- self.new(api.get(path))
64
- end
65
- end
66
-
67
- def execute(payment_execution)
68
- payment_execution = PaymentExecution.new(payment_execution) unless payment_execution.is_a? PaymentExecution
69
- path = "v1/payments/payment/#{self.id}/execute"
70
- response = api.post(path, payment_execution.to_hash, http_header)
71
- self.merge!(response)
72
- success?
73
- end
74
-
75
- class << self
76
- def all(options = {})
77
- path = "v1/payments/payment"
78
- PaymentHistory.new(api.get(path, options))
79
- end
80
- end
81
-
82
- end
83
- class Payer < Base
84
-
85
- def self.load_members
86
- object_of :payment_method, String
87
- array_of :funding_instruments, FundingInstrument
88
- object_of :payer_info, PayerInfo
89
- end
90
-
91
- end
92
- class FundingInstrument < Base
93
-
94
- def self.load_members
95
- object_of :credit_card, CreditCard
96
- object_of :credit_card_token, CreditCardToken
97
- end
98
-
99
- end
100
- class CreditCard < Base
101
-
102
- def self.load_members
103
- object_of :id, String
104
- object_of :number, String
105
- object_of :type, String
106
- object_of :expire_month, Integer
107
- object_of :expire_year, Integer
108
- object_of :cvv2, String
109
- object_of :first_name, String
110
- object_of :last_name, String
111
- object_of :billing_address, Address
112
- object_of :payer_id, String
113
- object_of :state, String
114
- object_of :valid_until, String
115
- array_of :links, Links
116
- end
117
-
118
- include RequestDataType
119
-
120
- def create()
121
- path = "v1/vault/credit-card"
122
- response = api.post(path, self.to_hash, http_header)
123
- self.merge!(response)
124
- success?
125
- end
126
-
127
- class << self
128
- def find(resource_id)
129
- raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
130
- path = "v1/vault/credit-card/#{resource_id}"
131
- self.new(api.get(path))
132
- end
133
- end
134
-
135
- def delete()
136
- path = "v1/vault/credit-card/#{self.id}"
137
- response = api.delete(path, {})
138
- self.merge!(response)
139
- success?
140
- end
141
-
142
- end
143
- class Address < Base
144
-
145
- def self.load_members
146
- object_of :line1, String
147
- object_of :line2, String
148
- object_of :city, String
149
- object_of :country_code, String
150
- object_of :postal_code, String
151
- object_of :state, String
152
- object_of :phone, String
153
- end
154
-
155
- end
156
- class Links < Base
157
-
158
- def self.load_members
159
- object_of :href, String
160
- object_of :rel, String
161
- object_of :targetSchema, HyperSchema
162
- object_of :method, String
163
- object_of :enctype, String
164
- object_of :schema, HyperSchema
165
- end
166
-
167
- end
168
- class HyperSchema < Base
169
-
170
- def self.load_members
171
- array_of :links, Links
172
- object_of :fragmentResolution, String
173
- object_of :readonly, Boolean
174
- object_of :contentEncoding, String
175
- object_of :pathStart, String
176
- object_of :mediaType, String
177
- end
178
-
179
- end
180
- class CreditCardToken < Base
181
-
182
- def self.load_members
183
- object_of :credit_card_id, String
184
- object_of :payer_id, String
185
- object_of :last4, String
186
- object_of :type, String
187
- object_of :expire_month, Integer
188
- object_of :expire_year, Integer
189
- end
190
-
191
- end
192
- class PayerInfo < Base
193
-
194
- def self.load_members
195
- object_of :email, String
196
- object_of :first_name, String
197
- object_of :last_name, String
198
- object_of :payer_id, String
199
- object_of :phone, String
200
- object_of :shipping_address, Address
201
- end
202
-
203
- end
204
- class Transaction < Base
205
-
206
- def self.load_members
207
- object_of :amount, Amount
208
- object_of :payee, Payee
209
- object_of :description, String
210
- object_of :item_list, ItemList
211
- array_of :related_resources, RelatedResources
212
- array_of :transactions, Transaction
213
- end
214
-
215
- end
216
- class Amount < Base
217
-
218
- def self.load_members
219
- object_of :currency, String
220
- object_of :total, String
221
- object_of :details, Details
222
- end
223
-
224
- end
225
- class Details < Base
226
-
227
- def self.load_members
228
- object_of :shipping, String
229
- object_of :subtotal, String
230
- object_of :tax, String
231
- object_of :fee, String
232
- end
233
-
234
- end
235
- class Payee < Base
236
-
237
- def self.load_members
238
- object_of :email, String
239
- object_of :merchant_id, String
240
- object_of :phone, String
241
- end
242
-
243
- end
244
- class Item < Base
245
-
246
- def self.load_members
247
- object_of :quantity, String
248
- object_of :name, String
249
- object_of :price, String
250
- object_of :currency, String
251
- object_of :sku, String
252
- end
253
-
254
- end
255
- class ShippingAddress < Address
256
-
257
- def self.load_members
258
- object_of :recipient_name, String
259
- end
260
-
261
- end
262
- class ItemList < Base
263
-
264
- def self.load_members
265
- array_of :items, Item
266
- object_of :shipping_address, ShippingAddress
267
- end
268
-
269
- end
270
- class RelatedResources < Base
271
-
272
- def self.load_members
273
- object_of :sale, Sale
274
- object_of :authorization, Authorization
275
- object_of :capture, Capture
276
- object_of :refund, Refund
277
- end
278
-
279
- end
280
- class Sale < Base
281
-
282
- def self.load_members
283
- object_of :id, String
284
- object_of :create_time, DateTime
285
- object_of :update_time, DateTime
286
- object_of :amount, Amount
287
- object_of :state, String
288
- object_of :parent_payment, String
289
- array_of :links, Links
290
- end
291
-
292
- include RequestDataType
293
-
294
- class << self
295
- def find(resource_id)
296
- raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
297
- path = "v1/payments/sale/#{resource_id}"
298
- self.new(api.get(path))
299
- end
300
- end
301
-
302
- def refund(refund)
303
- refund = Refund.new(refund) unless refund.is_a? Refund
304
- path = "v1/payments/sale/#{self.id}/refund"
305
- response = api.post(path, refund.to_hash, http_header)
306
- Refund.new(response)
307
- end
308
-
309
- end
310
- class Authorization < Base
311
-
312
- def self.load_members
313
- object_of :id, String
314
- object_of :create_time, DateTime
315
- object_of :update_time, DateTime
316
- object_of :amount, Amount
317
- object_of :state, String
318
- object_of :parent_payment, String
319
- object_of :valid_until, String
320
- array_of :links, Links
321
- end
322
-
323
- include RequestDataType
324
-
325
- class << self
326
- def find(resource_id)
327
- raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
328
- path = "v1/payments/authorization/#{resource_id}"
329
- self.new(api.get(path))
330
- end
331
- end
332
-
333
- def capture(capture)
334
- capture = Capture.new(capture) unless capture.is_a? Capture
335
- path = "v1/payments/authorization/#{self.id}/capture"
336
- response = api.post(path, capture.to_hash, http_header)
337
- Capture.new(response)
338
- end
339
-
340
- def void()
341
- path = "v1/payments/authorization/#{self.id}/void"
342
- response = api.post(path, {}, http_header)
343
- self.merge!(response)
344
- success?
345
- end
346
-
347
- def reauthorize()
348
- path = "v1/payments/authorization/#{self.id}/reauthorize"
349
- response = api.post(path, self.to_hash, http_header)
350
- self.merge!(response)
351
- success?
352
- end
353
-
354
- end
355
- class Capture < Base
356
-
357
- def self.load_members
358
- object_of :id, String
359
- object_of :create_time, DateTime
360
- object_of :update_time, DateTime
361
- object_of :amount, Amount
362
- object_of :is_final_capture, Boolean
363
- object_of :state, String
364
- object_of :parent_payment, String
365
- array_of :links, Links
366
- end
367
-
368
- include RequestDataType
369
-
370
- class << self
371
- def find(resource_id)
372
- raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
373
- path = "v1/payments/capture/#{resource_id}"
374
- self.new(api.get(path))
375
- end
376
- end
377
-
378
- def refund(refund)
379
- refund = Refund.new(refund) unless refund.is_a? Refund
380
- path = "v1/payments/capture/#{self.id}/refund"
381
- response = api.post(path, refund.to_hash, http_header)
382
- Refund.new(response)
383
- end
384
-
385
- end
386
- class Refund < Base
387
-
388
- def self.load_members
389
- object_of :id, String
390
- object_of :create_time, DateTime
391
- object_of :amount, Amount
392
- object_of :state, String
393
- object_of :sale_id, String
394
- object_of :capture_id, String
395
- object_of :parent_payment, String
396
- array_of :links, Links
397
- end
398
-
399
- include RequestDataType
400
-
401
- class << self
402
- def find(resource_id)
403
- raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
404
- path = "v1/payments/refund/#{resource_id}"
405
- self.new(api.get(path))
406
- end
407
- end
408
-
409
- end
410
- class RedirectUrls < Base
411
-
412
- def self.load_members
413
- object_of :return_url, String
414
- object_of :cancel_url, String
415
- end
416
-
417
- end
418
- class PaymentHistory < Base
419
-
420
- def self.load_members
421
- array_of :payments, Payment
422
- object_of :count, Integer
423
- object_of :next_id, String
424
- end
425
-
426
- end
427
- class PaymentExecution < Base
428
-
429
- def self.load_members
430
- object_of :payer_id, String
431
- array_of :transactions, Transactions
432
- end
433
-
434
- end
435
- class Transactions < Base
436
-
437
- def self.load_members
438
- object_of :amount, Amount
439
- end
440
-
441
- end
442
- class CreditCardHistory < Base
443
-
444
- def self.load_members
445
- array_of :"credit-cards", CreditCard
446
- object_of :count, Integer
447
- object_of :next_id, String
448
- end
449
-
450
- end
451
-
452
- constants.each do |data_type_klass|
453
- data_type_klass = const_get(data_type_klass)
454
- data_type_klass.load_members if defined? data_type_klass.load_members
455
- end
456
-
457
- end
458
- end
459
- end
1
+ require 'paypal-sdk-core'
2
+ require 'uuidtools'
3
+
4
+ module PayPal::SDK
5
+ module REST
6
+ module DataTypes
7
+ class Base < Core::API::DataTypes::Base
8
+ attr_accessor :error
9
+ attr_writer :header, :request_id
10
+
11
+ def header
12
+ @header ||= {}
13
+ end
14
+
15
+ def request_id
16
+ @request_id ||= UUIDTools::UUID.random_create.to_s
17
+ end
18
+
19
+ def http_header
20
+ { "PayPal-Request-Id" => request_id.to_s }.merge(header)
21
+ end
22
+
23
+ def success?
24
+ @error.nil?
25
+ end
26
+
27
+ def merge!(values)
28
+ @error = nil
29
+ super
30
+ end
31
+
32
+ def self.load_members
33
+ end
34
+
35
+ class Number < Float
36
+ end
37
+ end
38
+
39
+ class PaymentHistory < Base
40
+
41
+ def self.load_members
42
+ array_of :payments, Payment
43
+ object_of :count, Integer
44
+ object_of :next_id, String
45
+ end
46
+
47
+ end
48
+ class Payment < Base
49
+
50
+ def self.load_members
51
+ object_of :id, String
52
+ object_of :create_time, DateTime
53
+ object_of :update_time, DateTime
54
+ object_of :intent, String
55
+ object_of :payer, Payer
56
+ array_of :transactions, Transaction
57
+ object_of :state, String
58
+ object_of :redirect_urls, RedirectUrls
59
+ array_of :links, Links
60
+ end
61
+
62
+ include RequestDataType
63
+
64
+ def create()
65
+ path = "v1/payments/payment"
66
+ response = api.post(path, self.to_hash, http_header)
67
+ self.merge!(response)
68
+ success?
69
+ end
70
+
71
+ class << self
72
+ def find(resource_id)
73
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
74
+ path = "v1/payments/payment/#{resource_id}"
75
+ self.new(api.get(path))
76
+ end
77
+ end
78
+
79
+ def execute(payment_execution)
80
+ payment_execution = PaymentExecution.new(payment_execution) unless payment_execution.is_a? PaymentExecution
81
+ path = "v1/payments/payment/#{self.id}/execute"
82
+ response = api.post(path, payment_execution.to_hash, http_header)
83
+ self.merge!(response)
84
+ success?
85
+ end
86
+
87
+ class << self
88
+ def all(options = {})
89
+ path = "v1/payments/payment"
90
+ PaymentHistory.new(api.get(path, options))
91
+ end
92
+ end
93
+
94
+ end
95
+ class Payer < Base
96
+
97
+ def self.load_members
98
+ object_of :payment_method, String
99
+ array_of :funding_instruments, FundingInstrument
100
+ object_of :payer_info, PayerInfo
101
+ end
102
+
103
+ end
104
+ class FundingInstrument < Base
105
+
106
+ def self.load_members
107
+ object_of :credit_card, CreditCard
108
+ object_of :credit_card_token, CreditCardToken
109
+ end
110
+
111
+ end
112
+ class CreditCard < Base
113
+
114
+ def self.load_members
115
+ object_of :id, String
116
+ object_of :number, String
117
+ object_of :type, String
118
+ object_of :expire_month, Integer
119
+ object_of :expire_year, Integer
120
+ object_of :cvv2, String
121
+ object_of :first_name, String
122
+ object_of :last_name, String
123
+ object_of :billing_address, Address
124
+ object_of :payer_id, String
125
+ object_of :state, String
126
+ object_of :valid_until, String
127
+ array_of :links, Links
128
+ end
129
+
130
+ include RequestDataType
131
+
132
+ def create()
133
+ path = "v1/vault/credit-card"
134
+ response = api.post(path, self.to_hash, http_header)
135
+ self.merge!(response)
136
+ success?
137
+ end
138
+
139
+ class << self
140
+ def find(resource_id)
141
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
142
+ path = "v1/vault/credit-card/#{resource_id}"
143
+ self.new(api.get(path))
144
+ end
145
+ end
146
+
147
+ def delete()
148
+ path = "v1/vault/credit-card/#{self.id}"
149
+ response = api.delete(path, {})
150
+ self.merge!(response)
151
+ success?
152
+ end
153
+
154
+ def update()
155
+ path = "v1/vault/credit-card/#{self.id}"
156
+ response = api.patch(path, self.to_hash, http_header)
157
+ self.merge!(response)
158
+ success?
159
+ end
160
+
161
+ class << self
162
+ def all(options = {})
163
+ path = "v1/vault/credit-card"
164
+ CreditCardHistory.new(api.get(path, options))
165
+ end
166
+ end
167
+
168
+ end
169
+ class Address < Base
170
+
171
+ def self.load_members
172
+ object_of :line1, String
173
+ object_of :line2, String
174
+ object_of :city, String
175
+ object_of :country_code, String
176
+ object_of :postal_code, String
177
+ object_of :state, String
178
+ object_of :phone, String
179
+ end
180
+
181
+ end
182
+ class Links < Base
183
+
184
+ def self.load_members
185
+ object_of :href, String
186
+ object_of :rel, String
187
+ object_of :targetSchema, HyperSchema
188
+ object_of :method, String
189
+ object_of :enctype, String
190
+ object_of :schema, HyperSchema
191
+ end
192
+
193
+ end
194
+ class HyperSchema < Base
195
+
196
+ def self.load_members
197
+ array_of :links, Links
198
+ object_of :fragmentResolution, String
199
+ object_of :readonly, Boolean
200
+ object_of :contentEncoding, String
201
+ object_of :pathStart, String
202
+ object_of :mediaType, String
203
+ end
204
+
205
+ end
206
+ class CreditCardToken < Base
207
+
208
+ def self.load_members
209
+ object_of :credit_card_id, String
210
+ object_of :payer_id, String
211
+ object_of :last4, String
212
+ object_of :type, String
213
+ object_of :expire_month, Integer
214
+ object_of :expire_year, Integer
215
+ end
216
+
217
+ end
218
+ class PayerInfo < Base
219
+
220
+ def self.load_members
221
+ object_of :email, String
222
+ object_of :first_name, String
223
+ object_of :last_name, String
224
+ object_of :payer_id, String
225
+ object_of :phone, String
226
+ object_of :shipping_address, Address
227
+ end
228
+
229
+ end
230
+ class Transaction < Base
231
+
232
+ def self.load_members
233
+ object_of :amount, Amount
234
+ object_of :payee, Payee
235
+ object_of :description, String
236
+ object_of :item_list, ItemList
237
+ array_of :related_resources, RelatedResources
238
+ array_of :transactions, Transaction
239
+ end
240
+
241
+ end
242
+ class Amount < Base
243
+
244
+ def self.load_members
245
+ object_of :currency, String
246
+ object_of :total, String
247
+ object_of :details, Details
248
+ end
249
+
250
+ end
251
+ class Details < Base
252
+
253
+ def self.load_members
254
+ object_of :shipping, String
255
+ object_of :subtotal, String
256
+ object_of :tax, String
257
+ object_of :fee, String
258
+ end
259
+
260
+ end
261
+ class Payee < Base
262
+
263
+ def self.load_members
264
+ object_of :email, String
265
+ object_of :merchant_id, String
266
+ object_of :phone, String
267
+ end
268
+
269
+ end
270
+ class Item < Base
271
+
272
+ def self.load_members
273
+ object_of :quantity, String
274
+ object_of :name, String
275
+ object_of :price, String
276
+ object_of :currency, String
277
+ object_of :sku, String
278
+ end
279
+
280
+ end
281
+ class ShippingAddress < Address
282
+
283
+ def self.load_members
284
+ object_of :recipient_name, String
285
+ end
286
+
287
+ end
288
+ class ItemList < Base
289
+
290
+ def self.load_members
291
+ array_of :items, Item
292
+ object_of :shipping_address, ShippingAddress
293
+ end
294
+
295
+ end
296
+ class RelatedResources < Base
297
+
298
+ def self.load_members
299
+ object_of :sale, Sale
300
+ object_of :authorization, Authorization
301
+ object_of :capture, Capture
302
+ object_of :refund, Refund
303
+ end
304
+
305
+ end
306
+ class Sale < Base
307
+
308
+ def self.load_members
309
+ object_of :id, String
310
+ object_of :create_time, DateTime
311
+ object_of :update_time, DateTime
312
+ object_of :amount, Amount
313
+ object_of :state, String
314
+ object_of :parent_payment, String
315
+ array_of :links, Links
316
+ end
317
+
318
+ include RequestDataType
319
+
320
+ class << self
321
+ def find(resource_id)
322
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
323
+ path = "v1/payments/sale/#{resource_id}"
324
+ self.new(api.get(path))
325
+ end
326
+ end
327
+
328
+ def refund(refund)
329
+ refund = Refund.new(refund) unless refund.is_a? Refund
330
+ path = "v1/payments/sale/#{self.id}/refund"
331
+ response = api.post(path, refund.to_hash, http_header)
332
+ Refund.new(response)
333
+ end
334
+
335
+ end
336
+ class Authorization < Base
337
+
338
+ def self.load_members
339
+ object_of :id, String
340
+ object_of :create_time, DateTime
341
+ object_of :update_time, DateTime
342
+ object_of :amount, Amount
343
+ object_of :state, String
344
+ object_of :parent_payment, String
345
+ object_of :valid_until, String
346
+ array_of :links, Links
347
+ end
348
+
349
+ include RequestDataType
350
+
351
+ class << self
352
+ def find(resource_id)
353
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
354
+ path = "v1/payments/authorization/#{resource_id}"
355
+ self.new(api.get(path))
356
+ end
357
+ end
358
+
359
+ def capture(capture)
360
+ capture = Capture.new(capture) unless capture.is_a? Capture
361
+ path = "v1/payments/authorization/#{self.id}/capture"
362
+ response = api.post(path, capture.to_hash, http_header)
363
+ Capture.new(response)
364
+ end
365
+
366
+ def void()
367
+ path = "v1/payments/authorization/#{self.id}/void"
368
+ response = api.post(path, {}, http_header)
369
+ self.merge!(response)
370
+ success?
371
+ end
372
+
373
+ def reauthorize()
374
+ path = "v1/payments/authorization/#{self.id}/reauthorize"
375
+ response = api.post(path, self.to_hash, http_header)
376
+ self.merge!(response)
377
+ success?
378
+ end
379
+
380
+ end
381
+ class Capture < Base
382
+
383
+ def self.load_members
384
+ object_of :id, String
385
+ object_of :create_time, DateTime
386
+ object_of :update_time, DateTime
387
+ object_of :amount, Amount
388
+ object_of :is_final_capture, Boolean
389
+ object_of :state, String
390
+ object_of :parent_payment, String
391
+ array_of :links, Links
392
+ end
393
+
394
+ include RequestDataType
395
+
396
+ class << self
397
+ def find(resource_id)
398
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
399
+ path = "v1/payments/capture/#{resource_id}"
400
+ self.new(api.get(path))
401
+ end
402
+ end
403
+
404
+ def refund(refund)
405
+ refund = Refund.new(refund) unless refund.is_a? Refund
406
+ path = "v1/payments/capture/#{self.id}/refund"
407
+ response = api.post(path, refund.to_hash, http_header)
408
+ Refund.new(response)
409
+ end
410
+
411
+ end
412
+ class Refund < Base
413
+
414
+ def self.load_members
415
+ object_of :id, String
416
+ object_of :create_time, DateTime
417
+ object_of :update_time, DateTime
418
+ object_of :amount, Amount
419
+ object_of :state, String
420
+ object_of :sale_id, String
421
+ object_of :capture_id, String
422
+ object_of :parent_payment, String
423
+ array_of :links, Links
424
+ end
425
+
426
+ include RequestDataType
427
+
428
+ class << self
429
+ def find(resource_id)
430
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
431
+ path = "v1/payments/refund/#{resource_id}"
432
+ self.new(api.get(path))
433
+ end
434
+ end
435
+
436
+ end
437
+ class RedirectUrls < Base
438
+
439
+ def self.load_members
440
+ object_of :return_url, String
441
+ object_of :cancel_url, String
442
+ end
443
+
444
+ end
445
+ class PaymentExecution < Base
446
+
447
+ def self.load_members
448
+ object_of :payer_id, String
449
+ array_of :transactions, Transactions
450
+ end
451
+
452
+ end
453
+ class Transactions < Base
454
+
455
+ def self.load_members
456
+ object_of :amount, Amount
457
+ end
458
+
459
+ end
460
+ class CreditCardHistory < Base
461
+
462
+ def self.load_members
463
+ array_of :"credit-cards", CreditCard
464
+ object_of :count, Integer
465
+ object_of :next_id, String
466
+ end
467
+
468
+ end
469
+ class Error < Base
470
+
471
+ def self.load_members
472
+ object_of :name, String
473
+ object_of :debug_id, String
474
+ object_of :message, String
475
+ object_of :information_link, String
476
+ array_of :details, ErrorDetails
477
+ end
478
+
479
+ end
480
+ class Invoice < Base
481
+
482
+ def self.load_members
483
+ object_of :id, String
484
+ object_of :number, String
485
+ object_of :uri, String
486
+ object_of :status, String
487
+ object_of :merchant_info, MerchantInfo
488
+ array_of :billing_info, BillingInfo
489
+ object_of :shipping_info, ShippingInfo
490
+ array_of :items, InvoiceItem
491
+ object_of :invoice_date, String
492
+ object_of :payment_term, PaymentTerm
493
+ object_of :discount, Cost
494
+ object_of :shipping_cost, ShippingCost
495
+ object_of :custom, CustomAmount
496
+ object_of :tax_calculated_after_discount, Boolean
497
+ object_of :tax_inclusive, Boolean
498
+ object_of :terms, String
499
+ object_of :note, String
500
+ object_of :merchant_memo, String
501
+ object_of :logo_url, String
502
+ object_of :total_amount, Currency
503
+ array_of :payment_details, PaymentDetail
504
+ array_of :refund_details, RefundDetail
505
+ object_of :metadata, Metadata
506
+ end
507
+
508
+ include RequestDataType
509
+
510
+ def create()
511
+ path = "v1/invoicing/invoices"
512
+ response = api.post(path, self.to_hash, http_header)
513
+ self.merge!(response)
514
+ success?
515
+ end
516
+
517
+ class << self
518
+ def self.search(options)
519
+ path = "v1/invoicing/search"
520
+ response = api.post(path, options)
521
+ Invoices.new(response)
522
+ end
523
+ end
524
+
525
+ def send_invoice()
526
+ path = "v1/invoicing/invoices/#{self.id}/send"
527
+ response = api.post(path, {}, http_header)
528
+ self.merge!(response)
529
+ success?
530
+ end
531
+
532
+ def remind(notification)
533
+ notification = Notification.new(notification) unless notification.is_a? Notification
534
+ path = "v1/invoicing/invoices/#{self.id}/remind"
535
+ response = api.post(path, notification.to_hash, http_header)
536
+ self.merge!(response)
537
+ success?
538
+ end
539
+
540
+ def cancel(cancel_notification)
541
+ cancel_notification = CancelNotification.new(cancel_notification) unless cancel_notification.is_a? CancelNotification
542
+ path = "v1/invoicing/invoices/#{self.id}/cancel"
543
+ response = api.post(path, cancel_notification.to_hash, http_header)
544
+ self.merge!(response)
545
+ success?
546
+ end
547
+
548
+ def record_payment(payment_detail)
549
+ payment_detail = PaymentDetail.new(payment_detail) unless payment_detail.is_a? PaymentDetail
550
+ path = "v1/invoicing/invoices/#{self.id}/record-payment"
551
+ response = api.post(path, payment_detail.to_hash, http_header)
552
+ self.merge!(response)
553
+ success?
554
+ end
555
+
556
+ def record_refund(refund_detail)
557
+ refund_detail = RefundDetail.new(refund_detail) unless refund_detail.is_a? RefundDetail
558
+ path = "v1/invoicing/invoices/#{self.id}/record-refund"
559
+ response = api.post(path, refund_detail.to_hash, http_header)
560
+ self.merge!(response)
561
+ success?
562
+ end
563
+
564
+ class << self
565
+ def find(resource_id)
566
+ raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
567
+ path = "v1/invoicing/invoices/#{resource_id}"
568
+ self.new(api.get(path))
569
+ end
570
+ end
571
+
572
+ class << self
573
+ def get_all(options = {})
574
+ path = "v1/invoicing/invoices/"
575
+ Invoices.new(api.get(path, options))
576
+ end
577
+ end
578
+
579
+ def update()
580
+ path = "v1/invoicing/invoices/#{self.id}"
581
+ response = api.put(path, self.to_hash, http_header)
582
+ self.merge!(response)
583
+ success?
584
+ end
585
+
586
+ def delete()
587
+ path = "v1/invoicing/invoices/#{self.id}"
588
+ response = api.delete(path, {})
589
+ self.merge!(response)
590
+ success?
591
+ end
592
+
593
+ end
594
+ class Invoices < Base
595
+
596
+ def self.load_members
597
+ object_of :total_count, Integer
598
+ array_of :invoices, Invoice
599
+ end
600
+
601
+ end
602
+ class InvoiceItem < Base
603
+
604
+ def self.load_members
605
+ object_of :name, String
606
+ object_of :description, String
607
+ object_of :quantity, Number
608
+ object_of :unit_price, Currency
609
+ object_of :tax, Tax
610
+ object_of :date, String
611
+ object_of :discount, Cost
612
+ end
613
+
614
+ end
615
+ class MerchantInfo < Base
616
+
617
+ def self.load_members
618
+ object_of :email, String
619
+ object_of :first_name, String
620
+ object_of :last_name, String
621
+ object_of :address, Address
622
+ object_of :business_name, String
623
+ object_of :phone, Phone
624
+ object_of :fax, Phone
625
+ object_of :website, String
626
+ object_of :tax_id, String
627
+ object_of :additional_info, String
628
+ end
629
+
630
+ end
631
+ class BillingInfo < Base
632
+
633
+ def self.load_members
634
+ object_of :email, String
635
+ object_of :first_name, String
636
+ object_of :last_name, String
637
+ object_of :business_name, String
638
+ object_of :address, Address
639
+ object_of :language, String
640
+ object_of :additional_info, String
641
+ end
642
+
643
+ end
644
+ class ShippingInfo < Base
645
+
646
+ def self.load_members
647
+ object_of :first_name, String
648
+ object_of :last_name, String
649
+ object_of :business_name, String
650
+ object_of :address, Address
651
+ end
652
+
653
+ end
654
+ class InvoicingNotification < Base
655
+
656
+ def self.load_members
657
+ object_of :subject, String
658
+ object_of :note, String
659
+ object_of :send_to_merchant, Boolean
660
+ end
661
+
662
+ end
663
+ class InvoicingMetaData < Base
664
+
665
+ def self.load_members
666
+ object_of :created_date, String
667
+ object_of :created_by, String
668
+ object_of :cancelled_date, String
669
+ object_of :cancelled_by, String
670
+ object_of :last_updated_date, String
671
+ object_of :last_updated_by, String
672
+ object_of :first_sent_date, String
673
+ object_of :last_sent_date, String
674
+ object_of :last_sent_by, String
675
+ end
676
+
677
+ end
678
+ class InvoicingPaymentDetail < Base
679
+
680
+ def self.load_members
681
+ object_of :type, String
682
+ object_of :transaction_id, String
683
+ object_of :transaction_type, String
684
+ object_of :date, String
685
+ object_of :method, String
686
+ object_of :note, String
687
+ end
688
+
689
+ end
690
+ class InvoicingRefundDetail < Base
691
+
692
+ def self.load_members
693
+ object_of :type, String
694
+ object_of :date, String
695
+ object_of :note, String
696
+ end
697
+
698
+ end
699
+ class InvoicingSearch < Base
700
+
701
+ def self.load_members
702
+ object_of :email, String
703
+ object_of :recipient_first_name, String
704
+ object_of :recipient_last_name, String
705
+ object_of :recipient_business_name, String
706
+ object_of :number, String
707
+ object_of :status, String
708
+ object_of :lower_total_amount, Currency
709
+ object_of :upper_total_amount, Currency
710
+ object_of :start_invoice_date, String
711
+ object_of :end_invoice_date, String
712
+ object_of :start_due_date, String
713
+ object_of :end_due_date, String
714
+ object_of :start_payment_date, String
715
+ object_of :end_payment_date, String
716
+ object_of :start_creation_date, String
717
+ object_of :end_creation_date, String
718
+ object_of :page, Number
719
+ object_of :page_size, Number
720
+ object_of :total_count_required, Boolean
721
+ end
722
+
723
+ end
724
+ class ErrorDetails < Base
725
+
726
+ def self.load_members
727
+ object_of :field, String
728
+ object_of :issue, String
729
+ end
730
+
731
+ end
732
+ class PaymentTerm < Base
733
+
734
+ def self.load_members
735
+ object_of :term_type, String
736
+ object_of :due_date, String
737
+ end
738
+
739
+ end
740
+ class Cost < Base
741
+
742
+ def self.load_members
743
+ object_of :percent, Number
744
+ object_of :amount, Currency
745
+ end
746
+
747
+ end
748
+ class Currency < Base
749
+
750
+ def self.load_members
751
+ object_of :currency, String
752
+ object_of :value, String
753
+ end
754
+
755
+ end
756
+ class ShippingCost < Base
757
+
758
+ def self.load_members
759
+ object_of :amount, Currency
760
+ object_of :tax, Tax
761
+ end
762
+
763
+ end
764
+ class Tax < Base
765
+
766
+ def self.load_members
767
+ object_of :id, String
768
+ object_of :name, String
769
+ object_of :percent, Number
770
+ object_of :amount, Currency
771
+ end
772
+
773
+ end
774
+ class CustomAmount < Base
775
+
776
+ def self.load_members
777
+ object_of :label, String
778
+ object_of :amount, Currency
779
+ end
780
+
781
+ end
782
+ class PaymentDetail < Base
783
+
784
+ def self.load_members
785
+ object_of :type, String
786
+ object_of :transaction_id, String
787
+ object_of :transaction_type, String
788
+ object_of :date, String
789
+ object_of :method, String
790
+ object_of :note, String
791
+ end
792
+
793
+ end
794
+ class RefundDetail < Base
795
+
796
+ def self.load_members
797
+ object_of :type, String
798
+ object_of :date, String
799
+ object_of :note, String
800
+ end
801
+
802
+ end
803
+ class Metadata < Base
804
+
805
+ def self.load_members
806
+ object_of :created_date, String
807
+ object_of :created_by, String
808
+ object_of :cancelled_date, String
809
+ object_of :cancelled_by, String
810
+ object_of :last_updated_date, String
811
+ object_of :last_updated_by, String
812
+ object_of :first_sent_date, String
813
+ object_of :last_sent_date, String
814
+ object_of :last_sent_by, String
815
+ end
816
+
817
+ end
818
+ class Phone < Base
819
+
820
+ def self.load_members
821
+ object_of :country_code, String
822
+ object_of :national_number, String
823
+ end
824
+
825
+ end
826
+ class Notification < Base
827
+
828
+ def self.load_members
829
+ object_of :subject, String
830
+ object_of :note, String
831
+ object_of :send_to_merchant, Boolean
832
+ end
833
+
834
+ end
835
+ class Search < Base
836
+
837
+ def self.load_members
838
+ object_of :email, String
839
+ object_of :recipient_first_name, String
840
+ object_of :recipient_last_name, String
841
+ object_of :recipient_business_name, String
842
+ object_of :number, String
843
+ object_of :status, String
844
+ object_of :lower_total_amount, Currency
845
+ object_of :upper_total_amount, Currency
846
+ object_of :start_invoice_date, String
847
+ object_of :end_invoice_date, String
848
+ object_of :start_due_date, String
849
+ object_of :end_due_date, String
850
+ object_of :start_payment_date, String
851
+ object_of :end_payment_date, String
852
+ object_of :start_creation_date, String
853
+ object_of :end_creation_date, String
854
+ object_of :page, Number
855
+ object_of :page_size, Number
856
+ object_of :total_count_required, Boolean
857
+ end
858
+
859
+ end
860
+ class CancelNotification < Base
861
+
862
+ def self.load_members
863
+ object_of :subject, String
864
+ object_of :note, String
865
+ object_of :send_to_merchant, Boolean
866
+ object_of :send_to_payer, Boolean
867
+ end
868
+
869
+ end
870
+
871
+ constants.each do |data_type_klass|
872
+ data_type_klass = const_get(data_type_klass)
873
+ data_type_klass.load_members if defined? data_type_klass.load_members
874
+ end
875
+
876
+ end
877
+ end
878
+ end