Fixed Paypal IPN and other minor items

This commit is contained in:
Deon George 2013-12-04 21:37:09 +11:00
parent 06b87c5135
commit 8ba487a4a6
12 changed files with 44 additions and 71 deletions

View File

@ -63,8 +63,9 @@ class Controller_Reseller_Account extends Controller_Account {
public function action_view() {
$ao = ORM::factory('Account',$this->request->param('id'));
if (! $ao->loaded() OR ! $ao->status)
HTTP::redirect(URL::link('reseller','welcome'));
if (! $ao->loaded() OR ! $ao->status OR ! Auth::instance()->authorised($ao))
throw HTTP_Exception::factory(403,'Account either doesnt exist, or you are not authorised to see it');
Block::factory()
->title(sprintf('Active Service for Account: %s',$ao->accnum()))

View File

@ -1,15 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's 403 Exception
*
* @package OSB
* @category Exceptions
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class HTTP_Exception_403 extends HTTP_Exception {
protected $_code = 403;
}
?>

View File

@ -1,15 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's 404 Exception
*
* @package OSB
* @category Exceptions
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class HTTP_Exception_404 extends HTTP_Exception {
protected $_code = 404;
}
?>

View File

@ -1,15 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's 501 Exception to catch OSB specific errors
*
* @package OSB
* @category Exceptions
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class HTTP_Exception_501 extends HTTP_Exception {
protected $_code = 501;
}
?>

View File

@ -46,6 +46,7 @@ class Kohana_Exception extends Kohana_Kohana_Exception {
try {
if (Kohana::$config->load('debug')->show_errors) {
return parent::response($e);
} else {
SystemMessage::add(array(
'title'=>'An Error Occured.',
@ -57,6 +58,7 @@ class Kohana_Exception extends Kohana_Kohana_Exception {
$response = Response::factory();
$response->status(302);
$response->headers('Location',URL::site());
return $response;
}

View File

@ -16,7 +16,7 @@
<div class="row">
<div class="offset1">
<button type="submit" class="btn btn-primary">Checkout</button>
<a href="cart/empty" class="btn">Clear</a>
<?php echo HTML::anchor(URL::link('','/cart/empty'),'Clear',array('class'=>'btn')); ?>
</div>
</div>
</div> <!-- /span -->

View File

@ -13,6 +13,9 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
protected $url_prod = 'www.paypal.com';
protected $url_test = 'www.sandbox.paypal.com';
private $ipn_test = '173.0.82.126';
protected $email_prod = ''; // @todo This should be in the DB
protected $email_test = ''; // @todo This should be in the DB
protected $test_mode = FALSE;
protected $curlopts = array(
CURLOPT_CONNECTTIMEOUT => 60,
@ -31,13 +34,12 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
* User return from Paypal after payment
*/
public function after(Cart $co) {
SystemMessage::add(array(
'title'=>_('Payment Processing'),
'type'=>'info',
'body'=>sprintf('Thank you for your payment with paypal. It will be processed and applied to your cart items automatically in due course.'),
));
SystemMessage::factory()
->title(_('Payment Processing'))
->type('info')
->body(_('Thank you for your payment with paypal. It will be processed and applied to your cart items automatically in due course.'));
HTTP::redirect('/');
HTTP::redirect(URL::link('user','welcome'));
}
/**
@ -61,7 +63,7 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
// If testing
if (! $cno->status OR $cno->processed OR ($debug_mode AND Request::$client_ip == $this->ipn_test))
return ('Thank you');
return _('Thank you');
$co = Cart::instance(isset($cno->data['custom']) ? $cno->data['custom'] : '');
@ -83,7 +85,8 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
case 'VERIFIED':
// Verify that the IPN is for us.
// @todo This should be in the DB.
if ($cno->data['business'] == 'deon_1260578114_biz@graytech.net.au') {
if ($cno->data['business'] == ($this->test_mode ? $this->email_test : $this->email_prod)) {
switch ($cno->data['payment_status']) {
case 'Completed':
// Our cart items total.
@ -91,7 +94,7 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
$po = ORM::factory('Payment');
// Does the payment cover the cart total?
if ($this->co->fee_passon AND $cno->data['mc_gross'] == $total+$this->co->fee($total)) {
if ($this->co->fee_passon AND $cno->data['mc_gross'] === (string)($total+$this->co->fee($total))) {
// Store the amounts in an array, so we can pro-rata the fee to each item.
$amts = array();
@ -135,7 +138,10 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
}
$po->old_add_item($cio->module_item)->alloc_amt = $cno->data['mc_gross_'.$c];
$pio = $po->payment_item;
$pio->alloc_amt = $cno->data['mc_gross_'.$c];
$pio->invoice_id = $cio->module_item;
$po->add_item($pio);
break;
@ -156,7 +162,9 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
$po->date_payment = strtotime($cno->data['payment_date']);
$po->checkout_id = $this->co->id;
$po->notes = $cno->data['txn_id'];
$po->save();
if (! $po->save())
$cno->result = array('msg'=>'Failed to save PO?','po'=>$po);
// Clear the cart
if (! $debug_mode)
@ -166,13 +174,19 @@ abstract class Checkout_Plugin_Paypal extends Checkout_Plugin {
// Ignore the fee
} else {
echo Debug::vars('IPN doesnt match cart total');
$cno->result = array(
'msg'=>'IPN doesnt match cart total',
't'=>$total,
'tt'=>(string)($total+$this->co->fee($total)),
'g'=>$cno->data['mc_gross'],
'fpo'=>$this->co->fee_passon,
't1'=>($cno->data['mc_gross'] === (string)($total+$this->co->fee($total))),
);
// If there is more than 1 item in the cart, we'll leave it to an admin to process.
if ($cno->data['num_cart_items'] == 1) {
echo Debug::vars('Apply to cart item');
} else {
// @todo - add the payment, with no payment items
echo Debug::vars('Leave for admin');
}
}
@ -194,8 +208,9 @@ echo Debug::vars('Leave for admin');
$cno->status = FALSE;
}
$cno->processed = TRUE;
if (! $debug_mode)
$cno->processed = TRUE;
$cno->save();
return _('Processed, thank you!');

View File

@ -10,8 +10,6 @@
* @license http://dev.osbill.net/license.html
*/
class Checkout_Plugin_Paypal_Cart extends Checkout_Plugin_Paypal {
private $test_mode = FALSE;
/**
* Set payment via Paypal
*/
@ -25,7 +23,7 @@ class Checkout_Plugin_Paypal_Cart extends Checkout_Plugin_Paypal {
->set('cart',$co);
$output .= Form::hidden('cmd','_cart');
$output .= Form::hidden('business',$this->test_mode ? 'deon_1260578114_biz@graytech.net.au' : 'deon@graytech.net.au');
$output .= Form::hidden('business',$this->test_mode ? $this->email_test : $this->email_prod);
$output .= Form::hidden('bn','Graytech_BuyNow_WPS_AU');
$output .= Form::hidden('cancel_return',URL::site('checkout/cancel/'.$this->co->id,TRUE));
$output .= Form::hidden('custom',$co->id());

View File

@ -79,6 +79,8 @@ class Controller_Checkout extends Controller_TemplateDefault {
$this->response->body($cno->process());
} catch (Exception $e) {
Kohana_Exception::log($e);
$this->response->body('Received, thank you!');
}

@ -1 +1 @@
Subproject commit 319b4b29db9c1e467b34f75bb03d1d908d17afbc
Subproject commit f3066fd383a9211336c035acde462e32c38546e2

View File

@ -69,7 +69,7 @@ class Model_Payment extends ORM_OSB {
foreach ($this->items('ALLOC') as $pio)
$result -= $pio->alloc_amt;
return $format ? Currency::display($result) : $result;
return $format ? Currency::display($result) : Currency::round($result);
}
/**
@ -81,7 +81,7 @@ class Model_Payment extends ORM_OSB {
foreach ($this->items('CREDIT') as $pio)
$result += $pio->alloc_amt*-1;
return $format ? Currency::display($result) : $result;
return $format ? Currency::display($result) : Currency::round($result);
}
/**

View File

@ -19,7 +19,7 @@ class Task_SSL_Renew extends Minion_Task {
* Renew a certificate
*/
protected function _execute(array $params) {
ORM::factory('Service',$params['id'])->plugin()->renew($params['force']);
ORM::factory('Service',$params['id'])->plugin()->renew(Minion_CLI::options('force'));
}
}
?>