solidus_mp 1.1.3 → 1.1.4

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: 98311a30487ce46ab6c068e28f4b7cf5874c8635f393d931d98796b0755a74cc
4
- data.tar.gz: 5a86d4a580f33dcfd37cb4c5a6ee1e762618fb0c8527b80df6ced2f8a185d48e
3
+ metadata.gz: d914f60f118cbe299729a75b093004c8ae369e45dcb8bdd9a8a9b3e3a32ee534
4
+ data.tar.gz: ec0f3475cfb1077bfebfd7db60a192c9ad8f4ef577a3f19970b4ce54fd978fac
5
5
  SHA512:
6
- metadata.gz: 04b6d07ee9538a2ccb43a20d78d63633dd63972dc078a87f475da0e8523c9f3fa0aad8938b3549d9905f0dddfe10063bfb3e1688a939963736f240521eb00e2f
7
- data.tar.gz: 6fbde1e5c38ced49261a77c7d1f23de10d69e225bd834dbc2deedf1b7b70c5f0d668fbecb7e161b8b243a404e64e5bf0d50b499666145915d0d06de35e691b82
6
+ metadata.gz: c9bc1695e9528fe3d22ad3699a13f5427fa9b8d6ba4ae71d9db01613047fb176aeb67ce56ea993d6d9a9acad338c73a19dc90c4066102bfef5c2071b54e3bcf5
7
+ data.tar.gz: dd4411061a19f070d61914f965fd6337867b47f802b7702ee8cd440f1caf2fa4a973adea21f907dac6e87e730be6cff3ef7aa5ad864960cdd1047336c15c2cba
@@ -1,6 +1,5 @@
1
1
  module SolidusMp
2
2
  class MpPix < Spree::PaymentMethod
3
-
4
3
  preference :public_key, :string
5
4
  preference :access_token, :string
6
5
  preference :callback_url, :string
@@ -37,15 +36,43 @@ module SolidusMp
37
36
 
38
37
  def create_mp_payment payment
39
38
  MpApi.configuration.access_token = preferences[:access_token]
40
- identification_type = payment.source.tax_id.length > 14 ? "CNPJ" : "CPF"
41
- MpApi::Payment.new(payer_email: payment.source.email, payer_identification_type: identification_type, payment_method: "pix", payer_identification_number: payment.source.tax_id, amount: payment.amount.to_f, statement_descriptor: payment.source.statement_descriptor, description: payment.source.description, items: payment.source.items).create
39
+ identification_type = (payment.source.tax_id.length > 14) ? "CNPJ" : "CPF"
40
+ mp_payment = MpApi::Payment.new(
41
+ payer_email: payment.source.email,
42
+ payer_identification_type: identification_type,
43
+ payment_method: "pix",
44
+ payer_identification_number: payment.source.tax_id,
45
+ amount: payment.amount.to_f,
46
+ statement_descriptor: payment.source.statement_descriptor,
47
+ description: payment.source.description,
48
+ items: payment.source.items
49
+ ).create
50
+ payment.response_code = mp_payment.id
51
+ payment.source.assign_attributes(
52
+ external_id: mp_payment.id,
53
+ qr_code: mp_payment.qr_code,
54
+ qr_code_base64: mp_payment.qr_code_base_64,
55
+ status: mp_payment.status,
56
+ error_message: mp_payment.internal_error
57
+ )
58
+ payment.log_entries.new(parsed_payment_response_details_with_fallback: failure_response(mp_payment.internal_error)) if mp_payment.internal_error
59
+ mp_payment
42
60
  end
43
61
 
44
62
  def cancel_payment payment
63
+ return false unless payment && payment.source.external_id
64
+ MpApi.configuration.access_token = preferences[:access_token]
65
+ mp_payment = MpApi::Payment.find_by_id(payment.source.external_id)
66
+ return false if mp_payment.pix_paid?
67
+ mp_payment.invalidate_pix!
68
+ true
69
+ end
70
+
71
+ def find_payment external_id
45
72
  MpApi.configuration.access_token = preferences[:access_token]
