Fixed Paypal IPN and other minor items
This commit is contained in:
@@ -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,9 +208,10 @@ echo Debug::vars('Leave for admin');
|
||||
$cno->status = FALSE;
|
||||
}
|
||||
|
||||
$cno->processed = TRUE;
|
||||
if (! $debug_mode)
|
||||
$cno->save();
|
||||
$cno->processed = TRUE;
|
||||
|
||||
$cno->save();
|
||||
|
||||
return _('Processed, thank you!');
|
||||
}
|
||||
|
@@ -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());
|
||||
|
Reference in New Issue
Block a user