solidus_mp_dois 2.1.0 → 2.2.1
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 +22 -11
- 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: edf5b999d4b30c8674da2b092a90424ad6810862252dd4bb9b3ff031e5e9bc2d
|
4
|
+
data.tar.gz: 06be7b9e220459cbc761fd6fadb4f087bb38e422a72e4ce9b1501ec8a84e685c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf5d0b8bbe7e27b8afe59adde98cf36ed5b02e74b19bbcf994b4abfcaabb0fea41a2af83597132b68cb21844ad91bb8e6ccb790210be0b57f281547aaa9e8c15
|
7
|
+
data.tar.gz: 81c7c54fe00db3dd0f612f8d58d9ba82c0e4ee6f263ccb4713312e21c48a663e4632e922b49ba9f5af176708c944e5e78c30c18a2b1f83568382f0f1325fbe2b
|
@@ -48,7 +48,10 @@ module SolidusMpDois
|
|
48
48
|
|
49
49
|
def cancel!(mp_payment_id)
|
50
50
|
MpApi.configuration.access_token = preferences[:access_token]
|
51
|
-
MpApi::Payment.find_by_id(mp_payment_id)
|
51
|
+
mp_payment = MpApi::Payment.find_by_id(mp_payment_id)
|
52
|
+
if !mp_payment.status.in?(["rejected", "cancelled"])
|
53
|
+
mp_payment.update(status: "cancelled")
|
54
|
+
end
|
52
55
|
end
|
53
56
|
|
54
57
|
private
|
@@ -94,24 +97,32 @@ module SolidusMpDois
|
|
94
97
|
order_user = order.try(:store_user) || order&.user # Para suportar lojas que usam Spree::User e User
|
95
98
|
return unless order_user
|
96
99
|
|
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(
|
100
|
+
mp_customer = find_mp_customer(order_user)
|
101
|
+
if mp_customer
|
102
|
+
# Pode ser que exista na API mas nao no banco de dados
|
103
|
+
SolidusMpDois::Customer.upsert({
|
105
104
|
external_id: mp_customer.external_id,
|
106
105
|
email: mp_customer.email,
|
107
106
|
first_name: mp_customer.first_name,
|
108
107
|
identification_type: mp_customer.identification_type,
|
109
108
|
tax_id: mp_customer.identification_number,
|
110
109
|
spree_user_id: order_user.id
|
110
|
+
}, unique_by: [:external_id]
|
111
|
+
)
|
112
|
+
else
|
113
|
+
created_mp_customer = create_mp_customer(order, source_params, order_user)
|
114
|
+
if created_mp_customer.error.blank?
|
115
|
+
SolidusMpDois::Customer.create(
|
116
|
+
external_id: created_mp_customer.external_id,
|
117
|
+
email: created_mp_customer.email,
|
118
|
+
first_name: created_mp_customer.first_name,
|
119
|
+
identification_type: created_mp_customer.identification_type,
|
120
|
+
tax_id: created_mp_customer.identification_number,
|
121
|
+
spree_user_id: order_user.id
|
111
122
|
)
|
112
123
|
end
|
113
124
|
end
|
114
|
-
|
125
|
+
SolidusMpDois::Customer.find_by(spree_user_id: order_user.id)
|
115
126
|
end
|
116
127
|
|
117
128
|
def create_mp_customer(order, source_params, user)
|
@@ -133,7 +144,7 @@ module SolidusMpDois
|
|
133
144
|
search_req = Typhoeus.get("https://api.mercadopago.com/v1/customers/search?email=#{email}", headers: { "Authorization" => "Bearer #{preferences[:access_token]}" })
|
134
145
|
search_response = JSON.parse(search_req.body)
|
135
146
|
customer_json = search_response["results"].find { |r| r.dig("email") == email }
|
136
|
-
MpApi::Customer.new(**MpApi::Customer.build_hash(customer_json))
|
147
|
+
MpApi::Customer.new(**MpApi::Customer.build_hash(customer_json)) if customer_json
|
137
148
|
end
|
138
149
|
|
139
150
|
def save_credit_card(card_token, customer)
|