Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
bugfix: warn if required PHP extensions not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nmarley committed Apr 7, 2016
1 parent 5f2bcec commit c562a3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
6 changes: 3 additions & 3 deletions dashpay-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: DashPayments for WooCommerce
* Plugin URI: http://blackcarrotventures.com/dashpay-woocommerce
* Description: A WooCommerce payment gateway that enables direct Dash payments.
* Version: 0.0.1
* Version: 0.0.2
* Author: Black Carrot Ventures
* Author URI: http://blackcarrotventures.com/
* Requires at least: 4.4.2
Expand Down Expand Up @@ -46,7 +46,7 @@ final class DashPayments {
*
* @var string
*/
public $version = '0.0.1';
public $version = '0.0.2';

/**
* The single instance of the class.
Expand Down Expand Up @@ -96,7 +96,7 @@ public function __clone() {
* @since 0.0.1
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' );
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '0.0.1' );
}

/**
Expand Down
35 changes: 11 additions & 24 deletions includes/gateways/class-wc-gateway-dashpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function __construct() {
$this->description = $this->settings['description'];

$this->xpub_key = $this->settings['xpub_key'];
$this->correct_xpub_key = $this->ensure_correct_xpub_key($this->xpub_key);
$this->confirmations = $this->settings['confirmations'];
$this->exchange_multiplier = $this->settings['exchange_multiplier'];

Expand All @@ -59,7 +58,7 @@ public function __construct() {
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );

// Effectively broken, so not going to implement this 'til WordPress fixes it
// add_action( 'admin_notices', array( $this, 'admin_notices' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}


Expand Down Expand Up @@ -106,7 +105,8 @@ public function is_available() {
}

// ensure matching xpub and insight networks
$xpub_network = CoinUtil::guess_network_from_xkey($this->correct_xpub_key);
$xpub_network = CoinUtil::guess_network_from_xkey( $this->correct_xpub_key() );

$insight_network;
try {
$insight_network = $insight->get_network();
Expand Down Expand Up @@ -175,7 +175,7 @@ protected function check_valid() {


// ensure matching xpub and insight networks
$xpub_network = CoinUtil::guess_network_from_xkey($this->correct_xpub_key);
$xpub_network = CoinUtil::guess_network_from_xkey( $this->correct_xpub_key() );
try {
$insight_network = $insight->get_network();
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public function admin_notices() {
$missing = DP()->missing_required_extensions();
if ( 0 !== count($missing) ) {
$msg = sprintf(
esc_html__("Required extension(s) not loaded/enabled. Please enable '%s' PHP extension(s) on your WordPress server.", 'dashpay-woocommerce'),
__("<strong>DashPayments for WooCommerce:</strong> Required extension(s) not loaded/enabled. Please enable '%s' PHP extension(s) on your WordPress server.", 'dashpay-woocommerce'),
join(', ', $missing)
);
self::_admin_error( $msg );
Expand Down Expand Up @@ -261,7 +261,7 @@ public function admin_notices() {


// ensure matching xpub and insight networks
$xpub_network = CoinUtil::guess_network_from_xkey($this->correct_xpub_key);
$xpub_network = CoinUtil::guess_network_from_xkey( $this->correct_xpub_key() );
try {
$insight_network = $insight->get_network();
}
Expand Down Expand Up @@ -422,7 +422,7 @@ public function process_payment( $order_id ) {
$order_info = array(
'order_id' => $order_id,
'payment_currency' => self::$currency,
'xpub' => $this->settings['correct_xpub_key'],
'xpub' => $this->correct_xpub_key(),
'expires_at' => $expires_at,
'requested_by_ip' => @$_SERVER['REMOTE_ADDR'],
'order_total_coins' => $order_total_in_coins,
Expand Down Expand Up @@ -507,30 +507,17 @@ public function add_ajax_order_check() {
}

/**
* Update DB with properly serialized extended public key
* Return properly serialized extended public key
*
* @access protected
* @return void
*/
protected function ensure_correct_xpub_key($xpub) {
protected function correct_xpub_key() {
// must be valid xpub
if ( ! CoinUtil::is_valid_public_xkey( $xpub ) ) {
if ( ! CoinUtil::is_valid_public_xkey( $this->xpub_key ) ) {
return '';
}

$correct_xpub_key = CoinUtil::reserialize_key( $xpub, self::$currency );

$correct = $this->get_option('correct_xpub_key');

$settings_option_name = DP_Gateways::settings_option_for( self::$currency );
$settings = get_option( $settings_option_name );

// update if not the same
if ( $correct !== $correct_xpub_key ) {
$settings['correct_xpub_key'] = $correct_xpub_key;
update_option( $settings_option_name, $settings );
}

$correct_xpub_key = CoinUtil::reserialize_key( $this->xpub_key, self::$currency );
return $correct_xpub_key;
}

Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ In the future, this will either be delegated to something like coinmarketcap (no

== Changelog ==

= 0.0.2 =

* bugfix: Warn if required PHP extensions not enabled.

= 0.0.1 =

* New

0 comments on commit c562a3c

Please sign in to comment.