mp_api 1.2.1 → 1.3.0
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 +4 -4
- data/lib/mp_api/client.rb +9 -19
- data/lib/mp_api/payment.rb +11 -2
- data/lib/mp_api/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecd011ac10c3a5304cddfc658c65843eb2f3d7d207d2c6bc0d56aae2b22a79c0
|
4
|
+
data.tar.gz: e71a28267db159716157ea69872bff7382fdd83c2b0ef82b125ce105c0dbe2cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d86aced7158d3f6ee246b0601beb75b5f151659ac528e360587c1adbb9b9afc2cc00086e8c09d51e23144b301213b86ab9087eae22656554bd5e931053b19cff
|
7
|
+
data.tar.gz: 4b280a15c904e8f8a1f93b2c88be44d548905d80ff55f39ee94f6698696718711495bd89a0e9c81677293fe3821df315307c94bbe48431c8b566e98a094b2b87
|
data/lib/mp_api/client.rb
CHANGED
@@ -5,51 +5,41 @@ module MpApi
|
|
5
5
|
SAVE_RESPONSES = true
|
6
6
|
|
7
7
|
attr_reader :access_token
|
8
|
+
|
8
9
|
def initialize(access_token = MpApi.configuration.access_token)
|
9
|
-
@headers = {
|
10
|
-
"Content-Type" => "application/json",
|
11
|
-
"x-idempotency-key" => SecureRandom.uuid
|
12
|
-
}
|
13
10
|
super(access_token)
|
14
11
|
end
|
15
12
|
|
16
13
|
def create_payment(body)
|
17
|
-
post("/payments", body: body
|
14
|
+
post("/payments", body: body)
|
18
15
|
end
|
19
16
|
|
20
17
|
def get_payment(payment_id)
|
21
|
-
get("/payments/#{payment_id}")
|
18
|
+
get("/payments/#{payment_id}")
|
22
19
|
end
|
23
20
|
|
24
21
|
def update_payment(payment_id, body)
|
25
|
-
put("/payments/#{payment_id}", body: body
|
22
|
+
put("/payments/#{payment_id}", body: body)
|
26
23
|
end
|
27
24
|
|
28
25
|
def create_token(card_token_data)
|
29
|
-
post("/card_tokens", body: card_token_data
|
26
|
+
post("/card_tokens", body: card_token_data)
|
30
27
|
end
|
31
28
|
|
32
29
|
def search_payment_methods(query)
|
33
|
-
get("/payment_methods/search", params: query)
|
30
|
+
get("/payment_methods/search", params: query)
|
34
31
|
end
|
35
32
|
|
36
33
|
def get_payment_methods
|
37
|
-
get("/payment_methods")
|
34
|
+
get("/payment_methods")
|
38
35
|
end
|
39
36
|
|
40
37
|
def create_customer(body)
|
41
|
-
post("/customers", body: body
|
38
|
+
post("/customers", body: body)
|
42
39
|
end
|
43
40
|
|
44
41
|
def create_card(customer_id, body)
|
45
|
-
post("/customers/#{customer_id}/cards", body: body
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def validate_response(response, required_response_key)
|
51
|
-
puts response.json unless response.success?
|
52
|
-
![500, 429].include?(response.code) || response.json.dig(*required_response_key)
|
42
|
+
post("/customers/#{customer_id}/cards", body: body)
|
53
43
|
end
|
54
44
|
end
|
55
45
|
end
|
data/lib/mp_api/payment.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module MpApi
|
2
2
|
class Payment
|
3
3
|
attr_reader :status_detail, :three_ds_info_creq, :three_ds_info_external_resource_url, :three_d_secure_mode, :id, :description, :date_approved, :date_created, :money_release_date, :payer_email, :payer_identification_type, :payer_identification_number, :payment_method, :last_four_digits, :payment_type, :qr_code, :qr_code_base_64, :transaction_id, :ticket_url, :status, :amount, :token, :issuer_id, :installments, :statement_descriptor, :items, :error, :internal_error, :capture, :date_of_expiration, :saved_card, :customer_id
|
4
|
-
def initialize(payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, last_four_digits: nil,
|
4
|
+
def initialize(payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, amount:, last_four_digits: nil, status_detail: nil, three_ds_info_creq: nil, three_ds_info_external_resource_url: nil, three_d_secure_mode: nil, id: nil, description: nil, date_approved: nil, date_created: nil, money_release_date: nil, payment_type: nil, qr_code: nil, qr_code_base_64: nil, transaction_id: nil, ticket_url: nil, status: nil, token: nil, issuer_id: nil, installments: nil, items: nil, statement_descriptor: nil, error: nil, internal_error: nil, capture: nil, date_of_expiration: nil, saved_card: false, customer_id: nil)
|
5
5
|
@id = id
|
6
6
|
@description = description
|
7
7
|
@date_approved = date_approved
|
@@ -96,14 +96,23 @@ module MpApi
|
|
96
96
|
self.class.new(**self.class.build_hash(response.json))
|
97
97
|
end
|
98
98
|
|
99
|
+
def pix_paid? external_value = nil
|
100
|
+
external_value = @amount if external_value.nil?
|
101
|
+
@status == "approved" && external_value.to_d == @amount.to_d
|
102
|
+
end
|
103
|
+
|
99
104
|
def update attributes
|
100
105
|
attributes.each do |key, value|
|
101
|
-
instance_variable_set("@#{key}", value)
|
106
|
+
instance_variable_set(:"@#{key}", value)
|
102
107
|
end
|
103
108
|
Client.new.update_payment(id, JSON.dump(build_update_json))
|
104
109
|
self.class.find_by_id(id)
|
105
110
|
end
|
106
111
|
|
112
|
+
def invalidate_pix!
|
113
|
+
update(status: "cancelled")
|
114
|
+
end
|
115
|
+
|
107
116
|
def self.find_by_id(payment_id)
|
108
117
|
response = Client.new.get_payment(payment_id)
|
109
118
|
new(**build_hash(response.json))
|
data/lib/mp_api/version.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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todas Essas Coisas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|
@@ -16,15 +16,15 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
description:
|
26
|
+
version: 1.1.0
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- caioif4@gmail.com
|
30
30
|
executables: []
|
@@ -52,7 +52,7 @@ metadata:
|
|
52
52
|
homepage_uri: https://github.com/todasessascoisas/mp_api
|
53
53
|
source_code_uri: https://github.com/todasessascoisas/mp_api
|
54
54
|
changelog_uri: https://github.com/todasessascoisas/mp_api
|
55
|
-
post_install_message:
|
55
|
+
post_install_message:
|
56
56
|
rdoc_options: []
|
57
57
|
require_paths:
|
58
58
|
- lib
|
@@ -67,8 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
rubygems_version: 3.5.
|
71
|
-
signing_key:
|
70
|
+
rubygems_version: 3.5.3
|
71
|
+
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: ''
|
74
74
|
test_files: []
|