Ajout données bancaires si virement

This commit is contained in:
Jean-Philippe Staelen 2025-12-19 09:26:39 +01:00
parent ebbdaf2e15
commit 8ea5f4fe91

View File

@ -233,6 +233,8 @@ class PEPPOL_peppol_controller {
);
}
print_r($payload);
// Enregistrer ou mettre à jour dans la base de données
// On passe $inner_data comme response_data pour conserver la structure complète
PEPPOL_Main_model::save_for_order(
@ -389,6 +391,57 @@ class PEPPOL_peppol_controller {
}
}
/**
* Récupère les informations de paiement BACS depuis WooCommerce.
* Retourne le premier compte bancaire valide configuré.
*
* @return array{
* payee_iban: string,
* payee_bic: string,
* bank_name: string
* }
*/
protected static function get_bacs_payment_info(): array {
$payment_info = [
'payee_iban' => '',
'payee_bic' => '',
'bank_name' => '',
];
// Récupérer les comptes BACS configurés dans WooCommerce
$accounts = \get_option('woocommerce_bacs_accounts', []);
if (empty($accounts) || !is_array($accounts)) {
return $payment_info;
}
// Trouver le premier compte valide avec IBAN
foreach ($accounts as $account) {
if (!is_array($account)) {
continue;
}
// Vérifier que le compte a au moins un IBAN et un nom de banque
$iban = isset($account['iban']) ? trim((string) $account['iban']) : '';
$bank_name = isset($account['bank_name']) ? trim((string) $account['bank_name']) : '';
if ($iban !== '' && $bank_name !== '') {
$payment_info['payee_iban'] = $iban;
$payment_info['bank_name'] = $bank_name;
// BIC est optionnel dans WooCommerce BACS
if (isset($account['bic']) && !empty($account['bic'])) {
$payment_info['payee_bic'] = trim((string) $account['bic']);
}
// On prend le premier compte valide trouvé
break;
}
}
return $payment_info;
}
/**
* Construit le payload JSON attendu par /upload-json à partir
* d'une commande WooCommerce.
@ -871,12 +924,8 @@ class PEPPOL_peppol_controller {
$invoice_totals = \apply_filters('esi_peppol_invoice_totals', $invoice_totals, $order);
// Informations de paiement (laissées filtrables pour configuration future)
$payment_info = [
'payee_iban' => '',
'payee_bic' => '',
'bank_name' => '',
];
// Informations de paiement depuis BACS WooCommerce
$payment_info = self::get_bacs_payment_info();
$payment_info = \apply_filters('esi_peppol_payment_info', $payment_info, $order);