mp_api 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ef5ce1e7629dec0502dc357420093b7d839cf915040acd6acc7fcc78f0e7d59
4
- data.tar.gz: 3642209f573836df569a5df2c1e97d4f57ce7e3593dc89bef91bf9afccca5a51
3
+ metadata.gz: 3ebe10713a556b992e763bf6a0a4a418102bfe8469f27d88845d3df70171126d
4
+ data.tar.gz: 59f0cd67ff1deec0b91fcd319faa64b9be9e8684f1fb53a5fed516c95dde00a1
5
5
  SHA512:
6
- metadata.gz: '092cf8f0854dba266cdd79726e80913eec63f0f2ad4e81acec4baa5165498f740ea78024d47007c3d1fc8ece0862405f04619da096f582aa338b410fa8a081f7'
7
- data.tar.gz: 8866700ae106af20bbd742921834f4a3413b117ea9dbe3aad26ebfb54ea9a78e9ff89d96bc18c917c1e8b39cdad379f7dcac133c6827ada892834591eb600f38
6
+ metadata.gz: a8e4ea23197bd836248a98d8b7c3d0aef5c1f1fb235ca0fe48389cc8449d0d91a2bc27206fc5f7f8f1cffe5cfb4eeda5e7ec5201167819d2c3eca62eff03fc98
7
+ data.tar.gz: 32cd3dba045043c7e99de755d29874f5e009a4b90ea3d260d6c71c6651ecf48117b97765953ee9696555f80c403c1b8a34d8d29cc66c3342dd4375f25ecfb62f
data/lib/mp_api/client.rb CHANGED
@@ -19,6 +19,10 @@ module MpApi
19
19
  get("/payments/#{payment_id}") { |response| validate_response(response, 'id')}
20
20
  end
21
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
+
22
26
  def create_token(card_token_data)
23
27
  post("/card_tokens", body: card_token_data, headers: @headers) { |response| validate_response(response, 'id')}
24
28
  end
@@ -1,8 +1,8 @@
1
1
  module MpApi
2
2
  class Payment
3
3
 
4
- 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, :errors
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)
4
+ 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, :errors, :capture, :date_of_expiration
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)
6
6
  @id = id
7
7
  @description = description
8
8
  @date_approved = date_approved
@@ -29,19 +29,31 @@ module MpApi
29
29
  @statement_descriptor = statement_descriptor
30
30
  @items = items
31
31
  @errors = errors
32
+ @capture = capture
33
+ @date_of_expiration = date_of_expiration
32
34
  end
33
35
 
34
36
  def build_json
35
37
  send("build_json_#{payment_method == 'pix' ? 'pix' : 'credit_card'}").except(:description)
36
38
  end
37
39
 
40
+ def build_update_json
41
+ {
42
+ # capture: capture,
43
+ status: status,
44
+ # date_of_expiration: date_of_expiration,
45
+ # transaction_amount: amount
46
+ }.compact
47
+ end
48
+
38
49
  def build_json_pix
39
50
  {
51
+ date_of_expiration: date_of_expiration,
40
52
  transaction_amount: amount,
41
53
  description: description,
42
54
  statement_descriptor: statement_descriptor,
43
55
  additional_info: {
44
- items: @items
56
+ items: items
45
57
  },
46
58
  payment_method_id: payment_method,
47
59
  payer: {
@@ -51,23 +63,32 @@ module MpApi
51
63
  number: payer_identification_number
52
64
  }
53
65
  }
54
- }
66
+ }.compact
55
67
  end
56
68
 
57
69
  def build_json_credit_card
58
70
  build_json_pix.merge({
71
+ capture: capture,
59
72
  token: token,
60
73
  issuer_id: issuer_id,
61
74
  installments: installments,
62
75
  three_d_secure_mode: three_d_secure_mode ? 'optional' : 'not_supported'
63
- })
76
+ }.compact)
64
77
  end
65
78
 
66
79
  def create
67
80
  response = Client.new.create_payment(JSON.dump(build_json))
68
81
  self.class.new(**self.class.build_hash(response.json))
69
82
  end
70
-
83
+
84
+ def update attributes
85
+ attributes.each do |key, value|
86
+ instance_variable_set("@#{key}", value)
87
+ end
88
+ Client.new.update_payment(id, JSON.dump(build_update_json))
89
+ self.class.find_by_id(self.id)
90
+ end
91
+
71
92
  def self.find_by_id(payment_id)
72
93
  response = Client.new.get_payment(payment_id)
73
94
  new(**build_hash(response.json))
@@ -30,7 +30,7 @@ module MpApi
30
30
  'cc_rejected_insufficient_amount' => 'Recusado por quantia insuficiente.',
31
31
  'cc_rejected_call_for_authorize' => 'Recusado, ligue para a administradora do cartão para autorizar.',
32
32
  'cc_rejected_other_reason' => 'Recusado por erro geral'
33
- }
33
+ }[status_detail]
34
34
  end
35
35
 
36
36
  def message_by_error_code(code)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MpApi
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.5"
5
5
  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.3
4
+ version: 0.3.5
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-04 00:00:00.000000000 Z
11
+ date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ac