2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides checkout capabilities.
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package Checkout
|
2010-11-29 22:41:08 +00:00
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2010-11-29 22:41:08 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2012-12-10 21:48:30 +00:00
|
|
|
class Model_Checkout extends ORM_OSB {
|
2013-04-04 22:42:29 +00:00
|
|
|
protected $_has_many = array(
|
|
|
|
'account'=>array('through'=>'account_billing','foreign_key'=>'checkout_plugin_id'),
|
|
|
|
'payment'=>array(),
|
|
|
|
);
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
2013-01-15 06:07:54 +00:00
|
|
|
* Calcuale the fee for this checkout method
|
2010-11-29 22:41:08 +00:00
|
|
|
*
|
2013-01-15 06:07:54 +00:00
|
|
|
* @param $amt The amount the fee will be based on
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2013-01-15 06:07:54 +00:00
|
|
|
public function fee($amt) {
|
|
|
|
if (! $this->fee_passon)
|
|
|
|
return 0;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
$net = $amt;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
if (! is_null($this->fee_fixed))
|
|
|
|
$net += $this->fee_fixed;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
if (! is_null($this->fee_variable))
|
|
|
|
$net /= (1-$this->fee_variable);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
return Currency::round($net-$amt);
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
/**
|
|
|
|
* Return the object of the checkout plugin
|
|
|
|
*/
|
|
|
|
public function plugin($type='') {
|
|
|
|
$c = Kohana::classname('Checkout_Plugin_'.$this->plugin);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
if (! $this->plugin OR ! class_exists($c))
|
|
|
|
return NULL;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
$o = new $c($this);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
return $type ? $o->$type : $o;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|