Skip to content

Developer notes

The add-on is a CS-Cart payment processor (?:payment_processors, script app/addons/kv_sepa_direct_debit/payments/kv_sepa_direct_debit.php, storefront template addons/kv_sepa_direct_debit/views/orders/components/payments/kv_sepa_direct_debit.tpl). Creditor data lives in the payment method’s processor_params (creditor_name, creditor_id, creditor_iban, creditor_bic), so one payment method is one creditor.

  1. get_payments_post (storefront): the method is offered only when the add-on is on and licensed, the store has a EUR currency and the creditor data is valid.
  2. pre_place_order: Orders::prePlace() validates payment_info[holder|iban|bic|consent|mandate|keep] (ISO 13616 length + MOD 97, accepted country list, BIC pattern, consent), sets $allow = false with a message on an error, and takes the account data out of $cart['payment_info'] before core stores it (core encrypts payment_info into ?:order_data). Only a masked copy and the mandate reference stay.
  3. place_order: Orders::onPlace() stores the mandate (or reuses the saved one / the same account) and the debit of the top-level order. In Multi-Vendor the parent order carries the money; sub-orders (parent_order_id) get no debit.
  4. The processor script sets the order status (setting “after placement”). Nothing is charged: the bank collects later.
  5. get_order_info adds $order['kv_sdd'] (mandate without IBAN, debit, pre-notification text); template_snippet_render_post appends the SEPA block to the products_table snippet of the order_invoice and order_summary documents (invoice, order e-mails).
  6. change_order_status_post (cancelled / declined) and delete_order clean up open debits; delete_user cuts the link of mandates to a deleted account; update_payment_pre normalises and checks the creditor fields.
Table Content
?:kv_sdd_mandates Mandate per creditor: reference (unique per creditor identifier), type OOFF / RCUR, status A / R, holder, iban_enc (encrypted), iban_hash (keyed HMAC), iban_masked, BIC, creditor snapshot, accepted text, signature time and type (W web, P recorded by the shop)
?:kv_sdd_debits One collection per order: amount in EUR, state N / X / C / R / K, sequence type, end-to-end id (ORDER-<order>-D<debit>), due date, collection date, batch, return code, retry link
?:kv_sdd_batches A bank file: message id, format, creation time, collection date, count, total, downloads
?:kv_sdd_log Audit trail (created, exported, collected, returned, IBAN revealed, erased …)

Pain008::build($batch, '02'|'08') takes plain arrays (creditor, groups of debits with amounts in cents) and returns the XML; Pain008::problems() lists what would make a bank reject the file. Batches::create() claims the debits with one UPDATE ... WHERE status = 'N' per debit (two administrators never export the same debit), builds the file, and undoes the claim if the file is invalid. Batches::xml() rebuilds the file from the stored rows on every download, so no file with account numbers is written to disk.

Tests: tests/unit_pure.php builds files and validates them against tests/xsd/pain.008.001.02.xsd and pain.008.001.08.xsd (see tests/xsd/SOURCES.md for their origin), with negative cases to show that the check can fail.

Registered when the other add-on is installed, harmless otherwise.

Hook From What it does
kv_subscriptions_payment_driver Subscriptions & Recurring Orders Marks the SEPA methods as able to charge a saved credential
kv_subscriptions_charge Subscriptions & Recurring Orders Creates a debit for the renewal order from the customer’s recurrent mandate (pending, or failed without a mandate)
kv_bank_reconcile_booked / kv_bank_reconcile_undone Bank Transfer Auto-Reconcile Debit becomes collected / goes back to exported

Debits::netTermsDue() and Orders::collectOrder() read \Tygh\Addons\KvNetTermsCreditLimit\Invoices when it exists.

checkout.post.php assigns $kv_sdd_checkout (creditors, mandate text, saved mandates of the signed-in customer) to the payment step and removes account data from the session cart after every checkout request. Checkout, order and account pages are never cached by the 4.21 full page cache; nothing is added to cacheable pages. index.php?dispatch=kv_sdd.status returns {"state":"on|off","methods":N} as JSON (Cache-Control: no-store) for monitoring.

  • Every SQL statement uses placeholders. Backend and frontend modes check the company of every row (runtime.company_id), and customers see only their own mandates (or the mandate of an order they may open).
  • The IBAN is encrypted with fn_encrypt_text() (the store key), the lookup hash is an HMAC over the store key, the masked form is stored for display.
  • A mandate can be revoked by its customer or an administrator; a mandate of another customer, a revoked mandate and a mandate of another creditor are refused at checkout.
  • Bulk erase is administrator-only; revealing a full IBAN is logged.
app/addons/kv_sepa_direct_debit/
addon.xml, init.php, func.php
payments/kv_sepa_direct_debit.php processor script
controllers/backend/kv_sdd.php debits, mandates, batches, export, download, actions
controllers/backend/kv_sepa_direct_debit_license.php "Check now" / license cron
controllers/backend/orders.post.php collect-by-debit data for the order page
controllers/frontend/kv_sdd.php my mandates, mandate view / PDF, revoke, status JSON
controllers/frontend/checkout.post.php, orders.post.php account form data
schemas/menu/menu.post.php, schemas/permissions/admin.post.php, vendor_multivendor.post.php
Tygh/Addons/KvSepaDirectDebit/
Config.php Iban.php Text.php Calendar.php Pain008.php Pdf.php MandateDocument.php ReturnCodes.php
Mandates.php Debits.php Batches.php Orders.php Lists.php Log.php
License/Client.php License/Ed25519.php Upgrade/Synchronizer.php
design/backend/templates/addons/kv_sepa_direct_debit/
views/kv_sdd/{manage,mandates,mandate,update_mandate,batches}.tpl, views/kv_sdd/components/*
views/payments/components/cc_processors/kv_sepa_direct_debit.tpl creditor fields
views/orders/components/payments/kv_sepa_direct_debit.tpl (admin order editor hint)
hooks/orders/payment_info.post.tpl, hooks/index/styles.post.tpl, hooks/addons/*, license/*
design/backend/css/addons/kv_sepa_direct_debit/admin.less, license.less
var/themes_repository/responsive/templates/addons/kv_sepa_direct_debit/
views/orders/components/payments/kv_sepa_direct_debit.tpl account form at checkout
views/kv_sdd/{manage,view}.tpl
hooks/orders/details.post.tpl, hooks/checkout/payment_instruction.post.tpl,
hooks/profiles/my_account_menu.post.tpl, hooks/index/{styles,scripts}.post.tpl
var/themes_repository/responsive/css/addons/kv_sepa_direct_debit/styles.less
js/addons/kv_sepa_direct_debit/func.js

The add-on ships the Kavio Labs license client (License/Client.php, kv_sepa_direct_debit_license controller, card / status bar / badge templates). License\Client::isActive() gates the checkout method and the subscription driver through Config::isOn(); collecting what was authorised does not depend on it. The client contacts https://cs-cart.kaviolabs.com from the admin panel or cron only.

Back to the overview