mp_api 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mp_api/client.rb +59 -54
- data/lib/mp_api/payment_method.rb +5 -1
- data/lib/mp_api/token.rb +6 -2
- data/lib/mp_api/version.rb +5 -5
- data/lib/mp_api.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7958b0b7c457103803f4add0d017a49d36e0eb420552ed406aebe9a9bb31a210
|
4
|
+
data.tar.gz: 9421b7d5e0a50e7e4552f07f6319708b7abbb92b9e34925a1e2993f790155ba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b2e88528da605933fc22078a737a6b16d48df84a57c1034850d3627a4331a0c26882a3ca786410d2a78ff1f844e0913ddeda90c3b6a05bb93fd5038decced7
|
7
|
+
data.tar.gz: bda6cb3e8f9dabd483569564f7f542d0f00490722d783ead92ef10ec634afc07e06ac494f79448c48e21b4c016036e1a5809f4b530056b07c7fbe5270f8ab8a3
|
data/lib/mp_api/client.rb
CHANGED
@@ -1,55 +1,60 @@
|
|
1
|
-
module MpApi
|
2
|
-
class Client < Ac::Base
|
3
|
-
BASE_URL = "https://api.mercadopago.com/v1/"
|
4
|
-
MAX_RETRIES = 2
|
5
|
-
attr_reader :access_token
|
6
|
-
def initialize(access_token=MpApi.configuration.access_token)
|
7
|
-
@headers = {
|
8
|
-
"Content-Type": "application/json",
|
9
|
-
'x-idempotency-key' => SecureRandom.uuid
|
10
|
-
}
|
11
|
-
super access_token
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_payment(body)
|
15
|
-
response = post("/payments", body: body, headers: @headers) do |response|
|
16
|
-
p response.json unless response.success?
|
17
|
-
![500, 429].include?(response.code) || response['id']
|
18
|
-
end
|
19
|
-
response.json
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
response
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
response
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
module MpApi
|
2
|
+
class Client < Ac::Base
|
3
|
+
BASE_URL = "https://api.mercadopago.com/v1/"
|
4
|
+
MAX_RETRIES = 2
|
5
|
+
attr_reader :access_token
|
6
|
+
def initialize(access_token=MpApi.configuration.access_token)
|
7
|
+
@headers = {
|
8
|
+
"Content-Type": "application/json",
|
9
|
+
'x-idempotency-key' => SecureRandom.uuid
|
10
|
+
}
|
11
|
+
super access_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_payment(body)
|
15
|
+
response = post("/payments", body: body, headers: @headers) do |response|
|
16
|
+
p response.json unless response.success?
|
17
|
+
![500, 429].include?(response.code) || response['id']
|
18
|
+
end
|
19
|
+
raise RequestError.new(response.json['message']) if ![200,201].include?(response.code)
|
20
|
+
response.json
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_payment(payment_id)
|
24
|
+
response = get("/payments/#{payment_id}") do |response|
|
25
|
+
p response.json unless response.success?
|
26
|
+
![500, 429].include?(response.code) || response['id']
|
27
|
+
end
|
28
|
+
raise RequestError.new(response.json['message']) if ![200,201].include?(response.code)
|
29
|
+
response.json
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_token(card_token_data)
|
33
|
+
response = post("/card_tokens", body: card_token_data, headers: @headers) do |response|
|
34
|
+
p response.json unless response.success?
|
35
|
+
![500, 429].include?(response.code) || response['id']
|
36
|
+
end
|
37
|
+
raise RequestError.new(response.json['message']) if ![200,201].include?(response.code)
|
38
|
+
response.json
|
39
|
+
end
|
40
|
+
|
41
|
+
def search_payment_methods(query)
|
42
|
+
response = get("/payment_methods/search", params: query) do |response|
|
43
|
+
p response.json unless response.success?
|
44
|
+
![500, 429].include?(response.code) || response.json['results'][0]
|
45
|
+
end
|
46
|
+
raise RequestError.new(response.json['message']) if ![200,201].include?(response.code)
|
47
|
+
response.json
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_payment_methods
|
51
|
+
response = get("/payment_methods") do |response|
|
52
|
+
p response.json unless response.success?
|
53
|
+
![500, 429].include?(response.code) || response['id']
|
54
|
+
end
|
55
|
+
raise RequestError.new(response.json['message']) if ![200,201].include?(response.code)
|
56
|
+
response.json
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
55
60
|
end
|
@@ -3,7 +3,11 @@ module MpApi
|
|
3
3
|
class PaymentMethod
|
4
4
|
|
5
5
|
def self.find_by_first_six_digits(first_six_digits, credit: true)
|
6
|
-
|
6
|
+
begin
|
7
|
+
response = Client.new.search_payment_methods(build_query(first_six_digits))
|
8
|
+
rescue RuntimeError => e
|
9
|
+
e.message == 'Too many retries' ? raise(TooManyRequestsError) : raise(e)
|
10
|
+
end
|
7
11
|
new(**build_hash(response, credit))
|
8
12
|
end
|
9
13
|
|
data/lib/mp_api/token.rb
CHANGED
@@ -25,8 +25,12 @@ module MpApi
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def create
|
28
|
-
|
29
|
-
|
28
|
+
begin
|
29
|
+
response = Client.new.create_token(JSON.dump(build_json))
|
30
|
+
self.class.new(**self.class.build_hash(response))
|
31
|
+
rescue RuntimeError => e
|
32
|
+
e.message == 'Too many retries' ? raise(TooManyRequestsError) : raise(e)
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
def self.build_hash(response)
|
data/lib/mp_api/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MpApi
|
4
|
-
VERSION = "0.1.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MpApi
|
4
|
+
VERSION = "0.1.9"
|
5
|
+
end
|
data/lib/mp_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mp_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
rubygems_version: 3.4.
|
67
|
+
rubygems_version: 3.4.6
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: ''
|