mundipagg_v1 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/gateway/customer.rb +0 -0
- data/lib/mundipagg_v1_sdk.rb +574 -0
- data/spec/mundipagg_v1_sdk_spec.rb +289 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ec569f29da2cd58faa4f672595b4f10d3fa80d1
|
4
|
+
data.tar.gz: 9474988b94614f5499d477c00240fe3218afdee7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29df31f25a440ffffe6230f3482466305c3040194dddc897e1653008ea5166cab4eba36953544197e595fb7365694dfaabfeb2c9c4e9e40e8ecfd87ce46184ec
|
7
|
+
data.tar.gz: c356ecc47dbec24044bc81b120970b76c8799de4d34650891d4cf300669796e557a2ac4484b165b7523a9cfa520008043c98f6ffa9a5abf26af4936a4f528606
|
File without changes
|
@@ -0,0 +1,574 @@
|
|
1
|
+
module MundipaggV1Sdk
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
require 'rest-client'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
@@end_point = "https://api.mundipagg.com/core/v1"
|
8
|
+
|
9
|
+
@@SERVICE_HEADERS = {
|
10
|
+
:Authorization => "Basic #{::Base64.encode64("#{ENV['MUNDIPAGG_SECRET_KEY']}:")}",
|
11
|
+
:Accept => 'application/json',
|
12
|
+
:"Content-Type" => 'application/json'
|
13
|
+
}
|
14
|
+
|
15
|
+
# funcao de post generica
|
16
|
+
def postRequest(payload, url)
|
17
|
+
begin
|
18
|
+
response = RestClient.post("#{@@end_point}#{url}", payload, headers=@@SERVICE_HEADERS)
|
19
|
+
rescue RestClient::ExceptionWithResponse => err
|
20
|
+
handle_error_response(err)
|
21
|
+
response = err.response
|
22
|
+
end
|
23
|
+
|
24
|
+
JSON.load response
|
25
|
+
rescue JSON::ParserError => err
|
26
|
+
response
|
27
|
+
end
|
28
|
+
|
29
|
+
# funcao patch generica
|
30
|
+
def patchRequest(payload, url)
|
31
|
+
begin
|
32
|
+
response = RestClient.patch("#{@@end_point}#{url}", payload, headers=@@SERVICE_HEADERS)
|
33
|
+
rescue RestClient::ExceptionWithResponse => err
|
34
|
+
handle_error_response(err)
|
35
|
+
response = err.response
|
36
|
+
end
|
37
|
+
|
38
|
+
JSON.load response
|
39
|
+
rescue JSON::ParserError => err
|
40
|
+
response
|
41
|
+
end
|
42
|
+
|
43
|
+
# funcao de delete generica
|
44
|
+
def deleteRequest(url)
|
45
|
+
begin
|
46
|
+
response = RestClient.delete("#{@@end_point}#{url}", headers=@@SERVICE_HEADERS)
|
47
|
+
rescue RestClient::ExceptionWithResponse => err
|
48
|
+
handle_error_response(err)
|
49
|
+
response = err.response
|
50
|
+
end
|
51
|
+
|
52
|
+
JSON.load response
|
53
|
+
rescue JSON::ParserError => err
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
# funcao get generica
|
58
|
+
def getRequest(url)
|
59
|
+
begin
|
60
|
+
response = RestClient.get("#{@@end_point}#{url}", headers=@@SERVICE_HEADERS)
|
61
|
+
rescue RestClient::ExceptionWithResponse => err
|
62
|
+
handle_error_response(err)
|
63
|
+
response = err.response
|
64
|
+
end
|
65
|
+
|
66
|
+
v = JSON.load response
|
67
|
+
return v["data"] if v["data"] != nil
|
68
|
+
return v
|
69
|
+
rescue JSON::ParserError => err
|
70
|
+
response
|
71
|
+
end
|
72
|
+
|
73
|
+
# funcao get generica
|
74
|
+
def putRequest(payload, url)
|
75
|
+
begin
|
76
|
+
response = RestClient.put("#{@@end_point}#{url}", payload, headers=@@SERVICE_HEADERS)
|
77
|
+
rescue RestClient::ExceptionWithResponse => err
|
78
|
+
handle_error_response(err)
|
79
|
+
response = err.response
|
80
|
+
end
|
81
|
+
|
82
|
+
v = JSON.load response
|
83
|
+
return v["data"] if v["data"] != nil
|
84
|
+
return v
|
85
|
+
rescue JSON::ParserError => err
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
def handle_error_response(err)
|
90
|
+
# MundipaggV1Sdk::AuthenticationError.new
|
91
|
+
err_response = JSON.load(err.response)
|
92
|
+
puts err_response["message"]
|
93
|
+
puts JSON.pretty_generate(err_response["errors"]) unless err_response["errors"].nil?
|
94
|
+
raise(::Exception.new( err_response["message"] ))
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
class MundipaggV1Sdk::Customer
|
100
|
+
|
101
|
+
extend MundipaggV1Sdk
|
102
|
+
|
103
|
+
def self.create(customer)
|
104
|
+
customer = {} if customer == nil
|
105
|
+
postRequest(customer.to_json, "/customers")
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.retrieve(customer_id)
|
109
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
110
|
+
getRequest("/customers/#{customer_id}")
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.list
|
114
|
+
getRequest("/customers")
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.edit(customer_id, customer)
|
118
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
119
|
+
customer = {} if customer == nil
|
120
|
+
putRequest(customer.to_json, "/customers")
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
class MundipaggV1Sdk::AccessToken
|
126
|
+
|
127
|
+
extend MundipaggV1Sdk
|
128
|
+
|
129
|
+
def self.create(customer_id)
|
130
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
131
|
+
body = {}
|
132
|
+
postRequest(body.to_json, "/customers/#{customer_id}/access-tokens")
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.retrieve(customer_id, access_token_id)
|
136
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
137
|
+
ArgumentError.new("Access Token id should be a String") if access_token_id == nil
|
138
|
+
getRequest("/customers/#{customer_id}/access-tokens/#{access_token_id}")
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.list(customer_id)
|
142
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
143
|
+
getRequest("/customers/#{customer_id}/access-tokens")
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.delete(customer_id, access_token_id)
|
147
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
148
|
+
ArgumentError.new("Access Token id should be a String") if access_token_id == nil
|
149
|
+
deleteRequest("/customers/#{customer_id}/access-tokens/#{access_token_id}")
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
class MundipaggV1Sdk::Card
|
155
|
+
|
156
|
+
extend MundipaggV1Sdk
|
157
|
+
|
158
|
+
def self.create(customer_id, card)
|
159
|
+
card = {} if card == nil
|
160
|
+
postRequest(card.to_json, "/customers/#{customer_id}/cards")
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.retrieve(customer_id, card_id)
|
164
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
165
|
+
ArgumentError.new("Card can't be nil") if card_id == nil
|
166
|
+
getRequest("/customers/#{customer_id}/cards/#{card_id}")
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.list(customer_id)
|
170
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
171
|
+
getRequest("/customers/#{customer_id}/cards")
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.delete(customer_id, card_id)
|
175
|
+
ArgumentError.new("Customer id should be a String") if customer_id == nil
|
176
|
+
ArgumentError.new("Card id should be a String") if card_id == nil
|
177
|
+
deleteRequest("/customers/#{customer_id}/cards/#{card_id}")
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
class MundipaggV1Sdk::Charge
|
183
|
+
|
184
|
+
extend MundipaggV1Sdk
|
185
|
+
|
186
|
+
def self.create(charge)
|
187
|
+
charge = {} if charge == nil
|
188
|
+
postRequest(charge.to_json, "/charges")
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.retrieve(charge_id)
|
192
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
193
|
+
getRequest("/charges/#{charge_id}")
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.list(order_id = nil, customer_id = nil, page = nil, size = nil)
|
197
|
+
query = []
|
198
|
+
query << "order_id=#{order_id}" if !order_id.nil?
|
199
|
+
query << "customer_id=#{customer_id}" if !customer_id.nil?
|
200
|
+
query << "page=#{page}" if !page.nil?
|
201
|
+
query << "size=#{size}" if !size.nil?
|
202
|
+
query.first.prepend("?") if !query.empty?
|
203
|
+
getRequest("/charges#{query.join("&")}")
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.capture(charge_id, capture)
|
207
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
208
|
+
capture = {} if capture == nil
|
209
|
+
postRequest(capture.to_json, "/charges/#{charge_id}/capture")
|
210
|
+
end
|
211
|
+
|
212
|
+
def self.delete(charge_id, params)
|
213
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
214
|
+
params = {} if params == nil
|
215
|
+
deleteRequest(params.to_json, "/charges/#{charge_id}")
|
216
|
+
end
|
217
|
+
|
218
|
+
def self.edit_credit_card(charge_id, params)
|
219
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
220
|
+
params = {} if params == nil
|
221
|
+
patchRequest(params, "/charges/#{charge_id}/credit-card")
|
222
|
+
end
|
223
|
+
|
224
|
+
def self.edit_due_date(charge_id, params)
|
225
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
226
|
+
params = {} if params == nil
|
227
|
+
patchRequest(params, "/charges/#{charge_id}/due-date")
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.edit_payment_method(charge_id, params)
|
231
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
232
|
+
params = {} if params == nil
|
233
|
+
patchRequest(params, "/charges/#{charge_id}/retry")
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.retry(charge_id)
|
237
|
+
ArgumentError.new("Charge id should be a String") if charge_id == nil
|
238
|
+
params = {}
|
239
|
+
postRequest(params, "/charges/#{charge_id}/retry")
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
class MundipaggV1Sdk::Plan
|
245
|
+
|
246
|
+
extend MundipaggV1Sdk
|
247
|
+
|
248
|
+
def self.create(plan)
|
249
|
+
plan = {} if plan == nil
|
250
|
+
postRequest(plan.to_json, "/plans")
|
251
|
+
end
|
252
|
+
|
253
|
+
def self.retrieve(plan_id)
|
254
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
255
|
+
getRequest("/plans/#{plan_id}")
|
256
|
+
end
|
257
|
+
|
258
|
+
def self.list(page = nil, size = nil)
|
259
|
+
query = []
|
260
|
+
query << "page=#{page}" if !page.nil?
|
261
|
+
query << "size=#{size}" if !size.nil?
|
262
|
+
query.first.prepend("?") if !query.empty?
|
263
|
+
getRequest("/plans#{query.join("&")}")
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.list_subscriptions(plan_id)
|
267
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
268
|
+
query = []
|
269
|
+
query << "page=#{page}" if !page.nil?
|
270
|
+
query << "size=#{size}" if !size.nil?
|
271
|
+
query.first.prepend("?") if !query.empty?
|
272
|
+
getRequest("/plans/#{plan_id}/subscriptions#{query.join("&")}")
|
273
|
+
end
|
274
|
+
|
275
|
+
def self.edit(plan_id, plan)
|
276
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
277
|
+
plan = {} if plan == nil
|
278
|
+
putRequest(plan.to_json, "/plans")
|
279
|
+
end
|
280
|
+
|
281
|
+
def self.delete(plan_id)
|
282
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
283
|
+
deleteRequest("/plans/#{plan_id}")
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
class MundipaggV1Sdk::PlanItem
|
289
|
+
|
290
|
+
extend MundipaggV1Sdk
|
291
|
+
|
292
|
+
def self.include_in_plan(plan_id, item)
|
293
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
294
|
+
item = {} if item == nil
|
295
|
+
postRequest(item.to_json, "/plans/#{plan_id}/items")
|
296
|
+
end
|
297
|
+
|
298
|
+
def self.edit(plan_id, item_id, item)
|
299
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
300
|
+
ArgumentError.new("Item id should be a String") if item_id == nil
|
301
|
+
item = {} if item == nil
|
302
|
+
putRequest(item.to_json, "/plans/#{plan_id}/items/#{item_id}")
|
303
|
+
end
|
304
|
+
|
305
|
+
def self.remove_from_plan(plan_id, item_id, item)
|
306
|
+
ArgumentError.new("Plan id should be a String") if plan_id == nil
|
307
|
+
ArgumentError.new("Item id should be a String") if item_id == nil
|
308
|
+
deleteRequest("/plans/#{plan_id}/items/#{item_id}")
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
312
|
+
|
313
|
+
class MundipaggV1Sdk::Order
|
314
|
+
|
315
|
+
extend MundipaggV1Sdk
|
316
|
+
|
317
|
+
def self.create(order)
|
318
|
+
order = {} if order == nil
|
319
|
+
postRequest(order.to_json, "/orders")
|
320
|
+
end
|
321
|
+
|
322
|
+
def self.retrieve(order_id)
|
323
|
+
ArgumentError.new("Order id should be a String") if order_id == nil
|
324
|
+
getRequest("/orders/#{order_id}")
|
325
|
+
end
|
326
|
+
|
327
|
+
def self.list(customer_id = nil, page = nil, size = nil)
|
328
|
+
query = []
|
329
|
+
query << "customer_id=#{customer_id}" if !customer_id.nil?
|
330
|
+
query << "page=#{page}" if !page.nil?
|
331
|
+
query << "size=#{size}" if !size.nil?
|
332
|
+
query.first.prepend("?") if !query.empty?
|
333
|
+
getRequest("/orders#{query.join("&")}")
|
334
|
+
end
|
335
|
+
|
336
|
+
def self.include_charge(params)
|
337
|
+
params = {} if params == nil
|
338
|
+
postRequest(params.to_json, "/charges")
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
class MundipaggV1Sdk::OrderItem
|
344
|
+
|
345
|
+
extend MundipaggV1Sdk
|
346
|
+
|
347
|
+
def self.include_in_order(order_id, order_item)
|
348
|
+
ArgumentError.new("Order id should be a String") if order_id == nil
|
349
|
+
order_item = {} if order_item == nil
|
350
|
+
postRequest(order_item.to_json, "/orders/#{order_id}/items")
|
351
|
+
end
|
352
|
+
|
353
|
+
def self.edit(order_id, order_item_id, order_item)
|
354
|
+
ArgumentError.new("Order id should be a String") if order_id == nil
|
355
|
+
ArgumentError.new("Order Item id should be a String") if order_item_id == nil
|
356
|
+
order_item = {} if order_item == nil
|
357
|
+
patchRequest(order_item.to_json, "/orders/#{order_id}/items/#{order_item}")
|
358
|
+
end
|
359
|
+
|
360
|
+
def self.delete(order_id, order_item_id)
|
361
|
+
ArgumentError.new("Order id should be a String") if order_id == nil
|
362
|
+
ArgumentError.new("Order Item id should be a String") if order_item_id == nil
|
363
|
+
deleteRequest("/orders/#{order_id}/items/#{order_item}")
|
364
|
+
end
|
365
|
+
|
366
|
+
def self.delete_all_from_order(order_id)
|
367
|
+
ArgumentError.new("Order id should be a String") if order_id == nil
|
368
|
+
deleteRequest("/orders/#{order_id}/items/")
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
372
|
+
|
373
|
+
class MundipaggV1Sdk::Address
|
374
|
+
|
375
|
+
extend MundipaggV1Sdk
|
376
|
+
|
377
|
+
def self.create(address)
|
378
|
+
address = {} if address == nil
|
379
|
+
postRequest(address.to_json, "/addresses")
|
380
|
+
end
|
381
|
+
|
382
|
+
def self.retrieve(customer_id, address_id)
|
383
|
+
ArgumentError.new("Customer id should be a String") if customer == nil
|
384
|
+
ArgumentError.new("Address id should be a String") if address_id == nil
|
385
|
+
getRequest("/customers/#{customer_id}/addresses/#{address_id}")
|
386
|
+
end
|
387
|
+
|
388
|
+
def self.edit(customer_id, address_id, address)
|
389
|
+
ArgumentError.new("Customer id should be a String") if customer == nil
|
390
|
+
ArgumentError.new("Address id should be a String") if address_id == nil
|
391
|
+
address = {} if address == nil
|
392
|
+
putRequest(address.to_json, "/customers/#{customer_id}/addresses/#{address_id}")
|
393
|
+
end
|
394
|
+
|
395
|
+
def self.delete(customer_id, address_id, address)
|
396
|
+
ArgumentError.new("Customer id should be a String") if customer == nil
|
397
|
+
ArgumentError.new("Address id should be a String") if address_id == nil
|
398
|
+
deleteRequest("/customers/#{customer_id}/addresses/#{address_id}")
|
399
|
+
end
|
400
|
+
|
401
|
+
def self.list(customer_id = nil, page = nil, size = nil)
|
402
|
+
query = []
|
403
|
+
query << "page=#{page}" if !page.nil?
|
404
|
+
query << "size=#{size}" if !size.nil?
|
405
|
+
query.first.prepend("?") if !query.empty?
|
406
|
+
getRequest("/customers/#{customer_id}/addresses#{query.join("&")}")
|
407
|
+
end
|
408
|
+
|
409
|
+
end
|
410
|
+
|
411
|
+
class MundipaggV1Sdk::Subscription
|
412
|
+
|
413
|
+
extend MundipaggV1Sdk
|
414
|
+
|
415
|
+
def self.create(subscription)
|
416
|
+
subscription = {} if subscription nil
|
417
|
+
postRequest(subscription.to_json, "/subscriptions")
|
418
|
+
end
|
419
|
+
|
420
|
+
def self.create_from_plan(subscription)
|
421
|
+
ArgumentError.new("Plan id should be a String") if subscription["plan_id"] == nil
|
422
|
+
subscription = {} if subscription nil
|
423
|
+
postRequest(subscription.to_json, "/subscriptions")
|
424
|
+
end
|
425
|
+
|
426
|
+
def self.retrieve(subscription_id)
|
427
|
+
ArgumentError.new("Subscription id should be a String") if subscription_id == nil
|
428
|
+
getRequest("/subscriptions/#{subscription_id}")
|
429
|
+
end
|
430
|
+
|
431
|
+
def self.cancel(subscription_id)
|
432
|
+
ArgumentError.new("Subscription id should be a String") if subscription_id == nil
|
433
|
+
deleteRequest("/subscriptions/#{subscription_id}")
|
434
|
+
end
|
435
|
+
|
436
|
+
def self.list(customer_id = nil, plan_id = nil, credit_card_id = nil, status = nil, next_billing_at = nil, since = nil, until_ = nil, page = nil, size = nil)
|
437
|
+
query = []
|
438
|
+
query << "customer_id=#{customer_id}" if !customer_id.nil?
|
439
|
+
query << "plan_id=#{plan_id}" if !plan_id.nil?
|
440
|
+
query << "credit_card_id=#{credit_card_id}" if !credit_card_id.nil?
|
441
|
+
query << "status=#{status}" if !status.nil?
|
442
|
+
query << "next_billing_at=#{next_billing_at}" if !next_billing_at.nil?
|
443
|
+
query << "since=#{since}" if !since.nil?
|
444
|
+
query << "until=#{until_}" if !until_.nil?
|
445
|
+
query << "page=#{page}" if !page.nil?
|
446
|
+
query << "size=#{size}" if !size.nil?
|
447
|
+
query.first.prepend("?") if !query.empty?
|
448
|
+
getRequest("/subscriptions#{query.join("&")}")
|
449
|
+
end
|
450
|
+
|
451
|
+
def self.edit_credit_card(subscription_id, params)
|
452
|
+
ArgumentError.new("Subscription id should be a String") if subscription_id == nil
|
453
|
+
params = {} if params nil
|
454
|
+
patchRequest(params.to_json, "subscriptions/#{subscription_id}/credit-card")
|
455
|
+
end
|
456
|
+
|
457
|
+
def self.edit_payment_method
|
458
|
+
# PATCH
|
459
|
+
end
|
460
|
+
|
461
|
+
def edit_billing_date
|
462
|
+
# PATCH
|
463
|
+
end
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
class MundipaggV1Sdk::SubscriptionItem
|
468
|
+
|
469
|
+
extend MundipaggV1Sdk
|
470
|
+
|
471
|
+
def self.include
|
472
|
+
# POST
|
473
|
+
end
|
474
|
+
|
475
|
+
def self.edit
|
476
|
+
# PUT
|
477
|
+
end
|
478
|
+
|
479
|
+
def self.remove
|
480
|
+
# DELETE
|
481
|
+
end
|
482
|
+
|
483
|
+
end
|
484
|
+
|
485
|
+
class MundipaggV1Sdk::SubscriptionItemUsage
|
486
|
+
|
487
|
+
extend MundipaggV1Sdk
|
488
|
+
|
489
|
+
def self.include
|
490
|
+
# POST
|
491
|
+
end
|
492
|
+
|
493
|
+
def self.remove
|
494
|
+
# DELETE
|
495
|
+
end
|
496
|
+
|
497
|
+
def self.list
|
498
|
+
# GET
|
499
|
+
end
|
500
|
+
|
501
|
+
end
|
502
|
+
|
503
|
+
class MundipaggV1Sdk::SubscriptionDiscount
|
504
|
+
|
505
|
+
extend MundipaggV1Sdk
|
506
|
+
|
507
|
+
def self.include_in_subscription
|
508
|
+
# POST
|
509
|
+
end
|
510
|
+
|
511
|
+
def self.remove_from_subscription
|
512
|
+
# DELETE
|
513
|
+
end
|
514
|
+
|
515
|
+
end
|
516
|
+
|
517
|
+
class MundipaggV1Sdk::Invoice
|
518
|
+
|
519
|
+
extend MundipaggV1Sdk
|
520
|
+
|
521
|
+
def self.create(subscription_id, cycle_id)
|
522
|
+
ArgumentError.new("Subscription id should be a String") if subscription_id == nil
|
523
|
+
ArgumentError.new("Cycle id should be a String") if cycle_id == nil
|
524
|
+
invoice = {}
|
525
|
+
postRequest(invoice.to_json, "/subscriptions/#{subscription_id}/cycles/#{cycle_id}/pay")
|
526
|
+
end
|
527
|
+
|
528
|
+
def self.cancel
|
529
|
+
# DELETE
|
530
|
+
end
|
531
|
+
|
532
|
+
def self.list
|
533
|
+
# GET
|
534
|
+
end
|
535
|
+
|
536
|
+
def self.retrieve
|
537
|
+
# GET
|
538
|
+
end
|
539
|
+
|
540
|
+
end
|
541
|
+
|
542
|
+
class MundipaggV1Sdk::Token
|
543
|
+
|
544
|
+
extend MundipaggV1Sdk
|
545
|
+
|
546
|
+
def self.create(token)
|
547
|
+
token = {} if token nil
|
548
|
+
postRequest(token.to_json, "/tokens")
|
549
|
+
end
|
550
|
+
|
551
|
+
end
|
552
|
+
|
553
|
+
class MundipaggV1Sdk::Webhook
|
554
|
+
|
555
|
+
extend MundipaggV1Sdk
|
556
|
+
|
557
|
+
def self.create(hook_id)
|
558
|
+
ArgumentError.new("Webhook id should be a String") if hook_id == nil
|
559
|
+
hook = {}
|
560
|
+
postRequest(hook.to_json, "/tokens")
|
561
|
+
end
|
562
|
+
|
563
|
+
def self.retrieve
|
564
|
+
# GET
|
565
|
+
end
|
566
|
+
|
567
|
+
def self.list
|
568
|
+
# GET
|
569
|
+
end
|
570
|
+
|
571
|
+
end
|
572
|
+
|
573
|
+
class MundipaggV1Sdk::AuthenticationError
|
574
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MundipaggV1Sdk do
|
4
|
+
|
5
|
+
let(:wrong_customer) do
|
6
|
+
{
|
7
|
+
email: "user@example.com"
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:customer) do
|
12
|
+
{
|
13
|
+
"name": "Luke Skywalker",
|
14
|
+
"email": "lskywalkder@r2d2.com",
|
15
|
+
"phones": {
|
16
|
+
"home_phone": {
|
17
|
+
"country_code": "55",
|
18
|
+
"number": "000000000",
|
19
|
+
"area_code": "021"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"document": "26224451990",
|
23
|
+
"type": "individual",
|
24
|
+
"birthdate": "2000-09-09",
|
25
|
+
"metadata": {
|
26
|
+
"id": "my_customer_id"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:wrong_card) do
|
32
|
+
{
|
33
|
+
email: "user@example.com"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:card) do
|
38
|
+
{
|
39
|
+
"number": "4716020721549330",
|
40
|
+
"holder_name": "Tony Stark",
|
41
|
+
"exp_month": 1,
|
42
|
+
"exp_year": 18,
|
43
|
+
"cvv": "331",
|
44
|
+
"billing_address": {
|
45
|
+
"street": "Malibu Point",
|
46
|
+
"number": "10880",
|
47
|
+
"zip_code": "90265",
|
48
|
+
"neighborhood": "Central Malibu",
|
49
|
+
"city": "Malibu",
|
50
|
+
"state": "CA",
|
51
|
+
"country": "US"
|
52
|
+
},
|
53
|
+
"options": {
|
54
|
+
"verify_card": true
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "MundipaggV1Sdk::Customer" do
|
60
|
+
|
61
|
+
before do
|
62
|
+
@created_customer = MundipaggV1Sdk::Customer.create( customer )
|
63
|
+
@listed_customers = MundipaggV1Sdk::Customer.list
|
64
|
+
@retrieved_customer = MundipaggV1Sdk::Customer.retrieve( @created_customer["id"] )
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#create" do
|
68
|
+
|
69
|
+
context "Failing creation" do
|
70
|
+
|
71
|
+
it "should not create Customer" do
|
72
|
+
expect{ MundipaggV1Sdk::Customer.create(nil) }.to raise_error(Exception)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not create Customer" do
|
76
|
+
expect{ MundipaggV1Sdk::Customer.create(wrong_customer) }.to raise_error(Exception)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "Successful creation" do
|
82
|
+
|
83
|
+
subject { @created_customer }
|
84
|
+
|
85
|
+
it "should exist a created customer" do
|
86
|
+
expect( subject != nil && subject["id"] != nil ).to eq(true)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#list" do
|
94
|
+
|
95
|
+
context "Successful listing" do
|
96
|
+
|
97
|
+
subject { @listed_customers }
|
98
|
+
|
99
|
+
it "should exist a list of Customers" do
|
100
|
+
expect( subject != nil && subject.length > 0 && subject.include?( @created_customer ) ).to eq(true)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#retrieve" do
|
108
|
+
|
109
|
+
context "Successful retrieval" do
|
110
|
+
|
111
|
+
subject { @retrieved_customer }
|
112
|
+
|
113
|
+
it "should exist a retrieved Customer" do
|
114
|
+
expect( subject != nil && subject["email"] == customer[:email] ).to eq(true)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "MundipaggV1Sdk::Card" do
|
124
|
+
|
125
|
+
before do
|
126
|
+
@created_customer = MundipaggV1Sdk::Customer.create( customer )
|
127
|
+
@created_card = MundipaggV1Sdk::Card.create(@created_customer["id"], card)
|
128
|
+
@retrieved_card = MundipaggV1Sdk::Card.retrieve(@created_customer["id"], @created_card["id"])
|
129
|
+
@listed_cards = MundipaggV1Sdk::Card.list(@created_customer["id"])
|
130
|
+
@deleted_cards = []
|
131
|
+
@listed_cards.each do |c|
|
132
|
+
@deleted_cards << MundipaggV1Sdk::Card.delete(@created_customer["id"], c["id"])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#create" do
|
137
|
+
|
138
|
+
context "Failing creation" do
|
139
|
+
|
140
|
+
it "should not create Card" do
|
141
|
+
expect{ MundipaggV1Sdk::Card.create(nil, nil) }.to raise_error(Exception)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should not create Card" do
|
145
|
+
expect{ MundipaggV1Sdk::Card.create(nil, wrong_card) }.to raise_error(Exception)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not create Card" do
|
149
|
+
expect{ MundipaggV1Sdk::Card.create("", wrong_card) }.to raise_error(Exception)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should not create Card" do
|
153
|
+
expect{ MundipaggV1Sdk::Card.create("", wrong_card) }.to raise_error(Exception)
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
context "Successful creation" do
|
159
|
+
|
160
|
+
subject { @created_card }
|
161
|
+
|
162
|
+
it "should exist a created Card" do
|
163
|
+
expect( subject != nil && subject["id"] != nil ).to eq(true)
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "#retrieve" do
|
171
|
+
|
172
|
+
context "Failing retrieval" do
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
context "Successful retrieval" do
|
177
|
+
|
178
|
+
subject { @retrieved_card }
|
179
|
+
|
180
|
+
it "should exist a retrieved Card" do
|
181
|
+
expect( subject != nil && subject["id"] != nil ).to eq(true)
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#list" do
|
189
|
+
|
190
|
+
context "Successful listing" do
|
191
|
+
|
192
|
+
subject { @listed_cards }
|
193
|
+
|
194
|
+
it "should exist a list of customer Cards" do
|
195
|
+
expect( subject ).to_not be_nil
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#delete" do
|
203
|
+
|
204
|
+
context "Successful deletion" do
|
205
|
+
|
206
|
+
subject { @deleted_cards }
|
207
|
+
|
208
|
+
it "all cards should be deleted" do
|
209
|
+
expect( subject ).to all( satisfy{ |c| c["status"] == "deleted" } )
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "MundipaggV1Sdk::Charge" do
|
219
|
+
|
220
|
+
before do
|
221
|
+
@listed_charges = MundipaggV1Sdk::Charge.list("123")
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "#list" do
|
225
|
+
|
226
|
+
context "Successful listing" do
|
227
|
+
|
228
|
+
subject { @listed_charges }
|
229
|
+
|
230
|
+
it "should exist a list of Charges" do
|
231
|
+
expect( !subject.nil? && subject.length > 0 ).to_not be_nil
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "MundipaggV1Sdk::Token" do
|
241
|
+
|
242
|
+
before do
|
243
|
+
@created_customer = MundipaggV1Sdk::Customer.create( customer )
|
244
|
+
@created_card = MundipaggV1Sdk::Card.create(@created_customer["id"], card)
|
245
|
+
@retrieved_card = MundipaggV1Sdk::Card.retrieve(@created_customer["id"], @created_card["id"])
|
246
|
+
@listed_cards = MundipaggV1Sdk::Card.list(@created_customer["id"])
|
247
|
+
@deleted_cards = []
|
248
|
+
@listed_cards.each do |c|
|
249
|
+
@deleted_cards << MundipaggV1Sdk::Card.delete(@created_customer["id"], c["id"])
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe "#create" do
|
254
|
+
|
255
|
+
context "Failing creation" do
|
256
|
+
|
257
|
+
it "should not create Card" do
|
258
|
+
expect{ MundipaggV1Sdk::Card.create(nil, nil) }.to raise_error(Exception)
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should not create Card" do
|
262
|
+
expect{ MundipaggV1Sdk::Card.create(nil, wrong_card) }.to raise_error(Exception)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should not create Card" do
|
266
|
+
expect{ MundipaggV1Sdk::Card.create("", wrong_card) }.to raise_error(Exception)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should not create Card" do
|
270
|
+
expect{ MundipaggV1Sdk::Card.create("", wrong_card) }.to raise_error(Exception)
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
context "Successful creation" do
|
276
|
+
|
277
|
+
subject { @created_card }
|
278
|
+
|
279
|
+
it "should exist a created Card" do
|
280
|
+
expect( subject != nil && subject["id"] != nil ).to eq(true)
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mundipagg_v1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marmotex
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: New mundipagg api
|
84
|
+
email: admin@marmotex.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- lib/gateway/customer.rb
|
90
|
+
- lib/mundipagg_v1_sdk.rb
|
91
|
+
- spec/mundipagg_v1_sdk_spec.rb
|
92
|
+
homepage: http://rubygems.org/gems/mundipagg_v1
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.6.12
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: New mundipagg api
|
116
|
+
test_files:
|
117
|
+
- spec/mundipagg_v1_sdk_spec.rb
|