function TDM1.RegistrarBoletoUnico(CodCotista, Cod_Asaas, Desc_Cobranca: string;
VlrBoleto, VlDesconto, VlMulta, VlJuros: double; DtVenc: TDate; DiasDesc: integer): integer;
var
resp: IResponse;
Json_Boleto, Json_Desconto: TJSONObject;
Arr_Desconto, Arr_Multa, Arr_Juros: TJSONArray;
Json_Multa, Json_Juros: TJSONObject;
begin
TbBoleto.FieldDefs.Clear;
try
Json_Boleto := TJSONObject.Create;
Json_Boleto.AddPair('billingType', 'BOLETO');
Json_Boleto.AddPair('customer', Cod_Asaas);
Json_Boleto.AddPair('value', TJsonNumber.Create(VlrBoleto));
Json_Boleto.AddPair('duedate', FormatDateTime('yyyy-mm-dd', DtVenc));
Json_Boleto.AddPair('description', Desc_Cobranca);
Json_Boleto.AddPair('daysAfterDueDateToRegistrationCancellation', TJsonNumber.Create(1));
Json_Boleto.AddPair('externalReference', CodCotista);
// Desconto
if VlDesconto > 0 then
begin
Arr_Desconto := TJSONArray.Create;
Json_Desconto := TJSONObject.Create;
Json_Desconto.AddPair('value', TJsonNumber.Create(VlDesconto));
Json_Desconto.AddPair('dueDateLimitDays', TJsonNumber.Create(DiasDesc));
Json_Desconto.AddPair('type', 'FIXED');
Arr_Desconto.AddElement(Json_Desconto);
Json_Boleto.AddPair('discount', Json_Desconto);
end;
// Multa
if VlMulta > 0 then
begin
Arr_Multa := TJSONArray.Create;
Json_Multa := TJSONObject.Create;
Json_Multa.AddPair('value', TJsonNumber.Create(VlMulta));
Json_Multa.AddPair('type', 'PERCENTAGE');
Arr_Multa.AddElement(Json_Multa);
Json_Boleto.AddPair('fine', Json_Multa);
end;
// Juros
if VlJuros > 0 then
begin
Arr_Juros := TJSONArray.Create;
Json_Juros := TJSONObject.Create;
Json_Juros.AddPair('value', TJsonNumber.Create(VlJuros));
Arr_Juros.AddElement(Json_Juros);
Json_Boleto.AddPair('interest', Json_Juros);
end;
clipboard.AsText := Json_Boleto.ToJSON;
TRequest.New.BaseURL(BASE_URL).Resource('v3/payments').AddHeader('access_token', TOKEN_ASAAS,
[poDoNotEncode]).Adapters(TDataSetSerializeAdapter.New(TbBoleto)).Accept('application/json')
.AddBody(Json_Boleto.ToJSON).Post;
Result := resp.StatusCode;
finally
{ Json_Boleto.DisposeOf;
Json_Desconto.DisposeOf;
Json_Juros.DisposeOf;
Json_Multa.DisposeOf; }
end;
end;
Boa tarde amigos,
Estou tentando consumir uma api do Asaas. Os endpoints get estão funcionando perfeitamente mas quando tento fazer um post me retorna aquele erro doido Access Violatin at address.......
Algúem consegue me ajudar onde está errado?