46
- MpApi::Payment.find_by_id(payment.source.external_id).update(status: "cancelled")
73
+ MpApi::Payment.find_by_id(external_id)
47
74
  end
48
-
75
+
49
76
  def authorize(money, source, options = {})
50
77
  purchase(money, source, options)
51
78
  end
@@ -64,15 +91,11 @@ module SolidusMp
64
91
  def should_skip_processing?(source)
65
92
  MpApi.configuration.access_token = preferences[:access_token]
66
93
  mp_payment = MpApi::Payment.find_by_id(source.external_id)
67
- if mp_payment.status == "approved"
68
- false
69
- else
70
- true
71
- end
94
+ !(mp_payment.status == "approved")
72
95
  end
73
96
 
74
97
  def partial_name
75
- 'mercado_pago_pix'
98
+ "mercado_pago_pix"
76
99
  end
77
100
 
78
101
  def successful_response message, transaction_id
@@ -90,6 +113,5 @@ module SolidusMp
90
113
  message
91
114
  )
92
115
  end
93
-
94
116
  end
95
117
  end
@@ -1,9 +1,7 @@
1
1
  module SolidusMp
2
-
3
2
  class PixPaymentSource < Spree::PaymentSource
4
-
5
3
  def actions
6
- %w(capture void credit)
4
+ %w[capture void credit]
7
5
  end
8
6
 
9
7
  def can_capture?(payment)
@@ -19,9 +17,15 @@ module SolidusMp
19
17
  end
20
18
 
21
19
  def usable?
22
- status == "pending"
20
+ status == "pending" && external_id.present? && expiration_date&.future?
23
21
  end
24
22
 
25
- end
23
+ def expired?
24
+ expiration_date.past?
25
+ end
26
26
 
27
+ def retrieve_from_api
28
+ payment_method.find_payment(external_id)
29
+ end
30
+ end
27
31
  end
@@ -0,0 +1,6 @@
1
+ class AddExpirationDateAndAmountOnPixPaymentSource < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :solidus_mp_pix_payment_sources, :expiration_date, :datetime
4
+ add_column :solidus_mp_pix_payment_sources, :amount, :decimal, precision: 10, scale: 2
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMp
4
- VERSION = '1.1.3'
4
+ VERSION = "1.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_mp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - caio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-29 00:00:00.000000000 Z
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -122,6 +122,7 @@ files:
122
122
  - db/migrate/20240715124647_create_solidus_mp_customers.rb
123
123
  - db/migrate/20240715125709_create_solidus_mp_cards.rb
124
124
  - db/migrate/20240715131005_add_saved_card_column_to_card_source.rb
125
+ - db/migrate/20241113191603_add_expiration_date_and_amount_on_pix_payment_source.rb
125
126
  - lib/generators/solidus_mp/install/install_generator.rb
126
127
  - lib/generators/solidus_mp/install/templates/app/javascript/controllers/credit_card_controller.js
127
128
  - lib/generators/solidus_mp/install/templates/app/javascript/controllers/three_ds_controller.js
@@ -148,7 +149,7 @@ metadata:
148
149
  homepage_uri: https://github.com/CaioGarcia1/solidus_mp
149
150
  source_code_uri: https://github.com/CaioGarcia1/solidus_mp
150
151
  changelog_uri: https://github.com/CaioGarcia1/solidus_mp
151
- post_install_message:
152
+ post_install_message:
152
153
  rdoc_options: []
153
154
  require_paths:
154
155
  - lib
@@ -166,8 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
167
  - !ruby/object:Gem::Version
167
168
  version: '0'
168
169
  requirements: []
169
- rubygems_version: 3.5.11
170
- signing_key:
170
+ rubygems_version: 3.5.10
171
+ signing_key:
171
172
  specification_version: 4
172
173
  summary: ''
173
174
  test_files: