PDA

View Full Version : Savebill



michael_s
08-14-2013, 12:56 AM
:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::
SAFEBILL MODULE V1.0 FOR osCommerce Online Merchant v2.2 RC2a Released
:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::
Autor: info@salesconquest.com
Modified: Fabrizio S.
:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::



######### G E N E R A L I N F O R M A T I O N ###########

This module was created and tested for osCommerce Online Merchant v2.2 RC2a Released

IMPORTANT: Please backup your database and files before
making any changes!

All needed files are included (also the files which have
to be modified)

Tested on the following server config:
PHP Version 5.2.9
Apache/2.2.3 (CentOS)
Mysql 5.1.32
SOAP library enabled

############# C H A N G E L O G #######################
VERSION 1.1:
------------
- Correct the errors in the installationa package
- Add the safebill.php file in admin/includes/classes/
- Add the missing lines in orders.php file in admin/ rep.




###### I N S T A L L A T I O N ########


RECOMANDATION: PLEASE BACKUP YOUR DATABASE BEFORE INSTALLING THE MODULE
The install script add 2 new tables in the database and alter the tables orders and customers adding new fields.

-----------------------------------------------------------
1) Information, should I need this module ?
-----------------------------------------------------------

This module is available and should be installed only for Swiss merchant and swiss marcket.
To make it works, an account to Safebill is necessary.
If you need more information about this payment method, please contact Safebill at
support@safebill.ch

-----------------------------------------------------------
2) SHOP: New files
-----------------------------------------------------------

Copy the file /catalog/includes/modules/payment/safebillosc.php
into your directory:
YOUR_SHOP_ROOT_/includes/modules/payment/

Copy the file /catalog/includes/languages/english/modules/payment/safebillosc.php
into your directory:
YOUR_SHOP_ROOT_/includes/modules/payment/

Copy the repository /catalog/ext/modules/payment/safebillosc
into your directory:
YOUR_SHOP_ROOT_/includes/ext/modules/payment/

Copy the repository /catalog/images/icons/question.png and /catalog/images/icons/sb_logo.png.png
into your directory:
YOUR_SHOP_ROOT_/images/icons/

Copy the file /catalog/admin/includes/classes/safebill.php
into your directory:
YOUR_SHOP_ROOT_/admin/includes/classes

-----------------------------------------------------------
3) SHOP: 'general.php'
-----------------------------------------------------------
Open the file "/YOUR_SHOP_ROOT_/includes/functions/general.php".

************************************************** ************
At the end of file add the followinf function:
************************************************** ************

//SAFEBILL
function sb_get_safebill_order_info($order_id){
//Get order info
$sb_order_info_query = tep_db_query("SELECT sb_invoicing_costs,sb_partial_payment_fees, result FROM " .TABLE_ORDERS. " o, " .TABLE_SAFEBILL_PAYMENT_RESULTS. " pr WHERE o.orders_id=" . (int)$order_id . " AND o.orders_id=pr.orders_id");
$sb_order_info = tep_db_fetch_array($sb_order_info_query);

$sb_info = array('invoicing_costs' => $sb_order_info['sb_invoicing_costs'],
'partial_payment_fees' => $sb_order_info['sb_partial_payment_fees'],
'payment_result' => $sb_order_info['result']);

//Get partial payment info
$sb_payment_table_query = tep_db_query("SELECT * FROM " .TABLE_SAFEBILL_PARTIAL_PAYMENT_TABLE. " WHERE orders_id=" . (int)$order_id . " ORDER BY timestamp");
if(tep_db_num_rows($sb_payment_table_query) > 0){
$p_table_total = 0;
while($result = tep_db_fetch_array($sb_payment_table_query)){
$p_table_total = $p_table_total + $result['amount'];
$sb_info['partial_payment_table'][] = array('payment_date' => $result['date'],
'payment_amount' => $result['amount']);
}

$sb_info['partial_payment_table_total'] = $p_table_total;
}

//Get order total info
$sb_order_total_query = tep_db_query("SELECT value FROM " .TABLE_ORDERS_TOTAL. " WHERE orders_id=" .(int)$order_id. " AND class='ot_total'");
$sb_order_total = tep_db_fetch_array($sb_order_total_query);
$sb_info['order_total'] = tep_round($sb_order_total['value'],2);
$sb_info['order_total_with_safebill'] = $sb_info['order_total'] + $sb_info['invoicing_costs'] + $sb_info['partial_payment_fees'];

return $sb_info;
}
//SAFEBILL



