Génération d'un mandat de prélèvement depuis l'api

Bonjour à vous,
Je remets mon message dans la bonne catégorie.

Je suis à la recherche d’aide pour une fonctionnalité que je suis en train de développer.

Je veux générer un mandat de prélèvement sepa depuis l’api.

Mon problème est que je la fonction de génération du mandat me retourne le fait que tout s’est bien passé, c’est à dire qu’elle me retourne 1 mais aussi que je ne peux rien retourner après.

Je vous serais très reconnaissant de me venir en aide.

Voici mon code

<?php
/* Copyright (C) 2018 CHENE Pierre
 * 
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

use Luracast\Restler\RestException;
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';



/**
 * API class for apigenrib 
 *
 * @smart-auto-routing false
 * @access protected
 * @class  DolibarrApiAccess {@requires user,external}
 */
class ApiGenRibApi extends DolibarrApi
{
    private $company;
    public function __construct()
    {
        global $db, $conf, $langs;
        $this->db = $db;
        $this->langs = $langs;
        $this->company = new Societe($db);
    }

    /**
 * Generate a sepamandate Document
 * 
 * @param int $socid thirdparty id
 * 
 * @return array Check success
 * 
 * @url GET /generateMandat/{socid}
 */
public function generateMandat($socid){

    $this->langs->load("companies");
    $this->langs->load("commercial");
    $this->langs->load("banks");
    $this->langs->load("bills");
    $model = "sepamandate";
    
    $this->company->fetch($socid);
    
    $action = 'builddoc';
    $upload_dir = $conf->societe->multidir_output[$this->company->entity];
    if(! DolibarrApiAccess::$user->rights->societe->creer)
        throw new RestException(401);
    
    
    // Reload to get all modified line records and be ready for hooks
    
    
    $this->company->setDocModel($user, $model);
    
    $this->company->fk_bank = $this->company->fk_account;
    
    $outputlangs = $this->langs;
    $newlang='';   
    
    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang;  // for proposal, order, invoice, ...
    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang;                  // for thirdparty
    if (! empty($newlang))
    {
        $outputlangs = new Translate("",$conf);
        $outputlangs->setDefaultLang($newlang);
    }
    
    // To be sure vars is defined
    if (empty($hidedetails)) $hidedetails=0;
    if (empty($hidedesc)) $hidedesc=0;
    if (empty($hideref)) $hideref=0;
    if (empty($moreparams)) $moreparams=null;
    
    
    $sql = "SELECT rowid";
    $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
    if ($socid) $sql.= " WHERE fk_soc  = ".$socid." ";
    
    
    $result = $this->db->query($sql);
    
    if($result->num_rows == 0 ){
        throw new RestException(404, 'Account not found');
    }	
    
    $i=0;
    
    $accounts =[];
    
    if ($result)
    {
        $num = $this->db->num_rows($result);
        while ($i < $num)
        {
            $obj = $this->db->fetch_object($result);
            $account = new CompanyBankAccount($this->db);
            if($account->fetchFromApi($obj->rowid)) {
                $accounts[] = $account;
            }
            $i++;
        }
    }
    else{
        throw new RestException(404, 'Account not found');
    }
    
    $moreparams = array(
        'use_companybankid'=>$accounts[0]->id,
        'force_dir_output'=>$conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id)
    );
       
    $result = 0;
    
    try{
        $result = $this->company->generateDocument($this->company->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);      
    }
    catch(Exception $e){
        return array("message"=> $e->getMessage());
    }
      
    
    if ($result <= 0)
    {
        throw new RestException(500);
    }
    else
    {
        return array("success" => $result);
    }
       
    }   
}

Merci d’avance pour vos réponses