mp_api 1.0.1 → 1.2.0
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/card.rb +46 -0
- data/lib/mp_api/client.rb +8 -0
- data/lib/mp_api/customer.rb +54 -0
- data/lib/mp_api/payment.rb +23 -9
- data/lib/mp_api/version.rb +1 -1
- data/lib/mp_api.rb +3 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acb1327c5e7bdeb10e34f09b348fff419d38451506f7f4e18f75bdeeceec5294
|
4
|
+
data.tar.gz: 170333900c1568e4937e0dbd5b333ea764f1f548871acaab5dd1825e238c6605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77a6f9bc3cdce5dfddf47c90dc2de04af4b3f0da903cbd502c41325cdf910f9573a25757f22ef5dd99bcd822841cfd9cd23aa88950fac49315539f45ae4569cc
|
7
|
+
data.tar.gz: de19a66ddb638012c114f1df58b679affe37be5345ab418253c37bb8376f99b0634181353a26ce3ca61c5dca093c5fa0eec926a39fc8fc32beccb6208b63234c
|
data/lib/mp_api/card.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module MpApi
|
2
|
+
class Card
|
3
|
+
attr_reader :token, :customer_id, :external_id, :cardholder_name, :expiration_month, :expiration_year, :first_six_digits, :last_four_digits, :issuer_id, :mp_payment_method_id, :error, :error_detail
|
4
|
+
|
5
|
+
def initialize(token: nil, customer_id: nil, external_id: nil, cardholder_name: nil, expiration_month: nil, expiration_year: nil, first_six_digits: nil, last_four_digits: nil, issuer_id: nil, mp_payment_method_id: nil, error: nil, error_detail: nil)
|
6
|
+
@token = token
|
7
|
+
@customer_id = customer_id
|
8
|
+
@external_id = external_id
|
9
|
+
@cardholder_name = cardholder_name
|
10
|
+
@expiration_month = expiration_month
|
11
|
+
@expiration_year = expiration_year
|
12
|
+
@first_six_digits = first_six_digits
|
13
|
+
@last_four_digits = last_four_digits
|
14
|
+
@issuer_id = issuer_id
|
15
|
+
@mp_payment_method_id = mp_payment_method_id
|
16
|
+
@error = error
|
17
|
+
@error_detail = error_detail
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_json
|
21
|
+
{
|
22
|
+
token: token
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
response = Client.new.create_card(customer_id, JSON.dump(build_json))
|
28
|
+
self.class.new(**self.class.build_hash(response.json))
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.build_hash(response)
|
32
|
+
{
|
33
|
+
external_id: response.dig("id"),
|
34
|
+
cardholder_name: response.dig("cardholder", "name"),
|
35
|
+
expiration_month: response.dig("expiration_month"),
|
36
|
+
expiration_year: response.dig("expiration_year"),
|
37
|
+
first_six_digits: response.dig("first_six_digits"),
|
38
|
+
last_four_digits: response.dig("last_four_digits"),
|
39
|
+
issuer_id: response.dig("issuer", "id"),
|
40
|
+
mp_payment_method_id: response.dig("payment_method", "id"),
|
41
|
+
error: response.dig("message"),
|
42
|
+
error_detail: response.dig("cause")
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/mp_api/client.rb
CHANGED
@@ -35,6 +35,14 @@ module MpApi
|
|
35
35
|
get("/payment_methods") { |response| validate_response(response, "id") }
|
36
36
|
end
|
37
37
|
|
38
|
+
def create_customer(body)
|
39
|
+
post("/customers", body: body, headers: @headers) { |response| validate_response(response, "id") }
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_card(customer_id, body)
|
43
|
+
post("/customers/#{customer_id}/cards", body: body, headers: @headers) { |response| validate_response(response, "id") }
|
44
|
+
end
|
45
|
+
|
38
46
|
private
|
39
47
|
|
40
48
|
def validate_response(response, required_response_key)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MpApi
|
2
|
+
class Customer
|
3
|
+
|
4
|
+
attr_reader :external_id, :email, :first_name, :identification_type, :identification_number, :phone_area_code, :phone_number, :status, :error, :error_detail
|
5
|
+
def initialize(external_id: nil, email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil, status: nil, error: nil, error_detail: nil)
|
6
|
+
@external_id = external_id
|
7
|
+
@email = email
|
8
|
+
@first_name = first_name
|
9
|
+
@identification_type = identification_type
|
10
|
+
@identification_number = identification_number
|
11
|
+
@phone_area_code = phone_area_code
|
12
|
+
@phone_number = phone_number
|
13
|
+
@status = status
|
14
|
+
@error = error
|
15
|
+
@error_detail = error_detail
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_json
|
19
|
+
{
|
20
|
+
email: email,
|
21
|
+
first_name: first_name,
|
22
|
+
identification: {
|
23
|
+
type: identification_type,
|
24
|
+
number: identification_number
|
25
|
+
},
|
26
|
+
phone: {
|
27
|
+
area_code: phone_area_code,
|
28
|
+
number: phone_number
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def create
|
34
|
+
response = Client.new.create_customer(JSON.dump(build_json))
|
35
|
+
self.class.new(**self.class.build_hash(response.json))
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.build_hash(response)
|
39
|
+
{
|
40
|
+
external_id: response.dig("id"),
|
41
|
+
email: response.dig("email"),
|
42
|
+
first_name: response.dig("first_name"),
|
43
|
+
identification_type: response.dig("identification", "type"),
|
44
|
+
identification_number: response.dig("identification", "number"),
|
45
|
+
phone_area_code: response.dig("phone", "area_code"),
|
46
|
+
phone_number: response.dig("phone", "number"),
|
47
|
+
status: response.dig("status"),
|
48
|
+
error: response.dig("message"),
|
49
|
+
error_detail: response.dig("cause")
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/mp_api/payment.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module MpApi
|
2
2
|
class Payment
|
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
|
4
|
-
def initialize(payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, last_four_digits: nil, amount:, 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)
|
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, amount:, 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
|
@@ -32,6 +32,8 @@ module MpApi
|
|
32
32
|
@internal_error = internal_error
|
33
33
|
@capture = capture
|
34
34
|
@date_of_expiration = date_of_expiration
|
35
|
+
@saved_card = saved_card
|
36
|
+
@customer_id = customer_id
|
35
37
|
end
|
36
38
|
|
37
39
|
def build_json
|
@@ -68,13 +70,25 @@ module MpApi
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def build_json_credit_card
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
if saved_card
|
74
|
+
{
|
75
|
+
transaction_amount: amount,
|
76
|
+
token: token,
|
77
|
+
installments: installments,
|
78
|
+
payer: {
|
79
|
+
type: "customer",
|
80
|
+
id: customer_id
|
81
|
+
}
|
82
|
+
}
|
83
|
+
else
|
84
|
+
build_json_pix.merge({
|
85
|
+
capture: capture,
|
86
|
+
token: token,
|
87
|
+
issuer_id: issuer_id,
|
88
|
+
installments: installments,
|
89
|
+
three_d_secure_mode: three_d_secure_mode ? "optional" : "not_supported"
|
90
|
+
}.compact)
|
91
|
+
end
|
78
92
|
end
|
79
93
|
|
80
94
|
def create
|
data/lib/mp_api/version.rb
CHANGED
data/lib/mp_api.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "ac"
|
4
|
+
require "securerandom"
|
4
5
|
require_relative "mp_api/client"
|
5
6
|
require_relative "mp_api/payment"
|
6
7
|
require_relative "mp_api/payment_error"
|
7
8
|
require_relative "mp_api/token"
|
8
9
|
require_relative "mp_api/payment_method"
|
10
|
+
require_relative "mp_api/customer"
|
11
|
+
require_relative "mp_api/card"
|
9
12
|
require_relative "mp_api/version"
|
10
13
|
|
11
14
|
module MpApi
|
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.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todas Essas Coisas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|
@@ -37,7 +37,9 @@ files:
|
|
37
37
|
- lib/generators/mp_api/install/install_generator.rb
|
38
38
|
- lib/generators/mp_api/install/templates/initializer.rb
|
39
39
|
- lib/mp_api.rb
|
40
|
+
- lib/mp_api/card.rb
|
40
41
|
- lib/mp_api/client.rb
|
42
|
+
- lib/mp_api/customer.rb
|
41
43
|
- lib/mp_api/payment.rb
|
42
44
|
- lib/mp_api/payment_error.rb
|
43
45
|
- lib/mp_api/payment_method.rb
|
@@ -65,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
67
|
- !ruby/object:Gem::Version
|
66
68
|
version: '0'
|
67
69
|
requirements: []
|
68
|
-
rubygems_version: 3.5.
|
70
|
+
rubygems_version: 3.5.11
|
69
71
|
signing_key:
|
70
72
|
specification_version: 4
|
71
73
|
summary: ''
|