solidus_mp_dois 2.0.3 → 2.2.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/app/models/solidus_mp_dois/mp_card.rb +19 -10
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4ead0fc00f11a0e32c267a9056e87692ff2db687a4ecfc5c200f714a7cb7d2a
|
4
|
+
data.tar.gz: c8cac11c17a01ee837c6e0f6de0bb4f497e0ae85550c7676a7477c5c88fe5b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a110a136c54b7fab4626fe1d0ef2f071a6d88068cbf6d756c46326ef7e903db57a1db701a37fe888ca75a13a5660123dabc835c2f46fe1a5788eb77972347f44
|
7
|
+
data.tar.gz: 7f5df2e59d581d2b28113460535d3027b26586da7ea6a02cca32a7eb3a79c607806a3f303e9a8198429885dd69402d7380c1f3ee22069b54563301d9257940cd
|
@@ -94,24 +94,32 @@ module SolidusMpDois
|
|
94
94
|
order_user = order.try(:store_user) || order&.user # Para suportar lojas que usam Spree::User e User
|
95
95
|
return unless order_user
|
96
96
|
|
97
|
-
|
98
|
-
if
|
99
|
-
|
100
|
-
|
101
|
-
mp_customer = find_mp_customer(order_user)
|
102
|
-
end
|
103
|
-
if mp_customer.error.blank?
|
104
|
-
customer = SolidusMpDois::Customer.create(
|
97
|
+
mp_customer = find_mp_customer(order_user)
|
98
|
+
if mp_customer
|
99
|
+
# Pode ser que exista na API mas nao no banco de dados
|
100
|
+
SolidusMpDois::Customer.upsert({
|
105
101
|
external_id: mp_customer.external_id,
|
106
102
|
email: mp_customer.email,
|
107
103
|
first_name: mp_customer.first_name,
|
108
104
|
identification_type: mp_customer.identification_type,
|
109
105
|
tax_id: mp_customer.identification_number,
|
110
106
|
spree_user_id: order_user.id
|
107
|
+
}, unique_by: [:external_id]
|
108
|
+
)
|
109
|
+
else
|
110
|
+
created_mp_customer = create_mp_customer(order, source_params, order_user)
|
111
|
+
if created_mp_customer.error.blank?
|
112
|
+
SolidusMpDois::Customer.create(
|
113
|
+
external_id: created_mp_customer.external_id,
|
114
|
+
email: created_mp_customer.email,
|
115
|
+
first_name: created_mp_customer.first_name,
|
116
|
+
identification_type: created_mp_customer.identification_type,
|
117
|
+
tax_id: created_mp_customer.identification_number,
|
118
|
+
spree_user_id: order_user.id
|
111
119
|
)
|
112
120
|
end
|
113
121
|
end
|
114
|
-
|
122
|
+
SolidusMpDois::Customer.find_by(spree_user_id: order_user.id)
|
115
123
|
end
|
116
124
|
|
117
125
|
def create_mp_customer(order, source_params, user)
|
@@ -127,12 +135,13 @@ module SolidusMpDois
|
|
127
135
|
|
128
136
|
# A versão da MpApi nessa gem é limitada ("< 1.3.0") então não posso atualizar a mp_api.
|
129
137
|
# Por conta disso, precisei definir esse metodo aqui
|
138
|
+
# A limitação da versao foi removida, entao esse metodo pode ser implementado na mp_api
|
130
139
|
def find_mp_customer(user)
|
131
140
|
email = user.try(:email) || user.try(:email_address)
|
132
141
|
search_req = Typhoeus.get("https://api.mercadopago.com/v1/customers/search?email=#{email}", headers: { "Authorization" => "Bearer #{preferences[:access_token]}" })
|
133
142
|
search_response = JSON.parse(search_req.body)
|
134
143
|
customer_json = search_response["results"].find { |r| r.dig("email") == email }
|
135
|
-
MpApi::Customer.new(**MpApi::Customer.build_hash(customer_json))
|
144
|
+
MpApi::Customer.new(**MpApi::Customer.build_hash(customer_json)) if customer_json
|
136
145
|
end
|
137
146
|
|
138
147
|
def save_credit_card(card_token, customer)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_mp_dois
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todas Essas Coisas
|
@@ -27,16 +27,16 @@ dependencies:
|
|
27
27
|
name: mp_api
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
|
-
- - "
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: '0'
|
40
40
|
description: ''
|
41
41
|
email:
|
42
42
|
- ulyssesh.20@gmail.com
|