-----------------------------------------------------------
4) SHOP: order.php
-----------------------------------------------------------
Open the file "/YOUR_SHOP_ROOT_/includes/classes/order.php".

************************************************** ************
Search the following code (about line 53):
************************************************** ************

$this->info = array('currency' => $order['currency'],
'currency_value' => $order['currency_value'],
'payment_method' => $order['payment_method'],
'cc_type' => $order['cc_type'],
'cc_owner' => $order['cc_owner'],
'cc_number' => $order['cc_number'],
'cc_expires' => $order['cc_expires'],
'date_purchased' => $order['date_purchased'],
'orders_status' => $order_status['orders_status_name'],
'last_modified' => $order['last_modified'],
'total' => strip_tags($order_total['text']),
'shipping_method' => ((substr($shipping_method['title'], -1) == ':') ? substr(strip_tags($shipping_method['title']), 0, -1) : strip_tags($shipping_method['title'])));

************************************************** ************
and replace it with the following code:
************************************************** ************
$this->info = array('currency' => $order['currency'],
'currency_value' => $order['currency_value'],
'payment_method' => $order['payment_method'],
'cc_type' => $order['cc_type'],
'cc_owner' => $order['cc_owner'],
'cc_number' => $order['cc_number'],
'cc_expires' => $order['cc_expires'],
'date_purchased' => $order['date_purchased'],
'orders_status' => $order_status['orders_status_name'],
'last_modified' => $order['last_modified'],
'total' => strip_tags($order_total['text']),
'shipping_method' => ((substr($shipping_method['title'], -1) == ':') ? substr(strip_tags($shipping_method['title']), 0, -1) : strip_tags($shipping_method['title'])));
//SAFEBILL
if(defined('MODULE_PAYMENT_SAFEBILLOSC_STATUS')){
$this->info['safebill_info'] = sb_get_safebill_order_info($order_id);
}
//SAFEBILL

-----------------------------------------------------------
5) SHOP: account_history_info.php
-----------------------------------------------------------

Open the file "/YOUR_SHOP_ROOT_/account_history_info.php".

Please make the following modifications:

************************************************** ************
Search the following code (about line 320):
************************************************** ************



-----------------------------------------------------------
6) SHOP: english.php
-----------------------------------------------------------

Open the file "/YOUR_SHOP_ROOT_/includes/languages/english.php".

************************************************** ************
At the end of the file add:
************************************************** ************
//SAFEBILL
define('ENTRY_SAFEBILL_MODALITY', 'Payment modality:');
define('HEAD_SAFEBILL_MODALITY_DEPOSIT', 'Deposit Nb');
define('HEAD_SAFEBILL_MODALITY_DATE', 'Payment date');
define('HEAD_SAFEBILL_MODALITY_AMOUNT', 'Amount');
define('HEAD_SAFEBILL_INVOICE_FEE','Invoicing fees:');
define('HEAD_SAFEBILL_PARTIAL_PAYMENT_FEE','Partia l payment fees:');
define('HEAD_SAFEBILL_COMPLETE_TOTAL','Total final:');

-----------------------------------------------------------
7) SHOP: database_tables.php
-----------------------------------------------------------

//SAFEBILL
define('TABLE_SAFEBILL_PARTIAL_PAYMENT_TABLE','sb_ partial_payment_table');
define('TABLE_SAFEBILL_PAYMENT_RESULTS','sb_paymen t_results');



-----------------------------------------------------------
8) ADMIN: general.php
-----------------------------------------------------------

Open the file "/YOUR_SHOP_ROOT_/_YOUR_SHOP_ADMIN_/includes/functions/general.php".

************************************************** ************
At the end of file add the followinf function:
************************************************** ************

