BillSAFE-Integration in Magento

Small but important!

At present, payment by invoice via the BillSAFE service provider only works without problems with Magento's standard checkout.

With a one-step checkout, the BillSAFE extension is missing JavaScript functions that can easily be integrated afterwards, for example via the layout file. The solution presented here describes how to work with the one-step checkout extension from the Vietnamese provider <span;">Magestore, but the approach can also be applied to other extensions. The missing functions manifest themselves in the log file as follows:

<span;"> {"ack":"ERROR","errorList":{"code":225,"message":"Session ID not found"}}

The required files are integrated into the basic installation of the BillSAFE module in the file app\design\frontend\base\default\layout\billpay.xml. We now copy this file into the desired template folder. If, for example, we are using the "modern" template of the "default" package, we copy the file to app\design\frontend\default\modern\layout\billpay.xml and add the reference <onestepcheckout_index_index> intended for the one-step checkout before the closing </layout> tag, alongside the existing <checkout_onepage_index> reference for the standard one-page checkout:

<onestepcheckout_index_index>
   <reference name="head">
      <reference name="head">
        <action method="addCss"><stylesheet>css/billsafe.css</stylesheet></action>
      </reference>
      <block type="core/text" name="google.cdn.jquery">
        <action method="setText">
           <text><![CDATA[<script type="text/javascript" src="https://fn.billsafe.de/fb/js/lazyload-min.js"></script>]]></text>
        </action>
      </block>
   </reference>
</onestepcheckout_index_index>

The Session ID should now also be transmitted correctly, allowing Paul Positiv to place an order. However, since BillSAFE does not approve payment by invoice without first receiving an invoice from a test purchase according to a predefined format, a few more adjustments are required here. Since the BillSAFE invoice must not contain a bank code (BLZ) or account number belonging to BillSAFE, but the extension does not yet take this into account, we need to modify the file app\design\adminhtml\default\default\template\billsafe\pdf\info.phtml. To do this, we look for the line

<span"> <?php if (0 < strlen(trim($this->getBankCode())) && 0 < strlen(trim($this->getAccountNumber()))): ?>

and replace it, for example, with

<?php if (0 < strlen(trim($this->getBankCode())) && 0 < strlen(trim($this->getAccountNumber())) && 1==2): ?>

This hides the BillSAFE bank code and account number, and we are done. Unless the footer or another part of the invoice still contains the shop operator's own bank account information. Understandably, this is not desirable as part of the BillSAFE transaction, as it could result in direct payments. The following adjustment demonstrates how to hide the last block of the footer when using the PDF Customiser extension from the New Zealand developer <span;">Fooman:

In the file app\code\community\Fooman\PdfCustomiser\Model\Mypdf.php, within the Footer() function, we look for the following lines (approximately from line 1008):

} elseif ($key == $footers[0]) {
   //last element
   if (!empty($footer)) {
      $html .= '<td width="'.$width.'mm</td>';

and replace them with:

} elseif ($key == $footers[0]) {
   //last element
   if (!empty($footer)) {
      if ($helper->getOrder()->getPayment()->getMethodInstance()->getCode() == 'billsafe') {
         $html .= '<td width="'.$width.'mm</td>';
      } else {
         $html .= '<td width="'.$width.'mm">'.$footer.'</td>';
      }

This means that approval by BillSAFE is no longer a problem and secure payment by invoice has been successfully integrated.
Implemented with Magento CE 1.7.0.2.

... back to the blog