mp_api 0.3.5 → 0.3.6
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/generators/mp_api/install/templates/initializer.rb +1 -1
- data/lib/mp_api/client.rb +45 -46
- data/lib/mp_api/payment.rb +32 -30
- data/lib/mp_api/payment_error.rb +20 -112
- data/lib/mp_api/payment_method.rb +10 -14
- data/lib/mp_api/token.rb +8 -11
- data/lib/mp_api/version.rb +5 -5
- data/lib/mp_api.rb +3 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af6c473fbc12cab2fcc872a734480743f6da9e938f0289f58bcdf4b07275a9dd
|
4
|
+
data.tar.gz: 8c37b5e63d81b7187358db698480c57fcd5e8089c5ae06ec8407e9074420aaae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2a9a0bdabd4326ddf2167258bf8584d5efa6c7ddc03bd5c6cf85fd9fe7a6353fc29935ce4268033acae052fcb3e03852e1b12289a86b9b31f7022d352605b1
|
7
|
+
data.tar.gz: 85ae787be3b4461d11bfc97f88def20b582e3d04d934e2fc785b862a7f26c28ea269aac143177a216c1ae8809b4e1a87ce4005a089d57450444115d79fb6caae
|
data/lib/mp_api/client.rb
CHANGED
@@ -1,46 +1,45 @@
|
|
1
|
-
module MpApi
|
2
|
-
class Client < Ac::Base
|
3
|
-
BASE_URL = "https://api.mercadopago.com/v1/"
|
4
|
-
MAX_RETRIES = 1
|
5
|
-
attr_reader :access_token
|
6
|
-
def initialize(access_token=MpApi.configuration.access_token)
|
7
|
-
@headers = {
|
8
|
-
"Content-Type"
|
9
|
-
|
10
|
-
}
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_payment(body)
|
15
|
-
post("/payments", body: body, headers: @headers) { |response| validate_response(response,
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_payment(payment_id)
|
19
|
-
get("/payments/#{payment_id}") { |response| validate_response(response,
|
20
|
-
end
|
21
|
-
|
22
|
-
def update_payment(payment_id, body)
|
23
|
-
put("/payments/#{payment_id}", body: body, headers: @headers) { |response| validate_response(response,
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_token(card_token_data)
|
27
|
-
post("/card_tokens", body: card_token_data, headers: @headers) { |response| validate_response(response,
|
28
|
-
end
|
29
|
-
|
30
|
-
def search_payment_methods(query)
|
31
|
-
get("/payment_methods/search", params: query) { |response| validate_response(response, [
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_payment_methods
|
35
|
-
get("/payment_methods") { |response| validate_response(response,
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def validate_response(response, required_response_key)
|
41
|
-
puts response.json unless response.success?
|
42
|
-
![500, 429].include?(response.code) || response.json.dig(*required_response_key)
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
end
|
1
|
+
module MpApi
|
2
|
+
class Client < Ac::Base
|
3
|
+
BASE_URL = "https://api.mercadopago.com/v1/"
|
4
|
+
MAX_RETRIES = 1
|
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
|
+
post("/payments", body: body, headers: @headers) { |response| validate_response(response, "id") }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_payment(payment_id)
|
19
|
+
get("/payments/#{payment_id}") { |response| validate_response(response, "id") }
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_payment(payment_id, body)
|
23
|
+
put("/payments/#{payment_id}", body: body, headers: @headers) { |response| validate_response(response, "id") }
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_token(card_token_data)
|
27
|
+
post("/card_tokens", body: card_token_data, headers: @headers) { |response| validate_response(response, "id") }
|
28
|
+
end
|
29
|
+
|
30
|
+
def search_payment_methods(query)
|
31
|
+
get("/payment_methods/search", params: query) { |response| validate_response(response, ["results", 0]) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_payment_methods
|
35
|
+
get("/payment_methods") { |response| validate_response(response, "id") }
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def validate_response(response, required_response_key)
|
41
|
+
puts response.json unless response.success?
|
42
|
+
![500, 429].include?(response.code) || response.json.dig(*required_response_key)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/mp_api/payment.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module MpApi
|
2
2
|
class Payment
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(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, payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, payment_type:nil, qr_code:nil, qr_code_base_64:nil, transaction_id:nil, ticket_url:nil, status:nil, amount:, token:nil, issuer_id:nil, installments:nil, items:nil, statement_descriptor:nil, errors: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, :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:, 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)
|
6
5
|
@id = id
|
7
6
|
@description = description
|
8
7
|
@date_approved = date_approved
|
@@ -28,19 +27,20 @@ module MpApi
|
|
28
27
|
@status_detail = status_detail
|
29
28
|
@statement_descriptor = statement_descriptor
|
30
29
|
@items = items
|
31
|
-
@
|
30
|
+
@error = error
|
31
|
+
@internal_error = internal_error
|
32
32
|
@capture = capture
|
33
33
|
@date_of_expiration = date_of_expiration
|
34
34
|
end
|
35
35
|
|
36
36
|
def build_json
|
37
|
-
send("build_json_#{payment_method ==
|
37
|
+
send("build_json_#{(payment_method == "pix") ? "pix" : "credit_card"}").except(:description)
|
38
38
|
end
|
39
39
|
|
40
40
|
def build_update_json
|
41
41
|
{
|
42
42
|
# capture: capture,
|
43
|
-
status: status
|
43
|
+
status: status
|
44
44
|
# date_of_expiration: date_of_expiration,
|
45
45
|
# transaction_amount: amount
|
46
46
|
}.compact
|
@@ -72,21 +72,21 @@ module MpApi
|
|
72
72
|
token: token,
|
73
73
|
issuer_id: issuer_id,
|
74
74
|
installments: installments,
|
75
|
-
three_d_secure_mode: three_d_secure_mode ?
|
75
|
+
three_d_secure_mode: three_d_secure_mode ? "optional" : "not_supported"
|
76
76
|
}.compact)
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def create
|
80
80
|
response = Client.new.create_payment(JSON.dump(build_json))
|
81
81
|
self.class.new(**self.class.build_hash(response.json))
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def update attributes
|
85
85
|
attributes.each do |key, value|
|
86
86
|
instance_variable_set("@#{key}", value)
|
87
87
|
end
|
88
88
|
Client.new.update_payment(id, JSON.dump(build_update_json))
|
89
|
-
self.class.find_by_id(
|
89
|
+
self.class.find_by_id(id)
|
90
90
|
end
|
91
91
|
|
92
92
|
def self.find_by_id(payment_id)
|
@@ -95,27 +95,29 @@ module MpApi
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def self.build_hash json_response
|
98
|
+
payment_error = PaymentError.new(json_response: json_response)
|
98
99
|
{
|
99
|
-
id: json_response.dig(
|
100
|
-
description: json_response.dig(
|
101
|
-
date_approved: json_response.dig(
|
102
|
-
date_created: json_response.dig(
|
103
|
-
money_release_date: json_response.dig(
|
104
|
-
payer_email: json_response.dig(
|
105
|
-
payer_identification_type: json_response.dig(
|
106
|
-
payer_identification_number: json_response.dig(
|
107
|
-
payment_method: json_response.dig(
|
108
|
-
payment_type: json_response.dig(
|
109
|
-
qr_code: json_response.dig(
|
110
|
-
qr_code_base_64: json_response.dig(
|
111
|
-
three_ds_info_external_resource_url: json_response.dig(
|
112
|
-
three_ds_info_creq: json_response.dig(
|
113
|
-
transaction_id: json_response.dig(
|
114
|
-
ticket_url: json_response.dig(
|
115
|
-
status: json_response.dig(
|
116
|
-
status_detail: json_response.dig(
|
117
|
-
amount: json_response.dig(
|
118
|
-
|
100
|
+
id: json_response.dig("id"),
|
101
|
+
description: json_response.dig("description"),
|
102
|
+
date_approved: json_response.dig("date_approved"),
|
103
|
+
date_created: json_response.dig("date_created"),
|
104
|
+
money_release_date: json_response.dig("money_release_date"),
|
105
|
+
payer_email: json_response.dig("payer", "email"),
|
106
|
+
payer_identification_type: json_response.dig("payer", "identification", "type"),
|
107
|
+
payer_identification_number: json_response.dig("payer", "identification", "number"),
|
108
|
+
payment_method: json_response.dig("payment_method_id"),
|
109
|
+
payment_type: json_response.dig("payment_type_id"),
|
110
|
+
qr_code: json_response.dig("point_of_interaction", "transaction_data", "qr_code"),
|
111
|
+
qr_code_base_64: json_response.dig("point_of_interaction", "transaction_data", "qr_code_base64"),
|
112
|
+
three_ds_info_external_resource_url: json_response.dig("three_ds_info", "external_resource_url"),
|
113
|
+
three_ds_info_creq: json_response.dig("three_ds_info", "creq"),
|
114
|
+
transaction_id: json_response.dig("point_of_interaction", "transaction_data", "transaction_id"),
|
115
|
+
ticket_url: json_response.dig("point_of_interaction", "transaction_data", "ticket_url"),
|
116
|
+
status: json_response.dig("status"),
|
117
|
+
status_detail: json_response.dig("status_detail"),
|
118
|
+
amount: json_response.dig("transaction_amount"),
|
119
|
+
error: payment_error.error,
|
120
|
+
internal_error: payment_error.internal_error
|
119
121
|
}
|
120
122
|
end
|
121
123
|
end
|
data/lib/mp_api/payment_error.rb
CHANGED
@@ -1,131 +1,39 @@
|
|
1
1
|
module MpApi
|
2
2
|
class PaymentError
|
3
|
-
|
4
3
|
attr_reader :json_response
|
5
4
|
def initialize(json_response:)
|
6
5
|
@json_response = json_response
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
rejected_payment_error
|
8
|
+
def error
|
9
|
+
rejected_payment_error
|
11
10
|
end
|
12
|
-
|
11
|
+
|
12
|
+
def internal_error
|
13
|
+
failed_payment_error
|
14
|
+
end
|
15
|
+
|
13
16
|
private
|
14
|
-
|
17
|
+
|
15
18
|
def rejected_payment_error
|
16
|
-
return nil unless [
|
17
|
-
|
19
|
+
return nil unless ["rejected"].include?(json_response["status"])
|
20
|
+
message_by_status_detail(json_response["status_detail"])
|
18
21
|
end
|
19
22
|
|
20
23
|
def failed_payment_error
|
21
|
-
return nil unless json_response[
|
22
|
-
json_response[
|
24
|
+
return nil unless json_response["error"]
|
25
|
+
json_response["cause"].first["description"]
|
23
26
|
end
|
24
27
|
|
25
28
|
def message_by_status_detail(status_detail)
|
26
29
|
{
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}[status_detail]
|
30
|
+
"cc_rejected_bad_filled_other" => "Pagamento recusado.",
|
31
|
+
"cc_rejected_bad_filled_date" => "Pagamento recusado. Confira a data de validade do cartão.",
|
32
|
+
"cc_rejected_bad_filled_security_code" => "Pagamento recusado. Confira o código de segurança (CVV) do cartão.",
|
33
|
+
"cc_rejected_insufficient_amount" => "Pagamento recusado. Limite insuficiente.",
|
34
|
+
"cc_rejected_call_for_authorize" => "Pagamento recusado.",
|
35
|
+
"cc_rejected_other_reason" => "Pagamento recusado."
|
36
|
+
}[status_detail] || "Pagamento recusado."
|
34
37
|
end
|
35
|
-
|
36
|
-
def message_by_error_code(code)
|
37
|
-
{
|
38
|
-
1 => "Erro nos parâmetros.",
|
39
|
-
3 => "O token deve ser de teste.",
|
40
|
-
5 => "É necessário fornecer seu access_token para prosseguir.",
|
41
|
-
23 => "Os seguintes parâmetros devem ter uma data válida e no formato (aaaa-MM-dd'T'HH:mm:ssz) date_of_expiration.",
|
42
|
-
1000 => "Número de linhas excedeu os limites.",
|
43
|
-
1001 => "O formato da data deve ser aaaa-MM-dd'T'HH:mm:ss.SSSZ.",
|
44
|
-
2001 => "Já foi enviada a mesma solicitação no último minuto.",
|
45
|
-
2002 => "Cliente não encontrado.",
|
46
|
-
2004 => "Falha ao enviar POST para a API de Transações do Gateway.",
|
47
|
-
2006 => "Token do cartão não encontrado.",
|
48
|
-
2007 => "Falha na conexão com a API de Token do Cartão.",
|
49
|
-
2009 => "O emissor do token do cartão não pode ser nulo.",
|
50
|
-
2011 => "Id do método de pagamento inválido.",
|
51
|
-
2034 => "Erro estranho do mercado pago de usuarios envolvidos, normalmente causado pelo email do pagador.",
|
52
|
-
2060 => "O cliente não pode ser igual ao coletor.",
|
53
|
-
2062 => "Token do cartão inválido.",
|
54
|
-
2067 => "Número de identificação do usuário inválido.",
|
55
|
-
2072 => "Valor inválido para transaction_amount.",
|
56
|
-
2077 => "Captura diferida não suportada.",
|
57
|
-
2123 => "Operadores inválidos envolvidos.",
|
58
|
-
2131 => "Não é possível inferir o Método de Pagamento.",
|
59
|
-
3000 => "Você deve fornecer o nome do titular do cartão com seus dados do cartão.",
|
60
|
-
3001 => "Você deve fornecer o id do emissor do cartão com seus dados do cartão.",
|
61
|
-
3003 => "Id do token do cartão inválido.",
|
62
|
-
3004 => "Parâmetro site_id inválido.",
|
63
|
-
3005 => "Ação inválida, o recurso está em um estado que não permite esta operação. Para mais informações, consulte o estado que o recurso possui.",
|
64
|
-
3006 => "Parâmetro id do token do cartão inválido.",
|
65
|
-
3007 => "O parâmetro client_id não pode ser nulo ou vazio.",
|
66
|
-
3008 => "Token do Cartão não encontrado.",
|
67
|
-
3009 => "client_id não autorizado.",
|
68
|
-
3010 => "Cartão não encontrado na lista branca.",
|
69
|
-
3011 => "Método de pagamento não encontrado.",
|
70
|
-
3012 => "Parâmetro comprimento do código de segurança inválido.",
|
71
|
-
3013 => "O parâmetro código de segurança é um campo obrigatório e não pode ser nulo ou vazio.",
|
72
|
-
3014 => "Parâmetro método de pagamento inválido.",
|
73
|
-
3015 => "Parâmetro comprimento do número do cartão inválido.",
|
74
|
-
3016 => "Parâmetro número do cartão inválido.",
|
75
|
-
3017 => "O parâmetro id do número do cartão não pode ser nulo ou vazio.",
|
76
|
-
3018 => "O parâmetro mês de vencimento não pode ser nulo ou vazio.",
|
77
|
-
3019 => "O parâmetro ano de vencimento não pode ser nulo ou vazio.",
|
78
|
-
3020 => "O parâmetro nome do titular do cartão não pode ser nulo ou vazio.",
|
79
|
-
3021 => "O parâmetro número do documento do titular do cartão não pode ser nulo ou vazio.",
|
80
|
-
3022 => "O parâmetro tipo de documento do titular do cartão não pode ser nulo ou vazio.",
|
81
|
-
3023 => "O parâmetro subtipo de documento do titular do cartão não pode ser nulo ou vazio.",
|
82
|
-
3024 => "Ação inválida - reembolso parcial não suportado para esta transação.",
|
83
|
-
3025 => "Código de autenticação inválido.",
|
84
|
-
3026 => "Id do cartão inválido para este id do método de pagamento.",
|
85
|
-
3027 => "Id do tipo de pagamento inválido.",
|
86
|
-
3028 => "Id do método de pagamento inválido.",
|
87
|
-
3029 => "Mês de vencimento do cartão inválido.",
|
88
|
-
3030 => "Ano de vencimento do cartão inválido.",
|
89
|
-
3031 => "Secure_code_id não pode ser nulo.",
|
90
|
-
3032 => "Comprimento inválido do código de segurança 3033 3034 - Validação do número do cartão inválida.",
|
91
|
-
4000 => "Atributo do cartão não pode ser nulo.",
|
92
|
-
4001 => "Atributo do id do método de pagamento não pode ser nulo.",
|
93
|
-
4002 => "Atributo do valor da transação não pode ser nulo.",
|
94
|
-
4003 => "Atributo do valor da transação deve ser numérico.",
|
95
|
-
4004 => "Atributo de parcelas não pode ser nulo.",
|
96
|
-
4005 => "Atributo de parcelas deve ser numérico.",
|
97
|
-
4006 => "Atributo do pagador está malformado.",
|
98
|
-
4007 => "Atributo do site_id não pode ser nulo.",
|
99
|
-
4012 => "Atributo do id do pagador não pode ser nulo.",
|
100
|
-
4013 => "Atributo do tipo de pagador não pode ser nulo.",
|
101
|
-
4015 => "Atributo do id de referência do método de pagamento não pode ser nulo.",
|
102
|
-
4016 => "Atributo do id de referência do método de pagamento deve ser numérico.",
|
103
|
-
4017 => "Atributo do status não pode ser nulo.",
|
104
|
-
4018 => "Atributo do id do pagamento não pode ser nulo.",
|
105
|
-
4019 => "Atributo do id do pagamento deve ser numérico.",
|
106
|
-
4020 => "Atributo notificaction_url deve ser uma URL válida.",
|
107
|
-
4021 => "Atributo notificaction_url deve ter menos de 500 caracteres.",
|
108
|
-
4022 => "Atributo metadata deve ser um JSON válido.",
|
109
|
-
4023 => "Atributo do valor da transação não pode ser nulo.",
|
110
|
-
4024 => "Atributo do valor da transação deve ser numérico.",
|
111
|
-
4025 => "Id do reembolso não pode ser nulo.",
|
112
|
-
4026 => "Valor do cupom inválido.",
|
113
|
-
4027 => "Atributo do id da campanha deve ser numérico.",
|
114
|
-
4028 => "Atributo do valor do cupom deve ser numérico.",
|
115
|
-
4029 => "Tipo de pagador inválido.",
|
116
|
-
4033 => "Número de parcelas inváido.",
|
117
|
-
4037 => "Valor da transação inválido.",
|
118
|
-
4038 => "A taxa de aplicação não pode ser maior que o valor da transação.",
|
119
|
-
4039 => "A taxa de aplicação não pode ser um valor negativo.",
|
120
|
-
4049 => "Atributo do valor da transação deve ser positivo.",
|
121
|
-
4050 => "O email do pagador deve ser um email válido.",
|
122
|
-
4051 => "O email do pagador deve ter menos de 254 caracteres.",
|
123
|
-
4390 => "O email do pagador deve ser um email válido.",
|
124
|
-
4084 => "issuer_id deve ser inteiro.",
|
125
|
-
6033 => "Usuário indisponível.",
|
126
|
-
7523 => "Data de vencimento inválida."
|
127
|
-
}[code]
|
128
|
-
end
|
129
|
-
|
130
38
|
end
|
131
|
-
end
|
39
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module MpApi
|
2
|
-
|
3
2
|
class PaymentMethod
|
4
|
-
|
5
3
|
attr_reader :payment_method_id, :issuer_id, :installments, :errors
|
6
|
-
def initialize(payment_method_id
|
4
|
+
def initialize(payment_method_id:, issuer_id:, installments:, errors: nil)
|
7
5
|
@payment_method_id = payment_method_id
|
8
6
|
@issuer_id = issuer_id
|
9
7
|
@installments = installments
|
@@ -17,23 +15,21 @@ module MpApi
|
|
17
15
|
|
18
16
|
def self.build_query(first_six_digits)
|
19
17
|
{
|
20
|
-
marketplace:
|
21
|
-
status:
|
18
|
+
marketplace: "NONE",
|
19
|
+
status: "active",
|
22
20
|
bins: first_six_digits
|
23
21
|
}
|
24
22
|
end
|
25
23
|
|
26
24
|
def self.build_hash(response, credit)
|
27
|
-
payment_type_id = credit ?
|
28
|
-
payment_method = response.dig(
|
25
|
+
payment_type_id = credit ? "credit_card" : "debit_card"
|
26
|
+
payment_method = response.dig("results")&.find { |pm| pm["payment_type_id"] == payment_type_id }
|
29
27
|
{
|
30
|
-
payment_method_id: payment_method&.dig(
|
31
|
-
issuer_id: payment_method&.dig(
|
32
|
-
installments: payment_method&.dig(
|
33
|
-
errors: response.dig(
|
28
|
+
payment_method_id: payment_method&.dig("id"),
|
29
|
+
issuer_id: payment_method&.dig("issuer", "id"),
|
30
|
+
installments: payment_method&.dig("payer_costs"),
|
31
|
+
errors: response.dig("message")
|
34
32
|
}
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
38
|
-
|
39
|
-
end
|
35
|
+
end
|
data/lib/mp_api/token.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module MpApi
|
2
|
-
|
3
2
|
class Token
|
4
|
-
|
5
3
|
attr_reader :card_number, :expiration_year, :expiration_month, :security_code, :cardholder_name, :id, :errors
|
6
|
-
def initialize(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:, id:nil, errors:nil)
|
4
|
+
def initialize(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:, id: nil, errors: nil)
|
7
5
|
@card_number = card_number
|
8
6
|
@expiration_year = expiration_year
|
9
7
|
@expiration_month = expiration_month
|
@@ -32,15 +30,14 @@ module MpApi
|
|
32
30
|
|
33
31
|
def self.build_hash(response)
|
34
32
|
{
|
35
|
-
id: response[
|
36
|
-
expiration_year: response[
|
37
|
-
expiration_month: response[
|
38
|
-
cardholder_name: response.dig(
|
39
|
-
card_number: response[
|
40
|
-
security_code: response[
|
41
|
-
errors: response[
|
33
|
+
id: response["id"],
|
34
|
+
expiration_year: response["expiration_year"],
|
35
|
+
expiration_month: response["expiration_month"],
|
36
|
+
cardholder_name: response.dig("cardholder", "name"),
|
37
|
+
card_number: response["card_number"],
|
38
|
+
security_code: response["security_code"],
|
39
|
+
errors: response["error"]
|
42
40
|
}
|
43
41
|
end
|
44
|
-
|
45
42
|
end
|
46
43
|
end
|
data/lib/mp_api/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MpApi
|
4
|
-
VERSION = "0.3.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MpApi
|
4
|
+
VERSION = "0.3.6"
|
5
|
+
end
|
data/lib/mp_api.rb
CHANGED
@@ -7,22 +7,20 @@ require_relative "mp_api/payment_error"
|
|
7
7
|
require_relative "mp_api/token"
|
8
8
|
require_relative "mp_api/payment_method"
|
9
9
|
require_relative "mp_api/version"
|
10
|
+
|
10
11
|
module MpApi
|
11
12
|
class Error < StandardError; end
|
12
13
|
|
13
14
|
class RequestError < StandardError
|
14
|
-
def initialize(message="Request error")
|
15
|
+
def initialize(message = "Request error")
|
15
16
|
super(message)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
class Configuration
|
20
21
|
attr_accessor :access_token, :public_key
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
end
|
24
22
|
end
|
25
|
-
|
23
|
+
|
26
24
|
class << self
|
27
25
|
attr_accessor :configuration
|
28
26
|
end
|
@@ -31,5 +29,4 @@ module MpApi
|
|
31
29
|
self.configuration ||= Configuration.new
|
32
30
|
yield configuration
|
33
31
|
end
|
34
|
-
|
35
32
|
end
|
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.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|