Emitir e cancelar sim, usei IdHTTP:
function Tfrm_BoletoItau.RequisicaoRestCert(BodyJson: String; var MsgRetorno: String; Requisicao: TMetodoRequisicao): Integer;
var
HTTP: TIdHTTP;
IOHandle: TIdSSLIOHandlerSocketOpenSSL;
ListParams: TStringList;
JsonStreamEnvio, Resp: TStringStream;
Jso: TJSONObject;
JsoPair: TJSONPair;
Parametros, Uri: String;
PostBoletoError: String;
PostBoletoResult: Boolean;
UriConsulta: TStringList;
begin
if (memoToken.Lines.Text = '') then
begin
PostBoletoError := 'Error: Token oAuth não gerado ou expirado!';
exit;
end;
try
ListParams := TStringList.Create;
Resp := TStringStream.Create;
UriConsulta := TStringList.Create;
HTTP := TIdHTTP.Create(Self);
HTTP.Request.BasicAuthentication := False;
HTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';
IOHandle := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
IOHandle.SSLOptions.Method := sslvTLSv1_2;
IOHandle.SSLOptions.Mode := sslmClient;
IOHandle.SSLOptions.CertFile := Cert_File;
IOHandle.SSLOptions.KeyFile := Key_File;
HTTP.IOHandler := IOHandle;
HTTP.Request.ContentType := 'application/json';
HTTP.Request.Accept := '*/*';
HTTP.Request.CharSet := 'utf-8';
HTTP.Request.CustomHeaders.FoldLines := False;
HTTP.Request.CustomHeaders.Add('Authorization: Bearer ' + memoToken.Lines.Text);
try
// Verificando qual tipo de requisição
if Requisicao = mrPost then
begin
ListParams.text := BodyJson;
JsonStreamEnvio := TStringStream.Create(ListParams.text);
HTTP.Post(Uri_Emissao, JsonStreamEnvio, Resp);
end
else if Requisicao = mrPatch then
begin
Uri := StringReplace(Uri_Baixa, '{idBoleto}', edtIdBoleto.Text, [rfReplaceAll]);
ListParams.text := '{}';
JsonStreamEnvio := TStringStream.Create(ListParams.text);
HTTP.Patch(Uri, JsonStreamEnvio, Resp);
end
else if Requisicao = mrGet then
begin
ListParams.text := '{}';
JsonStreamEnvio := TStringStream.Create(ListParams.text);
UriConsulta.Text := Uri_Consulta;
UriConsulta.Text := StringReplace(UriConsulta.Text, '{id_beneficiario}', copy(edtBoletoCons.Text, 1, 12), [rfReplaceAll]);
UriConsulta.Text := StringReplace(UriConsulta.Text, '{codigo_carteira}', copy(edtBoletoCons.Text, 13, 3), [rfReplaceAll]);
UriConsulta.Text := StringReplace(UriConsulta.Text, '{nosso_numero}' , copy(edtBoletoCons.Text, 16, 8), [rfReplaceAll]);
UriConsulta.Text := StringReplace(UriConsulta.Text, '{data_emissao}', FormatDateTime('YYYY-MM-DD',strToDate(edtDataEmissao.Text)) , [rfReplaceAll]);
HTTP.Request.CustomHeaders.FoldLines := False;
HTTP.Request.ContentType := 'application/json';
HTTP.HandleRedirects := True;
HTTP.Request.CustomHeaders.Add('Authorization: Bearer ' + memoToken.Lines.Text);
HTTP.Request.CustomHeaders.Add('x-itau-apikey:' + Client_ID);
HTTP.Request.CustomHeaders.Add('x-itau-correlationID:' + Correlation_ID);
HTTP.Request.CustomHeaders.Add('x-itau-flowID:' + '8A30E15C-1AC9-418A-AF1E-02E36BF77ADE');
Clipboard.AsText := UriConsulta.Text;
HTTP.Get(UriConsulta.Text, Resp);
end;
if HTTP.ResponseCode = 200 then
begin
PostBoletoResult := true;
try
Jso := TJSONObject.Create;
Jso.Parse(Resp.Bytes, 0);
MsgRetorno := Jso.ToString;
Result := HTTP.ResponseCode;
finally
FreeAndNil(Jso);
end;
end
else
PostBoletoError := 'Error: ' + IntToStr(HTTP.ResponseCode) + ' - ' +
Resp.DataString;
except
on e: EIdHTTPProtocolException do
begin
Result := HTTP.ResponseCode;
MsgRetorno := e.ErrorMessage;
PostBoletoError := 'Error: ' + HTTP.ResponseText + ' - ' + MsgRetorno;
end;
end;
finally
memoRetornoCons.Lines.Text := PostBoletoError;
FreeAndNil(ListParams);
FreeAndNil(Resp);
FreeAndNil(JsonStreamEnvio);
FreeAndNil(IOHandle);
FreeAndNil(HTTP);
end;
end;
Não consigo agora consultar o boleto...
Só retorna erro 403 Forbidden
Se alguem puder me ajudar nesse problema, ficarei muito grato.