unit ChavePixEndpoints;

interface

uses
  Classes, Conexoes, IdHTTP, XSuperObject, IdGlobal, Vcl.Dialogs, System.SysUtils, Forms,
  MainCode, ViewDetail, ViewCreateImmediateCharge;

Procedure SGetV2GnEvp;
Procedure SPostV2GnEvp;
Procedure SDelV2GnEvp_chave;

implementation

threadvar
  HttpClient: TIdHTTP;
  AccessToken, ObjResult : iSuperObject;
  JsonToSend: TMemoryStream;

procedure SGetV2GnEvp;
var
  sResponse: string;
begin
  try
    AccessToken := Conexoes.OauthToken;
    HttpClient := Conexoes.SetupClient;

    HttpClient.Request.CustomHeaders.Values['Authorization'] := ('Bearer '+ AccessToken.S['access_token']);
    sResponse := HttpClient.Get( MainCode.MainFrm.Enviroment + '/v2/gn/evp');

    MainCode.MainFrm.MemoResponse.text := sresponse;

  except
    on E: Exception do
    begin
      ShowMessage('Erro na Requisião GET /v2/gn/evp '#13#10#13#10 + e.Message);
    end;
  end;
end;

procedure SPostV2GnEvp;
Const
  Body = '{}';
var
  sResponse: string;
begin
  try
    AccessToken := Conexoes.OauthToken;
    HttpClient := Conexoes.SetupClient;

    HttpClient.Request.CustomHeaders.Values['Authorization'] := ('Bearer '+ AccessToken.S['access_token']);

    JsonToSend := TMemoryStream.Create;
    WriteStringToStream(JsonToSend, Body, IndyTextEncoding_UTF8);
    //WriteStringToStream(JsonToSend, ModalParametrosBodyCob.Body, IndyTextEncoding_UTF8);
    JsonToSend.Position := 0;

    sResponse := HttpClient.Post( MainCode.MainFrm.Enviroment + '/v2/gn/evp', JsonToSend);

    MainCode.MainFrm.MemoResponse.text := sresponse;

  except
    on E: Exception do
    begin
      ShowMessage('Erro na Requisião POST /v2/gn/evp '#13#10#13#10 + e.Message);
    end;
  end;
end;

procedure SDelV2GnEvp_chave;
var
  sResponse: string;
begin
  try
    try
     if not Assigned(ModalParametrosIdent) then
        Application.CreateForm(TModalParametrosIdent, ModalParametrosIdent);

      if ModalParametrosIdent.ShowModal = 1 then
      begin
        AccessToken := Conexoes.OauthToken;
        HttpClient := Conexoes.SetupClient;

        HttpClient.Request.CustomHeaders.Values['Authorization'] := ('Bearer '+ AccessToken.S['access_token']);

        sResponse := HttpClient.Delete(MainCode.MainFrm.Enviroment + '/v2/gn/evp/'+ ModalParametrosIdent.Identificador);

        MainCode.MainFrm.MemoResponse.text := sresponse;

      end;
    except
      on E: Exception do
      begin
        ShowMessage('Erro na requisição DELETE /v2/gn/evp '#13#10#13#10 + e.Message);
      end;
    end;
  finally
    ModalParametrosIdent.txtIdent.Text := '';
  end;
end;


end.
