solidus_mp_dois 2.1.0 → 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 +18 -10
- metadata +1 -1
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)
|
@@ -133,7 +141,7 @@ module SolidusMpDois
|
|
133
141
|
search_req = Typhoeus.get("https://api.mercadopago.com/v1/customers/search?email=#{email}", headers: { "Authorization" => "Bearer #{preferences[:access_token]}" })
|
134
142
|
search_response = JSON.parse(search_req.body)
|
135
143
|
customer_json = search_response["results"].find { |r| r.dig("email") == email }
|
136
|
-
MpApi::Customer.new(**MpApi::Customer.build_hash(customer_json))
|
144
|
+
MpApi::Customer.new(**MpApi::Customer.build_hash(customer_json)) if customer_json
|
137
145
|
end
|
138
146
|
|
139
147
|
def save_credit_card(card_token, customer)
|