From 8ea5f4fe91291e79419653cb1fab94a4d08ae194 Mon Sep 17 00:00:00 2001 From: jps Date: Fri, 19 Dec 2025 09:26:39 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20donn=C3=A9es=20bancaires=20si=20viremen?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/Peppol_controller.php | 61 ++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/app/controllers/Peppol_controller.php b/app/controllers/Peppol_controller.php index df02d31..b837e8c 100644 --- a/app/controllers/Peppol_controller.php +++ b/app/controllers/Peppol_controller.php @@ -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);