//SAFEBILL
function sb_get_safebill_order_info($order_id){
//Get order info
$sb_order_info_query = tep_db_query("SELECT sb_invoicing_costs,sb_partial_payment_fees, result FROM " .TABLE_ORDERS. " o, " .TABLE_SAFEBILL_PAYMENT_RESULTS. " pr WHERE o.orders_id=" . (int)$order_id . " AND o.orders_id=pr.orders_id");
$sb_order_info = tep_db_fetch_array($sb_order_info_query);

$sb_info = array('invoicing_costs' => $sb_order_info['sb_invoicing_costs'],
'partial_payment_fees' => $sb_order_info['sb_partial_payment_fees'],
'payment_result' => $sb_order_info['result']);

//Get partial payment info
$sb_payment_table_query = tep_db_query("SELECT * FROM " .TABLE_SAFEBILL_PARTIAL_PAYMENT_TABLE. " WHERE orders_id=" . (int)$order_id . " ORDER BY timestamp");
if(tep_db_num_rows($sb_payment_table_query) > 0){
$p_table_total = 0;
while($result = tep_db_fetch_array($sb_payment_table_query)){
$p_table_total = $p_table_total + $result['amount'];
$sb_info['partial_payment_table'][] = array('payment_date' => $result['date'],
'payment_amount' => $result['amount']);
}

$sb_info['partial_payment_table_total'] = $p_table_total;
}

//Get order total info
$sb_order_total_query = tep_db_query("SELECT value FROM " .TABLE_ORDERS_TOTAL. " WHERE orders_id=" .(int)$order_id. " AND class='ot_total'");
$sb_order_total = tep_db_fetch_array($sb_order_total_query);
$sb_info['order_total'] = tep_round($sb_order_total['value'],2);
$sb_info['order_total_with_safebill'] = $sb_info['order_total'] + $sb_info['invoicing_costs'] + $sb_info['partial_payment_fees'];

return $sb_info;
}
//SAFEBILL



-----------------------------------------------------------
10) ADMIN: order.php
-----------------------------------------------------------
Open the file "/YOUR_SHOP_ROOT_/_YOUR_SHOP_ADMIN_/includes/classes/order.php".

************************************************** ************
Search the following code (about line 36):
************************************************** ************

$this->info = array('currency' => $order['currency'],
'currency_value' => $order['currency_value'],
'payment_method' => $order['payment_method'],
'cc_type' => $order['cc_type'],
'cc_owner' => $order['cc_owner'],
'cc_number' => $order['cc_number'],
'cc_expires' => $order['cc_expires'],
'date_purchased' => $order['date_purchased'],
'orders_status' => $order['orders_status'],
'last_modified' => $order['last_modified']);

************************************************** ************
and replace it with the following code:
************************************************** ************
$this->info = array('currency' => $order['currency'],
'currency_value' => $order['currency_value'],
'payment_method' => $order['payment_method'],
'cc_type' => $order['cc_type'],
'cc_owner' => $order['cc_owner'],
'cc_number' => $order['cc_number'],
'cc_expires' => $order['cc_expires'],
'date_purchased' => $order['date_purchased'],
'orders_status' => $order['orders_status'],
'last_modified' => $order['last_modified']);
//SAFEBILL
if(defined('MODULE_PAYMENT_SAFEBILLOSC_STATUS')){
$this->info['safebill_info'] = sb_get_safebill_order_info($order_id);
}
//SAFEBILL

-----------------------------------------------------------
11) ADMIN: orders.php
-----------------------------------------------------------

/YOUR_SHOP_ROOT_/_YOUR_SHOP_ADMIN_/orders.php".

