Skip to content

Commit

Permalink
Use the log system provided by WC
Browse files Browse the repository at this point in the history
  • Loading branch information
mgiulio committed Sep 11, 2014
1 parent 1b4a2c7 commit 8cafbdd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ None at this time
* Bug fix: no need of explicit unset of 'order_awaiting_payment' session variable in newer WC versions, gh-21
* Enhancement: prepare plugin messages for I18N
* Refactoring: wc gateway admin settings API
* Use the logging system provided by WC
* Use wc_add_notice() instead of deprecated $woocommerce->add_error()
* Code cleanup
= 0.29 =
Expand Down
36 changes: 26 additions & 10 deletions stripe_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class Striper extends WC_Payment_Gateway
private $version = '0.30';
private $path;
private $url;


private $logger = null;
protected $usesandboxapi = true;
protected $order = null;
protected $transactionId = null;
Expand All @@ -40,6 +39,9 @@ public function __construct()

$alt_image = $this->get_option('alternate_imageurl');
$this->icon = empty($alt_image) ? $this->url['assets'] . 'images/credits.png' : $alt_image;

if ($this->get_option('logging') == 'yes')
$logger = new WC_Logger();

$this->usesandboxapi = $this->get_option('sandbox') == 'yes';

Expand Down Expand Up @@ -81,7 +83,7 @@ public function perform_ssl_check()

public function init_form_fields()
{
$this->form_fields = array(
$this->form_fields = array(
'enabled' => array(
'title' => __('Enable/Disable', 'striper'),
'type' => 'checkbox',
Expand Down Expand Up @@ -144,6 +146,12 @@ public function init_form_fields()
'label' => __('Turn on testing with Stripe sandbox', 'striper'),
'default' => 'no'
),
'logging' => array(
'title' => __('Logging', 'striper'),
'type' => 'checkbox',
'label' => __('Turn on logging to troubleshot problems', 'striper'),
'default' => 'no'
)
);
}

Expand Down Expand Up @@ -211,12 +219,16 @@ protected function send_to_stripe()
return true;

} catch(Stripe_Error $e) {
// The card has been declined, or other error
// The card has been declined, or other error
$body = $e->getJsonBody();
$err = $body['error'];
error_log('Stripe Error:' . $err['message'] . "\n");
wc_add_notice(__('Payment error:', 'striper') . $err['message'], 'error');
return false;

if ($this->logger)
$this->logger->add('striper', 'Stripe Error:' . $err['message']);

wc_add_notice(__('Payment error:', 'striper') . $err['message'], 'error');

return false;
}
}

Expand Down Expand Up @@ -350,9 +362,13 @@ function striper_order_status_completed($order_id = null)
// There was an error
$body = $e->getJsonBody();
$err = $body['error'];
error_log('Stripe Error:' . $err['message'] . "\n");
wc_add_notice(__('Payment error:', 'striper') . $err['message'], 'error');
return null;

if ($this->logger)
$this->logger->add('striper', 'Stripe Error:' . $err['message']);

wc_add_notice(__('Payment error:', 'striper') . $err['message'], 'error');

return null;
}
return true;
}
Expand Down

0 comments on commit 8cafbdd

Please sign in to comment.