Exemplo n.º 1
0
<?php

require_once "SEPASDD.php";
$config = array("name" => "Test", "IBAN" => "NL50BANK1234567890", "BIC" => "BANKNL2A", "batch" => true, "creditor_id" => "00000", "currency" => "EUR");
$payment = array("name" => "Test von Testenstein", "IBAN" => "NL50BANK1234567890", "BIC" => "BANKNL2A", "amount" => "1000", "type" => "FRST", "collection_date" => date("Y-m-d"), "mandate_id" => "1234", "mandate_date" => date("2014-02-01"), "description" => "Test transaction");
try {
    $SEPASDD = new SEPASDD($config);
    $SEPASDD->addPayment($payment);
    print_r($SEPASDD->save());
} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}
Exemplo n.º 2
0
function GenerateSepa($debit_id, $debit_type = null)
{
    if ($debit_type != 'FRST' and $debit_type != 'RCUR') {
        error_log(__FUNCTION__ . '() invalid $debit_type ' . $debit_type);
        return FALSE;
    }
    // Check $debit_id
    if (defined($debit_id) and !is_numeric($debit_id)) {
        die('Invalid $debit_id');
    }
    $sepa = GetSepaContent($debit_id, $debit_type);
    if ($sepa === FALSE) {
        error_log(__FUNCTION__ . "(): unable to fetch content from GetSepaContent() for direct debit {$debit_id} with type {$debit_type}. There is probably no transaction here");
        return FALSE;
    }
    $company_rib = GetCompanyMaiRIB();
    $nombre_virements = 0;
    $montant_total = 0;
    $montant_total_centimes = 0;
    $chaine_totale = "";
    $nb_erreurs = 0;
    $erreurs_details = "";
    require_once 'sepa_constants.php';
    $config = array("name" => RAISON_SOCIALE, "IBAN" => preg_replace('/\\s+/', '', CODE_IBAN), "BIC" => preg_replace('/\\s+/', '', CODE_BIC), "batch" => "true", "creditor_id" => preg_replace('/\\s+/', '', CODE_ICS), "currency" => "EUR");
    try {
        $SEPASDD = new SEPASDD($config);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    foreach ($sepa as $line) {
        // On recherche les éléments pouvant bloquer la génération du paiement
        if (empty($config['IBAN']) or empty($config['BIC']) or empty($config['creditor_id'])) {
            $nb_erreurs++;
            $nb_erreurs_ligne++;
            $erreurs_details .= " - Aucun IBAN et/ou BIC et/ou ICS enregistré(s) pour la société <a href=\"/prospection/fiche_prospect.php?id={$line['id']}\">{$line['name']}</a>.<br />";
        }
        if (strlen($line['iban']) > LONGUEUR_IBAN or empty($line['iban'])) {
            $nb_erreurs++;
            $nb_erreurs_ligne++;
            $erreurs_details .= " - Le code IBAN de \"" . $line['name'] . "\" permettant de générer un virement d'un montant de " . $line['montant'] . " EUR contient " . strlen($line['iban']) . " caractères au lieu de " . LONGUEUR_IBAN . " max. (valeur constatée : " . $line['iban'] . "). Cette ligne est abandonnée.<br />";
        }
        if (strlen($line['bic']) > LONGUEUR_BIC or empty($line['bic'])) {
            $nb_erreurs++;
            $nb_erreurs_ligne++;
            $erreurs_details .= " - Le code BIC de \"" . $line['name'] . "\" permettant de générer un virement d'un montant de " . $line['montant'] . " EUR contient " . strlen($line['bic']) . " caractères au lieu de " . LONGUEUR_BIC . " max. (valeur constatée : " . $line['bic'] . "). Cette ligne est abandonnée.<br />";
        }
        $montant_debit = $line['montant'];
        $payment = array("name" => $line['name'], "IBAN" => $line['iban'], "BIC" => $line['bic'], "amount" => "{$montant_debit}", "type" => $line['debit_type'], "collection_date" => date('Y-m-d'), "mandate_id" => $line['client_sepaid'], "mandate_date" => $line['mandat_date'], "description" => $line['ref']);
        try {
            $SEPASDD->addPayment($payment);
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
    if ($nb_erreurs > 0) {
        // Des erreurs bloquantes ont été detectées
        ?>
		<div class="mess_err">
			<?php 
        echo $nb_erreurs;
        ?>
 erreur(s) bloquante(s) détectée(s) pour la génération du fichier de remise :<br />
			<?php 
        echo $erreurs_details;
        ?>
<br />
			Remise d'ordre de virement abandonnée <!-- ' -->
		</div>
		<br /><br />
		<?php 
        return false;
    }
    try {
        $chaine_totale = $SEPASDD->save();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    $res = mysql_query("UPDATE direct_debit SET type = 'SEPA' WHERE id = {$debit_id}") or die(mysql_error());
    $myFile = sys_get_temp_dir() . "/sepa-{$debit_id}-{$debit_type}.xml";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $chaine_totale);
    fclose($fh);
    return $myFile;
}
Exemplo n.º 3
0
<?php

require_once "SEPASDD.php";
$config = array("name" => "Test", "IBAN" => "NL41BANK1234567890", "batch" => True, "creditor_id" => "00000", "currency" => "EUR", "version" => "3");
$payment = array("name" => "Test von Testenstein", "IBAN" => "NL40BANK1234567890", "amount" => "1000", "type" => "FRST", "collection_date" => date("Y-m-d"), "mandate_id" => "1234", "mandate_date" => date("2014-02-01"), "description" => "Test transaction");
try {
    $SEPASDD = new SEPASDD($config);
    $SEPASDD->addPayment($payment);
    $xml = $SEPASDD->save();
    if ($SEPASDD->validate($xml)) {
        print_r($xml);
    } else {
        print_r($SEPASDD->validate($xml));
    }
    print_r($SEPASDD->getDirectDebitInfo());
} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}