diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java index df6c8b746..397a46931 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarEmpresaController.java @@ -33,8 +33,6 @@ import java.util.regex.Pattern; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; -import org.apache.http.HttpStatus; -import org.apache.http.entity.ContentType; import org.apache.log4j.Logger; import org.brazilutils.br.cpfcnpj.Cnpj; import org.brazilutils.br.cpfcnpj.Cpf; @@ -68,7 +66,6 @@ import org.zkoss.zul.Tab; import org.zkoss.zul.Tabbox; import org.zkoss.zul.Textbox; -import com.google.gson.Gson; import com.rjconsultores.ventaboletos.constantes.ConstantesFuncionSistema; import com.rjconsultores.ventaboletos.entidad.Categoria; 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.enums.TipoCstGratuidade; import com.rjconsultores.ventaboletos.enums.TipoEmail; -import com.rjconsultores.ventaboletos.enums.TipoEnvioRest; import com.rjconsultores.ventaboletos.enums.TipoOperacaoECommerce; import com.rjconsultores.ventaboletos.exception.BusinessException; -import com.rjconsultores.ventaboletos.rest.generic.GenericRest; -import com.rjconsultores.ventaboletos.rest.generic.RetornoGenericRest; +import com.rjconsultores.ventaboletos.rest.MercadoPagoService; import com.rjconsultores.ventaboletos.service.CategoriaService; import com.rjconsultores.ventaboletos.service.CiudadService; 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.UsuarioLogado; 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.RetornoStoreVO; 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.MyComboboxParada; 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 { - Object storeVO = cadastrarStoreMercadoPago(); - - if (storeVO != null && storeVO instanceof StoreVO ) { - RetornoStoreVO retornoStoreVO = retornarStoreMercadoPago(); + Object storeVO = MercadoPagoService.getInstance().cadastrarStoreMercadoPago(empresa, txtNomeStore.getValue(), + txtIdStoreMercadoPago.getValue(), txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), + txtTokenMercadoPago.getValue()); + + if (storeVO != null && storeVO instanceof StoreVO) { + 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(); for (StoreVO vo : retornoStoreVO.getResults()) { lsStoreMercadoPago.add(vo); @@ -1845,7 +1854,10 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException { BindingListModel listModel = new BindingListModelList(lsStoreMercadoPago, true); cmbStoreMercadoPago.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.OK, Messagebox.INFORMATION); } else { @@ -1856,16 +1868,40 @@ public void onClick$btnTestEmailFlexBus(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) { - 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(); for (PosVO vo : retornoPosVO.getResults()) { lsPosMercadoPago.add(vo); } BindingListModel listModel = new BindingListModelList(lsPosMercadoPago, true); 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.OK, Messagebox.INFORMATION); } else { @@ -1881,16 +1917,18 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException { lsStoreMercadoPago = new ArrayList(); lsPosMercadoPago = new ArrayList(); - - RetornoStoreVO retornoStoreVO = retornarStoreMercadoPago(); + + RetornoStoreVO retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago( + txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue()); for (StoreVO vo : retornoStoreVO.getResults()) { - if ( store != null && vo.toString().equals(store)) { + if (store != null && vo.toString().equals(store)) { this.storeVO = vo; } lsStoreMercadoPago.add(vo); } - RetornoPosVO retornoPosVO = retornarPosMercadoPago(); + RetornoPosVO retornoPosVO = MercadoPagoService.getInstance() + .retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue()); for (PosVO vo : retornoPosVO.getResults()) { if (pos != null && vo.toString().equals(pos)) { 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 headers = new HashMap(); - 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 headers = new HashMap(); - 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 headers = new HashMap(); - 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 headers = new HashMap(); - 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() { return cmbEstadoInscEstadual; } diff --git a/web/gui/catalogos/editarEmpresa.zul b/web/gui/catalogos/editarEmpresa.zul index fcef2e9f7..bfab6a465 100644 --- a/web/gui/catalogos/editarEmpresa.zul +++ b/web/gui/catalogos/editarEmpresa.zul @@ -63,7 +63,7 @@ + label="${c:l('editarEmpresaController.lblMercadoPago.value')}" /> @@ -2270,8 +2270,8 @@ - - + + @@ -2286,28 +2286,28 @@ -