Cart work for payments and Paypal work to test

This commit is contained in:
Deon George
2013-01-15 17:07:54 +11:00
parent 133ae4d5c6
commit 69645c4eea
42 changed files with 968 additions and 801 deletions

View File

@@ -11,58 +11,38 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Checkout extends ORM_OSB {
protected $_has_many = array(
'account'=>array('through'=>'account_billing','foreign_key'=>'checkout_plugin_id'),
'payment'=>array(),
);
/**
* Calcuale the fee for this checkout method
*
* @param $amt The amount the fee will be based on
*/
public function fee($amt) {
if (! $this->fee_passon)
return 0;
$net = $amt;
if (! is_null($this->fee_fixed))
$net += $this->fee_fixed;
if (! is_null($this->fee_variable))
$net /= (1-$this->fee_variable);
return Currency::round($net-$amt);
}
/**
* Give a cart, this will present the available checkout options
*
* Trial Products are NEW products
* Cart items are NEW products
* Invoice items are RE-OCCURING items (ie: carts are not re-occuring)
*
* Return the object of the checkout plugin
*/
public function payment_options_cart() {
$cart = Cart::instance();
public function plugin($type='') {
$c = Kohana::classname('Checkout_Plugin_'.$this->plugin);
$available_payments = array();
if (! $this->plugin OR ! class_exists($c))
return NULL;
if ($cart->has_trial())
$this->and_where('allow_trial','=',TRUE);
$o = new $c($this);
$this->and_where('allow_new','=',TRUE);
foreach ($this->list_active() as $item) {
// Check that the cart total meets the minimum requirement
if ($item->total_minimum AND $cart->total() < $item->total_minimum)
continue;
// Check the cart total meets the maximum requirement
if (($item->total_maximum AND $cart->total() > $item->total_maximum) OR ($item->total_maximum == '0' AND $cart->total()))
continue;
// Check that the payment option is available to this client based on groups
// @todo Enable this test
// Check that the payment option is not prohibited by an SKU item
// @todo Enable this test
// Check if this payment method is a default payment method
// @todo Enable this test
// By Amount
// By Currency
// By Group
// By Country
// This payment option is valid
array_push($available_payments,$item);
// Sort the checkout options
// @todo Is this required?
}
return $available_payments;
return $type ? $o->$type : $o;
}
}
?>

View File

@@ -0,0 +1,23 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides checkout capabilities.
*
* @package OSB
* @subpackage Checkout
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Checkout_Notify extends ORM_OSB {
// Relationships
protected $_has_one = array(
'checkout'=>array('far_key'=>'checkout_id','foreign_key'=>'id'),
);
public function process() {
return $this->checkout->plugin()->notify($this);
}
}
?>