master
lucas.taia 2023-02-22 20:04:15 -03:00
parent b24418b6a6
commit adfe63ed56
2 changed files with 76 additions and 175 deletions

View File

@ -33,8 +33,6 @@ import java.util.regex.Pattern;
import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.http.entity.ContentType;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.brazilutils.br.cpfcnpj.Cnpj; import org.brazilutils.br.cpfcnpj.Cnpj;
import org.brazilutils.br.cpfcnpj.Cpf; import org.brazilutils.br.cpfcnpj.Cpf;
@ -68,7 +66,6 @@ import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox; import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Textbox; import org.zkoss.zul.Textbox;
import com.google.gson.Gson;
import com.rjconsultores.ventaboletos.constantes.ConstantesFuncionSistema; import com.rjconsultores.ventaboletos.constantes.ConstantesFuncionSistema;
import com.rjconsultores.ventaboletos.entidad.Categoria; import com.rjconsultores.ventaboletos.entidad.Categoria;
import com.rjconsultores.ventaboletos.entidad.Ciudad; import com.rjconsultores.ventaboletos.entidad.Ciudad;
@ -95,11 +92,9 @@ import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.TipoEventoExtra; import com.rjconsultores.ventaboletos.entidad.TipoEventoExtra;
import com.rjconsultores.ventaboletos.enums.TipoCstGratuidade; import com.rjconsultores.ventaboletos.enums.TipoCstGratuidade;
import com.rjconsultores.ventaboletos.enums.TipoEmail; import com.rjconsultores.ventaboletos.enums.TipoEmail;
import com.rjconsultores.ventaboletos.enums.TipoEnvioRest;
import com.rjconsultores.ventaboletos.enums.TipoOperacaoECommerce; import com.rjconsultores.ventaboletos.enums.TipoOperacaoECommerce;
import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.rest.generic.GenericRest; import com.rjconsultores.ventaboletos.rest.MercadoPagoService;
import com.rjconsultores.ventaboletos.rest.generic.RetornoGenericRest;
import com.rjconsultores.ventaboletos.service.CategoriaService; import com.rjconsultores.ventaboletos.service.CategoriaService;
import com.rjconsultores.ventaboletos.service.CiudadService; import com.rjconsultores.ventaboletos.service.CiudadService;
import com.rjconsultores.ventaboletos.service.EmpresaAdyenConfigService; import com.rjconsultores.ventaboletos.service.EmpresaAdyenConfigService;
@ -122,11 +117,9 @@ import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException;
import com.rjconsultores.ventaboletos.utilerias.SendMail.AuthType; import com.rjconsultores.ventaboletos.utilerias.SendMail.AuthType;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.vo.mercadopago.PosVO; import com.rjconsultores.ventaboletos.vo.mercadopago.PosVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoErro;
import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoPosVO; import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoPosVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoStoreVO; import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoStoreVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.StoreVO; import com.rjconsultores.ventaboletos.vo.mercadopago.StoreVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.StoreVO.Location;
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar; import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar;
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxParada; import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxParada;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
@ -1834,10 +1827,26 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
} }
public void onClick$btnCadastrarStoreMercadoPago(Event ev) throws InterruptedException { public void onClick$btnCadastrarStoreMercadoPago(Event ev) throws InterruptedException {
Object storeVO = cadastrarStoreMercadoPago(); Object storeVO = MercadoPagoService.getInstance().cadastrarStoreMercadoPago(empresa, txtNomeStore.getValue(),
txtIdStoreMercadoPago.getValue(), txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(),
txtTokenMercadoPago.getValue());
if (storeVO != null && storeVO instanceof StoreVO ) { if (storeVO != null && storeVO instanceof StoreVO) {
RetornoStoreVO retornoStoreVO = retornarStoreMercadoPago(); RetornoStoreVO retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago(
txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
boolean processing = true;
while (processing) {
for (StoreVO vo : retornoStoreVO.getResults()) {
if (storeVO.toString().equals(vo.toString())) {
processing = false;
break;
}
}
retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago(
txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(),
txtTokenMercadoPago.getValue());
}
lsStoreMercadoPago.clear(); lsStoreMercadoPago.clear();
for (StoreVO vo : retornoStoreVO.getResults()) { for (StoreVO vo : retornoStoreVO.getResults()) {
lsStoreMercadoPago.add(vo); lsStoreMercadoPago.add(vo);
@ -1845,6 +1854,9 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
BindingListModel listModel = new BindingListModelList(lsStoreMercadoPago, true); BindingListModel listModel = new BindingListModelList(lsStoreMercadoPago, true);
cmbStoreMercadoPago.setModel(listModel); cmbStoreMercadoPago.setModel(listModel);
cmbStoreCadastroMercadoPago.setModel(listModel); cmbStoreCadastroMercadoPago.setModel(listModel);
if (this.storeVO != null) {
cmbStoreMercadoPago.setSelectedIndex(lsStoreMercadoPago.indexOf(this.storeVO));
}
Messagebox.show("Store cadastrada com sucesso", Labels.getLabel("editarEmpresaController.window.title"), Messagebox.show("Store cadastrada com sucesso", Labels.getLabel("editarEmpresaController.window.title"),
Messagebox.OK, Messagebox.INFORMATION); Messagebox.OK, Messagebox.INFORMATION);
@ -1856,16 +1868,40 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
} }
public void onClick$btnCadastrarPOSMercadoPago(Event ev) throws InterruptedException { public void onClick$btnCadastrarPOSMercadoPago(Event ev) throws InterruptedException {
Object posVO = cadastrarPOSMercadoPago();
Object posVO = MercadoPagoService.getInstance().cadastrarPOSMercadoPago(txtNomePOS.getValue(),
cmbStoreCadastroMercadoPago.getSelectedItem() != null
? (StoreVO) cmbStoreCadastroMercadoPago.getSelectedItem().getValue()
: null,
txtIdPOSMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
if (posVO != null && posVO instanceof PosVO) { if (posVO != null && posVO instanceof PosVO) {
RetornoPosVO retornoPosVO = retornarPosMercadoPago(); RetornoPosVO retornoPosVO = MercadoPagoService.getInstance()
.retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
boolean processing = true;
while (processing) {
for (PosVO vo : retornoPosVO.getResults()) {
if (posVO.toString().equals(vo.toString())) {
processing = false;
break;
}
}
retornoPosVO = MercadoPagoService.getInstance().retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(),
txtTokenMercadoPago.getValue());
}
lsPosMercadoPago.clear(); lsPosMercadoPago.clear();
for (PosVO vo : retornoPosVO.getResults()) { for (PosVO vo : retornoPosVO.getResults()) {
lsPosMercadoPago.add(vo); lsPosMercadoPago.add(vo);
} }
BindingListModel listModel = new BindingListModelList(lsPosMercadoPago, true); BindingListModel listModel = new BindingListModelList(lsPosMercadoPago, true);
cmbPOSMercadoPago.setModel(listModel); cmbPOSMercadoPago.setModel(listModel);
if (this.posVO != null) {
cmbPOSMercadoPago.setSelectedIndex(lsPosMercadoPago.indexOf(this.posVO));
}
Messagebox.show("POS cadastrado com sucesso", Labels.getLabel("editarEmpresaController.window.title"), Messagebox.show("POS cadastrado com sucesso", Labels.getLabel("editarEmpresaController.window.title"),
Messagebox.OK, Messagebox.INFORMATION); Messagebox.OK, Messagebox.INFORMATION);
} else { } else {
@ -1882,15 +1918,17 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
lsStoreMercadoPago = new ArrayList<StoreVO>(); lsStoreMercadoPago = new ArrayList<StoreVO>();
lsPosMercadoPago = new ArrayList<PosVO>(); lsPosMercadoPago = new ArrayList<PosVO>();
RetornoStoreVO retornoStoreVO = retornarStoreMercadoPago(); RetornoStoreVO retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago(
txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
for (StoreVO vo : retornoStoreVO.getResults()) { for (StoreVO vo : retornoStoreVO.getResults()) {
if ( store != null && vo.toString().equals(store)) { if (store != null && vo.toString().equals(store)) {
this.storeVO = vo; this.storeVO = vo;
} }
lsStoreMercadoPago.add(vo); lsStoreMercadoPago.add(vo);
} }
RetornoPosVO retornoPosVO = retornarPosMercadoPago(); RetornoPosVO retornoPosVO = MercadoPagoService.getInstance()
.retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
for (PosVO vo : retornoPosVO.getResults()) { for (PosVO vo : retornoPosVO.getResults()) {
if (pos != null && vo.toString().equals(pos)) { if (pos != null && vo.toString().equals(pos)) {
this.posVO = vo; this.posVO = vo;
@ -1899,146 +1937,6 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
} }
} }
private Object cadastrarStoreMercadoPago() {
try {
StoreVO consulta = new StoreVO();
consulta.setName(txtNomeStore.getValue());
consulta.setExternal_id(txtIdStoreMercadoPago.getValue());
Location item = new Location();
item.setStreet_number(empresa.getNumero());
item.setStreet_name(empresa.getLogradouro());
item.setCity_name(StringUtils.capitalize(empresa.getCidade().getNombciudad().toLowerCase()));
item.setState_name(StringUtils.capitalize(empresa.getCidade().getEstado().getNombestado().toLowerCase()) );
item.setLatitude(empresa.getLatitude());
item.setLongitude(empresa.getLongitude());
item.setReference(empresa.getComplemento());
consulta.setLocation(item);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
String userId = txtUserIdMercadoPago.getValue();
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/users/" + userId + "/stores",
TipoEnvioRest.POST, new Gson().toJson(consulta).toString(), ContentType.APPLICATION_JSON,
headers, StoreVO.class, Object.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (StoreVO) resposta.getConteudo();
} else {
return resposta.getConteudoErro();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
private Object cadastrarPOSMercadoPago() {
try {
PosVO consulta = new PosVO();
consulta.setName(txtNomePOS.getValue());
consulta.setFixed_amount(false);
if (cmbStoreCadastroMercadoPago.getSelectedItem() != null) {
StoreVO storeVO = (StoreVO) cmbStoreCadastroMercadoPago.getSelectedItem().getValue();
consulta.setStore_id(storeVO.getId());
consulta.setExternal_store_id(storeVO.getExternal_id());
}
consulta.setExternal_id(txtIdPOSMercadoPago.getValue());
consulta.setCategory(5611203);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/pos",
TipoEnvioRest.POST, new Gson().toJson(consulta).toString(), ContentType.APPLICATION_JSON,
headers, PosVO.class, RetornoErro.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (PosVO) resposta.getConteudo();
} else {
return resposta.getConteudoErro();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
private RetornoStoreVO retornarStoreMercadoPago() {
try {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
String userId = txtUserIdMercadoPago.getValue();
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/users/" + userId + "/stores/search",
TipoEnvioRest.GET, null, ContentType.APPLICATION_JSON,
headers, RetornoStoreVO.class, RetornoErro.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (RetornoStoreVO) resposta.getConteudo();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
private RetornoPosVO retornarPosMercadoPago() {
try {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/pos",
TipoEnvioRest.GET, null, ContentType.APPLICATION_JSON,
headers, RetornoPosVO.class, RetornoErro.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (RetornoPosVO) resposta.getConteudo();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
public Combobox getCmbEstadoInscEstadual() { public Combobox getCmbEstadoInscEstadual() {
return cmbEstadoInscEstadual; return cmbEstadoInscEstadual;
} }

View File

@ -63,7 +63,7 @@
<tab id="tabAdyen" <tab id="tabAdyen"
label="${c:l('editarEmpresaController.lblAdyen.value')}" /> label="${c:l('editarEmpresaController.lblAdyen.value')}" />
<tab id="tabMercadoPago" <tab id="tabMercadoPago"
label="Mercado Pago" /> label="${c:l('editarEmpresaController.lblMercadoPago.value')}" />
</tabs> </tabs>
@ -2270,8 +2270,8 @@
<tabbox> <tabbox>
<tabs> <tabs>
<tab label="Geral" /> <tab label="${c:l('editarEmpresaController.lblTabGeralMercadoPago.value')}" />
<tab label="Cadastro" /> <tab label="${c:l('editarEmpresaController.lblTabCadastroMercadoPago.value')}" />
</tabs> </tabs>
<tabpanels> <tabpanels>
@ -2286,28 +2286,28 @@
<row> <row>
<label <label
value="User ID" /> value="${c:l('editarEmpresaController.lblUserIdMercadoPago.value')}" />
<textbox id="txtUserIdMercadoPago" width="80%" maxlength="255" <textbox id="txtUserIdMercadoPago" width="80%" maxlength="255"
value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.userId}" /> value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.userId}" />
</row> </row>
<row> <row>
<label <label
value="Token" /> value="${c:l('editarEmpresaController.lblUserIdMercadoPago.value')}" />
<textbox id="txtTokenMercadoPago" width="80%" maxlength="255" <textbox id="txtTokenMercadoPago" width="80%" maxlength="255"
value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.token}" /> value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.token}" />
</row> </row>
<row> <row>
<label <label
value="Url API" /> value="${c:l('editarEmpresaController.lblUrlApiMercadoPago.value')}" />
<textbox id="txtUrlApiMercadoPago" width="80%" maxlength="255" <textbox id="txtUrlApiMercadoPago" width="80%" maxlength="255"
value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.urlApi}" /> value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.urlApi}" />
</row> </row>
<row> <row>
<label <label
value="Store" /> value="${c:l('editarEmpresaController.lblStoreMercadoPago.value')}" />
<combobox id="cmbStoreMercadoPago" <combobox id="cmbStoreMercadoPago"
width="90%" mold="rounded" width="90%" mold="rounded"
buttonVisible="true" buttonVisible="true"
@ -2318,7 +2318,7 @@
<row> <row>
<label <label
value="POS" /> value="${c:l('editarEmpresaController.lblPOSMercadoPago.value')}" />
<combobox id="cmbPOSMercadoPago" <combobox id="cmbPOSMercadoPago"
width="90%" mold="rounded" width="90%" mold="rounded"
buttonVisible="true" buttonVisible="true"
@ -2348,19 +2348,20 @@
<row> <row>
<label <label
value="Nome" /> value="${c:l('editarEmpresaController.lblStoreNomeMercadoPago.value')}" />
<textbox id="txtNomeStore" width="80%" maxlength="255" /> <textbox id="txtNomeStore" width="80%" maxlength="255" />
</row> </row>
<row> <row>
<label <label
value="ID Externo" /> value="${c:l('editarEmpresaController.lblIdExternoMercadoPago.value')}" />
<textbox id="txtIdStoreMercadoPago" width="80%" maxlength="255" /> <textbox id="txtIdStoreMercadoPago" width="80%" maxlength="255" />
</row> </row>
</rows> </rows>
</grid> </grid>
<button id="btnCadastrarStoreMercadoPago" height="20" label="Cadastrar Store" /> <button id="btnCadastrarStoreMercadoPago" height="20"
label="${c:l('editarEmpresaController.lblBtnCadastrarStoreMercadoPago.value')}" />
<toolbar> <toolbar>
<separator bar="true"/> <separator bar="true"/>
POS POS
@ -2375,27 +2376,29 @@
<row> <row>
<label <label
value="Nome" /> value="${c:l('editarEmpresaController.lblPOSNomeMercadoPago.value')}" />
<textbox id="txtNomePOS" width="80%" maxlength="255" /> <textbox id="txtNomePOS" width="80%" maxlength="255" />
</row> </row>
<row> <row>
<label <label
value="ID Externo" /> value="${c:l('editarEmpresaController.lblIdExternoMercadoPago.value')}" />
<textbox id="txtIdPOSMercadoPago" width="80%" maxlength="255" /> <textbox id="txtIdPOSMercadoPago" width="80%" maxlength="255" />
</row> </row>
<row> <row>
<label <label
value="Store" /> value="${c:l('editarEmpresaController.lblStoreMercadoPago.value')}" />
<combobox id="cmbStoreCadastroMercadoPago" <combobox id="cmbStoreCadastroMercadoPago"
width="90%" mold="rounded" width="90%" mold="rounded"
buttonVisible="true" buttonVisible="true"
use="com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar"/> use="com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar"
model="@{winEditarEmpresa$composer.lsStoreMercadoPago}"/>
</row> </row>
</rows> </rows>
</grid> </grid>
<button id="btnCadastrarPOSMercadoPago" height="20" label="Cadastrar POS" /> <button id="btnCadastrarPOSMercadoPago" height="20"
label="${c:l('editarEmpresaController.lblBtnCadastrarPOSMercadoPago.value')}" />
</tabpanel> </tabpanel>
</tabpanels> </tabpanels>
</tabbox> </tabbox>