public class GerarPix {
static public void gerarPix(int valor){
Credentials credentials = new Credentials();
JSONObject options = new JSONObject();
options.put("client_id", credentials.getClientId());
options.put("client_secret", credentials.getClientSecret());
options.put("pix_cert", credentials.getCertificadoPix());
options.put("sandbox", credentials.isSandbox());
JSONObject body = new JSONObject();
body.put("calendario", new JSONObject().put("expiracao", 3600));
//body.put("devedor", new JSONObject().put("cpf", "94271564656").put("nome", "Gorbadoc Oldbuck"));
body.put("valor", new JSONObject().put("original", valor));
body.put("chave", "sua_chave");
try {
Gerencianet gn = new Gerencianet(options);
JSONObject response = gn.call("pixCreateImmediateCharge", new HashMap(), body);
System.out.println(response);
}catch (GerencianetException e){
System.out.println(e.getError());
System.out.println(e.getErrorDescription());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
static public void gerarQrCode(String locId){
Credentials credentials = new Credentials();
HashMap options = new HashMap();
options.put("client_id", credentials.getClientId());
options.put("client_secret", credentials.getClientSecret());
options.put("pix_cert", credentials.getCertificadoPix());
options.put("sandbox", credentials.isSandbox());
HashMap params = new HashMap();
params.put("id", locId );
try {
Gerencianet gn = new Gerencianet(options);
Map response = gn.call("pixGenerateQRCode", params, new HashMap());
File outputfile = new File("qrCodeImage.png");
ImageIO.write(ImageIO.read(new ByteArrayInputStream(javax.xml.bind.DatatypeConverter.parseBase64Binary(((String) response.get("imagemQrcode")).split(",")[1]))), "png", outputfile);
Desktop desktop = Desktop.getDesktop();
desktop.open(outputfile);
}catch (GerencianetException e){
System.out.println(e.getError());
System.out.println(e.getErrorDescription());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}