************************************************** ************
Search the following code (about line 175):
************************************************** ************
if ($order_updated == true) {

$messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');

************************************************** ************
Right after, add the following part of code:
************************************************** ************
//SAFEBILL
$order_status_history_id = tep_db_insert_id();
include(DIR_WS_CLASSES . 'safebill.php');
$sb = new safebill();

if($sb->check_status()){

$sb_check_status_query = tep_db_query("SELECT set_sb_aknowledge, set_sb_cancel FROM " . TABLE_ORDERS_STATUS . " WHERE orders_status_id = '" . (int)$status . "'");
$sb_check_status = tep_db_fetch_array($sb_check_status_query);

$operation = $sb->set_sb_operation($sb_check_status['set_sb_aknowledge'],$sb_check_status['set_sb_cancel'],$oID,$order_status_history_id);

if($operation != false){

if(isset($operation['aknowledge'])){
$messageStack->add_session($operation['aknowledge']['message'], $operation['aknowledge']['status']);

}

if(isset($operation['cancel'])){
$messageStack->add_session($operation['cancel']['message'], $operation['cancel']['status']);
}
}else{
$messageStack->add_session('Safebill operation error', 'error');
}

}
//SAFEBILL
************************************************** ************
Search the following code (about line 175):
************************************************** ************











************************************************** ************
Right after, add the following part of code:
************************************************** ************












************************************************** ************
Search the following code (about line 257):
************************************************** ************


************************************************** ************
And replace with:
************************************************** ************




************************************************** ************
After the code above find that html code around line 287
************************************************** ************








************************************************** ************
Add the following part of code
************************************************** ************




































Total















************************************************** ************
After the code above find that html code
************************************************** ************








************************************************** ************
Add the following part of code
************************************************** ************




************************************************** ************
After the code above find this piece of code
************************************************** ************
$orders_history_query = tep_db_query("select orders_status_id, date_added, customer_notified, comments from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . tep_db_input($oID) . "' order by date_added");

************************************************** ************
Replace with this one
************************************************** ************

//SAFEBILL
$orders_history_query = tep_db_query("select orders_status_id, date_added, customer_notified, comments, sb_return_status from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . tep_db_input($oID) . "' order by date_added");
//SAFEBILL

************************************************** ************
Fine the following part of code
************************************************** ************
if ($orders_history['customer_notified'] == '1') {
echo tep_image(DIR_WS_ICONS . 'tick.gif', ICON_TICK) . "
n";
} else {
echo tep_image(DIR_WS_ICONS . 'cross.gif', ICON_CROSS) . "n";
}
echo ' ' . $orders_status_array[$orders_history['orders_status_id']] . '
' . "n" .
' ' . nl2br(tep_db_output($orders_history['comments'])) . '
' . "n" .
************************************************** ************
Right after add the following line
************************************************** ************
//SAFEBILL
' ' . nl2br(tep_db_output($orders_history['sb_return_status'])) . '
' . "n" .
//SAFEBILL
-----------------------------------------------------------
12) ADMIN: orders.php
-----------------------------------------------------------
Open the file "/YOUR_SHOP_ROOT_/_YOUR_SHOP_ADMIN_/includes/languages/english/orders.php".
************************************************** ************
At the end of file add the following part of code:
************************************************** ************
//SAFEBILL
define('ENTRY_SAFEBILL_RESULT','Safebill payment result: ');
define('ENTRY_SAFEBILL_MODALITY', 'Payment modality:');
define('HEAD_SAFEBILL_MODALITY_DEPOSIT', 'Deposit Nb');
define('HEAD_SAFEBILL_MODALITY_DATE', 'Payment date');
define('HEAD_SAFEBILL_MODALITY_AMOUNT', 'Amount');
define('HEAD_SAFEBILL_INVOICE_FEE','Invoicing fees:');
define('HEAD_SAFEBILL_PARTIAL_PAYMENT_FEE','Partia l payment fees:');
define('HEAD_SAFEBILL_COMPLETE_TOTAL','Total final:');

-----------------------------------------------------------
13) ADMIN: database_tables.php
-----------------------------------------------------------

Open the file "/YOUR_SHOP_ROOT_/_YOUR_SHOP_ADMIN_/includes/database_tables.php".

************************************************** ************
At the end of file add the following part of code:
************************************************** ************
//SAFEBILL
define('TABLE_SAFEBILL_PARTIAL_PAYMENT_TABLE','sb_ partial_payment_table');
define('TABLE_SAFEBILL_PAYMENT_RESULTS','sb_paymen t_results');


-----------------------------------------------------------
14) ADMIN: MODULE INSTALLATION
-----------------------------------------------------------

RECOMANDATION: PLEASE BACKUP YOUR DATABASE BEFORE INSTALLING THE MODULE

The install script add 2 new tables in the database and alter the table orders and customers adding new fields.

Once you've made ALL the modifications above, login to your administration and go
to Modules>Payment section, select the Safebill payment Method and click on the install button


###################### E N D #########################


More... (http://addons.oscommerce.com/info/8875)