Hallo,
ich möchte als zusätzliche Zahlart noch Lastschrift anbieten, weshalb zusätzliche Eingabefelder für die Bankverbindung benötigt werden, dessen Eingaben dann in den E-Mails angezeigt oder in der Datenbank gespeichert werden.
Die Erweiterung isotope_payment_directdebit integriert diese Funktion in Isotope, doch funktioniert sie mit der aktuellen Contao- und Isotope-Version nicht korrekt. Im Frontend läuft alles korrekt ab, doch in der E-Mail ist die Bankverbindung nicht enthalten – die Simple Tokens funktionieren offenbar nicht.
Wie löst ihr das bislang? Oder könnt mir helfen, die Erweiterung fit für Isotope 1.3 und Contao 2.11.2 zu machen?
config/config.php
PHP-Code:
/**
* Payment modules
*/
$GLOBALS['ISO_PAY']['directdebit'] = 'Isotope_Payment_PaymentDirectDebit';
/**
* Hooks
*/
$GLOBALS['TL_HOOKS']['iso_writeOrder'][] = array('Isotope_Payment_DirectDebitHelper', 'onWriteOrder');
Isotope_Payment_DirectDebitHelper.php – hier werden die Simple Tokens definiert.
Die Datei wird aber wohl überhaupt nicht aufgerufen, da keinerlei Fehler auftritt, wenn ich in die Datei nur Mist schreibe.
PHP-Code:
/**
* Helper class for direct debit payment method
*
* Provides hook to inject direct debit payment data such as
* the account holder on writing the order.
*
* @copyright Copyright (c) 2010 Michael Gruschwitz <info@grusch-it.de>
* @license http://opensource.org/licenses/lgpl-3.0.html
* @category Contao
* @package Isotope
* @subpackage Payment
* @uses Frontend
*/
class Isotope_Payment_DirectDebitHelper extends Frontend
{
/**
* @var Isotope
*/
public $Isotope;
/**
* Hook on writing the order
*
* TL_HOOKS::iso_writeOrder
*
* @param int|str $orderId The order id
* @param bool $blnCheckout TODO: don't know what $blnCheckout realy is
* @param ModuleIsotopeCheckout $isoModCheckout Isotope checkout object
* @return bool TODO: don't know what $blnCheckout realy is
*/
public function onWriteOrder($orderId, $blnCheckout, $isoModCheckout)
{
// import isotope object
$this->import('Isotope');
// get the id of the selected payment module
$paymentId = $this->Isotope->Cart->Payment->id;
// get payment modules that are _not_ of type directdebit
$objModules = $this->Database->execute("SELECT * FROM tl_iso_payment_modules WHERE type!='directdebit' AND enabled='1'");
// iterate through the payment modules that are _not_ of type directdebit
// because we only want to inject account data if directdebit was selected
while ($objModules->next()) {
// the current selected payment module is not type of directdebit, so stop here
if ($objModules->id == $paymentId) {
return $blnCheckout;
}
}
// collect data from the session
$accHolder = $_SESSION['CHECKOUT_DATA']['payment'][$paymentId]['acc_holder'];
$accNumber = $_SESSION['CHECKOUT_DATA']['payment'][$paymentId]['acc_number'];
$accRoutingNumber = $_SESSION['CHECKOUT_DATA']['payment'][$paymentId]['acc_routing_number'];
// obfuscate the account number for the frontend
$accNumberObf = $this->Isotope->Cart->Payment->getObfuscatedAccountNumber($accNumber);
// inject data to the order data array
$isoModCheckout->arrOrderData = array_merge($isoModCheckout->arrOrderData, array(
'acc_holder' => $accHolder,
'acc_number' => $accNumber,
'acc_number_obf' => $accNumberObf,
'acc_routing_number' => $accRoutingNumber
));
return $blnCheckout;
}
}
Isotope_Payment_PaymentDirectDebit.php
PHP-Code:
/**
* Direct debit payment provider
*
* Provides a direct debit payment provider collecting the following data:
* - account holder
* - account number
* - account routing number.
*
* @copyright Copyright (c) 2010 Michael Gruschwitz <info@grusch-it.de>
* @license http://opensource.org/licenses/lgpl-3.0.html
* @category Contao
* @package Isotope
* @subpackage Payment
* @uses Frontend
*/
class Isotope_Payment_PaymentDirectDebit extends IsotopePayment
{
/**
* Return a list of status options
*
* @return array Array of availble status options
*/
public function statusOptions()
{
return array('pending', 'processing', 'complete', 'on_hold');
}
/**
* Processes the payment
*
* Direct debit does not require any processing; so the method will just
* return 'true'.
*
* @see IsotopePayment::processPayment()
* @return bool True if the processing was successfull
*/
public function processPayment()
{
return true;
}
/**
* Returns a html form for payment data
*
* Includes fields for
* - account holder
* - account number
* - account routing number.
*
* @see IsotopePayment::paymentForm()
*
* @param ModuleIsotopeCheckout $objCheckoutModule The checkout module object
* @return string The html string of the form
*/
public function paymentForm($objCheckoutModule)
{
// get posted payment data
$arrPayment = $this->Input->post('payment');
// form fields as array
$formFields = array
(
'acc_holder' => array
(
'label' => &$GLOBALS['TL_LANG']['ISO']['acc_holder'],
'inputType' => 'text',
'eval' => array('mandatory' => true, 'tableless' => true)
),
'acc_number' => array
(
'label' => &$GLOBALS['TL_LANG']['ISO']['acc_number'],
'inputType' => 'text',
'eval' => array('mandatory' => true, 'rgxp' => 'digit', 'maxlength' => 12, 'tableless' => true)
),
'acc_routing_number' => array
(
'label' => &$GLOBALS['TL_LANG']['ISO']['acc_routing_number'],
'inputType' => 'text',
'eval' => array('mandatory' => true, 'rgxp' => 'digit', 'maxlength' => 8, 'tableless' => true)
)
);
$strBuffer = '';
// build form
foreach ($formFields as $fieldName => $arrData)
{
// get class of the current input field
$strClass = $GLOBALS['TL_FFL'][$arrData['inputType']];
// if the input field class is unkown; continue
if (!$this->classFileExists($strClass))
{
continue;
}
// generate the name of the input field
$strName = sprintf('payment[%s][%s]', $this->id, $fieldName);
// create the input field object/widget
$objWidget = new $strClass($this->prepareForWidget($arrData, $strName, $_SESSION['CHECKOUT_DATA']['payment'][$this->id][$field]));
// validate the posted data
if ($this->Input->post('FORM_SUBMIT') == 'iso_mod_checkout_payment' && $arrPayment['module'] == $this->id)
{
$objWidget->validate();
if ($objWidget->hasErrors())
{
$objCheckoutModule->doNotSubmit = true;
}
}
$strBuffer.= $objWidget->parse();
}
// add error message
if (strlen($_SESSION['CHECKOUT_DATA']['payment'][$this->id]['error']))
{
$strBuffer = '<p class="error">' . $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['error'] . '</p>' . $strBuffer;
unset($_SESSION['CHECKOUT_DATA']['payment'][$this->id]['error']);
}
return $strBuffer;
}
/**
* Return the checkout review information
*
* Displays the provided account data:
* - account holder
* - account number (obfuscated)
* - account routing number.
*
* @return string The account data as html
*/
public function checkoutReview()
{
// collect data from session
$accHolder = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['acc_holder'];
$accNumber = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['acc_number'];
$accRoutingNumber = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['acc_routing_number'];
$accNumberObf = $this->getObfuscatedAccountNumber($accNumber);
// html template
$strBuffer = '<span class="payment_label">%s</span>' . PHP_EOL;
$strBuffer.= '<div class="account_info">' . PHP_EOL;
$strBuffer.= '<span class="label">%s:</span> %s<br />' . PHP_EOL;
$strBuffer.= '<span class="label">%s:</span> %s<br />' . PHP_EOL;
$strBuffer.= '<span class="label">%s:</span> %s<br />' . PHP_EOL;
$strBuffer.= '</div>' . PHP_EOL;
// inject data into the html template
return sprintf(
$strBuffer,
$this->label,
$GLOBALS['TL_LANG']['ISO']['acc_holder'],
$accHolder,
$GLOBALS['TL_LANG']['ISO']['acc_number'],
$accNumberObf,
$GLOBALS['TL_LANG']['ISO']['acc_routing_number'],
$accRoutingNumber
);
}
/**
* Obfuscates a account number
*
* Replaces all digits with asteriks (*) except the last four
*
* Examples:
* 1093847569 -> ******7569
* 62534 -> ******2534
* 62 => ********62
*
* @param int|str $number The account number
* @return string The obfuscated account number
*/
public function getObfuscatedAccountNumber($number)
{
$number = (string) $number;
$visible = $number;
if (strlen($number) > 4) {
$visible = substr($number, (strlen($number) - 4));
}
return sprintf("%'*10s", $visible);
}
}
Vielen Dank im Voraus,
Gruß JaiBee
Lesezeichen