2012-01-11 08:59:20 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is for processing Ezypay payments.
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package Payment
|
2012-01-11 08:59:20 +00:00
|
|
|
* @category Helpers
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2012-01-11 08:59:20 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Payment_Bulk_Ezypay {
|
|
|
|
public function form() {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = '';
|
2012-01-11 08:59:20 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
|
|
|
|
$result .= Form::hidden('payer',$_POST['payer']);
|
|
|
|
$result .= View::factory('payment/admin/addbulk/ezypay');
|
|
|
|
$result .= Form::submit('submit','submit',array('class'=>'form_button'));
|
|
|
|
$result .= Form::close();
|
2012-01-11 08:59:20 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2012-01-11 08:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function process() {
|
|
|
|
$payments = array();
|
|
|
|
|
|
|
|
// Process payment
|
|
|
|
$file = file_get_contents($_FILES['payment']['tmp_name']);
|
2012-05-08 14:59:08 +00:00
|
|
|
$file = preg_split("/[\r]?[\n]+/",$file);
|
2012-01-11 08:59:20 +00:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach ($file as $line) {
|
|
|
|
// Line 0 is our header
|
|
|
|
if ($i++ == 0 OR ! trim($line))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Trim our whitespace on the end of the line.
|
|
|
|
$line = preg_replace("/\s+$/",'',$line);
|
|
|
|
$array = explode("\t",$line);
|
|
|
|
|
|
|
|
// Field 4 has our account reference
|
2013-02-12 11:14:59 +00:00
|
|
|
if (preg_match('/^'.Company::instance()->site(TRUE).'-/',$array[4]) AND $array[10] == 'Cleared') {
|
2013-02-26 03:19:32 +00:00
|
|
|
$aid = preg_replace('/^'.Company::instance()->site(TRUE).'-/','',$array[4]);
|
2012-01-11 08:59:20 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$po = ORM::factory('Payment');
|
2012-01-11 08:59:20 +00:00
|
|
|
$po->account_id = $aid;
|
|
|
|
$po->total_amt = $array[7];
|
|
|
|
$po->notes = $array[2].':'.$array[3];
|
|
|
|
$po->date_payment = strtotime(str_replace('/','-',$array[8]));
|
|
|
|
|
|
|
|
$payments[$array[3]] = $po;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = file_get_contents($_FILES['transaction']['tmp_name']);
|
2012-05-08 14:59:08 +00:00
|
|
|
$file = preg_split("/[\r]?[\n]+/",$file);
|
2012-01-11 08:59:20 +00:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach ($file as $line) {
|
|
|
|
// Line 0 is our header
|
|
|
|
if ($i++ == 0 OR ! trim($line))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Trim our whitespace on the end of the line.
|
|
|
|
$line = preg_replace("/\s+$/",'',$line);
|
|
|
|
$array = explode("\t",$line);
|
|
|
|
|
2012-04-17 10:50:06 +00:00
|
|
|
// If we dont have a payment item for this fee, we'll continue.
|
|
|
|
if (! isset($payments[$array[3]]))
|
|
|
|
continue;
|
|
|
|
|
2012-01-11 08:59:20 +00:00
|
|
|
// Our commission fees
|
|
|
|
// @todo This should be in a config file
|
|
|
|
if (in_array($array[9],array(1,15)))
|
|
|
|
$payments[$array[3]]->fees_amt = (float)$array[7];
|
|
|
|
|
|
|
|
// @todo Hack - since the reports dont show how the payment was made.
|
|
|
|
// @todo Put this in a config file, in the mean time.
|
|
|
|
if ($array[7] == 1.05)
|
|
|
|
$payments[$array[3]]->checkout_plugin_id = 2;
|
|
|
|
else
|
|
|
|
$payments[$array[3]]->checkout_plugin_id = 4;
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = '';
|
|
|
|
$result .= View::Factory('payment/admin/addbulk/ezypay/head');
|
2012-01-11 08:59:20 +00:00
|
|
|
|
|
|
|
$total = $fees = 0;
|
|
|
|
foreach ($payments as $po) {
|
|
|
|
$po->save();
|
|
|
|
|
|
|
|
$total += $po->total_amt;
|
|
|
|
$fees += $po->fees_amt;
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result .= View::Factory('payment/admin/addbulk/ezypay/body')
|
2012-01-11 08:59:20 +00:00
|
|
|
->set('o',$po);
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result .= View::Factory('payment/admin/addbulk/ezypay/foot')
|
2012-01-11 08:59:20 +00:00
|
|
|
->set('total',$total)
|
|
|
|
->set('fees',$fees);;
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2012-01-11 08:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|