Tabla de Contenidos

API: Borrar deuda

Ejemplo de cómo eliminar una deuda y su correspondiente URL de pago utilizando el API.

Harías este llamada porque una deuda ya no es válida o ha sido cobrada por otro método.

Llamadas al API | Ciclo de cobro


PHP

<?php
 
$idDeuda = 'demo001';
$apiUrl = 'https://staging.adamspay.com/api/v1/debts/' . $idDeuda;
$apiKey = 'tu-api-key';
$notificarAlWebhook='true'; // Puede ser true,false o "now" si debe notificar de inmediato
 
$curl = curl_init();
 
curl_setopt_array($curl,[
 CURLOPT_URL => $apiUrl,
 CURLOPT_HTTPHEADER => ['apikey: '.$apiKey, 'x-should-notify'=>$notificarAlWebhook],
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_CUSTOMREQUEST=>'DELETE'
 ]);
 
$response = curl_exec($curl);
if( $response ){
  $data = json_decode($response,true);
 
  $debt = isset($data['debt']) ? $data['debt'] : null;
  if( $debt ){
    echo "Deuda eliminada\n";
    print_r($debt);
  } else {
    echo "No se pudo eliminar la deuda\n";
    print_r($data['meta']);
  }
 
}
else {
  echo 'curl_error: ',curl_error($curl);
}
curl_close($curl);

Python

import http.client
import json
import pprint
 
apiKey = "tu-api-key"
idDeuda = "demo001"
notificarAlWebhook = "true"
host = "staging.adamspay.com"
path = "/api/v1/debts/" + idDeuda
headers = {"apikey": apiKey, "x-should-notify": notificarAlWebhook}
 
conn = http.client.HTTPSConnection(host)
conn.request("DELETE", path , "", headers)
data = conn.getresponse().read().decode("utf-8")
 
response = json.JSONDecoder().decode(data)
 
pp = pprint.PrettyPrinter(indent=2)
if "debt" in response:
    debt=response["debt"]
    print("Deuda borrada")
    print("Detalles:")
    pp.pprint(response["debt"])
else:
    print("# Error")
    if "meta" in response:
        pp.pprint(response["meta"])