Skip to content

Commit

Permalink
Version 1.1.3
Browse files Browse the repository at this point in the history
+ Solves a problem with payment gateway loading
+ Additional validation on order id's
  • Loading branch information
jesse-mollie committed Apr 16, 2014
1 parent fa292b2 commit 7a4eee6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion MPM/mpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: MPM - Mollie Payment Module
* Plugin URI: https://github.com/Mollie/WooCommerce/releases
* Version: 1.1.2
* Version: 1.1.3
* Description: Integration of the Mollie API for WooCommerce
* Author: Mollie
* Author URI: https://www.mollie.nl
Expand Down
15 changes: 14 additions & 1 deletion MPM/mpm_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,20 @@ public function payment_fields()
public function process_payment($order_id)
{
global $mpm, $woocommerce;
$order = new WC_Order($order_id);
$order = $mpm->order_get($order_id, null, true);
if ($order === FALSE)
{
if (defined('WB_DEBUG') && WP_DEBUG)
{
$woocommerce->add_error(__('Could not create payment.', 'MPM') . ' Reason: invalid order ID');
}
else
{
$woocommerce->add_error(__('Could not create payment.', 'MPM'));
}
return array('result' => 'failure');
}

$order->update_status('pending', __('Awaiting payment confirmation', 'MPM'));

$webhook = admin_url('admin-ajax.php') . '?action=mollie_webhook';
Expand Down
32 changes: 20 additions & 12 deletions MPM/mpm_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class MPM_Settings extends WC_Settings_API
{
// Keep track of payment methods
public $count = 0;
public $methods = array();
protected $methods = array();

/** @var $api Mollie_API_Client|null */
public $api = null;
protected $api = null;

/** @var $return MPM_return|null */
public $return = null;

public $plugin_version = '1.1.2';
public $plugin_version = '1.1.3';
public $update_url = 'https://github.com/mollie/WooCommerce';

public function __construct()
Expand Down Expand Up @@ -233,7 +233,7 @@ public function gateways_add_dynamic($gateways)
if ($this->get_option('enabled') === 'yes' && get_option('woocommerce_currency', 'unknown') === 'EUR')
{
// Add as much gateways as we have payment methods (they will claim their own indices)
for ($i = count($this->methods); $i > 0; $i--)
for ($i = count($this->get_methods()); $i > 0; $i--)
{
$gateways[] = 'MPM_Gateway';
}
Expand All @@ -256,7 +256,11 @@ public function gateways_add_static($gateways)
{
// Retrieve correct gateway position (tougher than it sounds)
$pos_list = (array) get_option('woocommerce_gateway_order');
$pos_orig = $pos_list['mpm'];
$pos_orig = 0;
if (array_key_exists('mpm', $pos_list))
{
$pos_orig = $pos_list['mpm'];
}
$pos = $pos_orig;
$wc = WC_Payment_Gateways::instance();
$all_gateways = $wc->payment_gateways();
Expand All @@ -274,25 +278,28 @@ public function gateways_add_static($gateways)
if ($this->get_option('enabled') === 'yes' && get_option('woocommerce_currency', 'unknown') === 'EUR')
{
// Add as much gateways as we have payment methods (they will claim their own indices)
for ($i = 0; $i < count($this->methods); $i++)
$methods = $this->get_methods();
for ($i = 0; $i < count($methods); $i++)
{
$mollie_gateways[$this->methods[$i]->id] = new MPM_Gateway();
$mollie_gateways[$methods[$i]->id] = new MPM_Gateway();
}
}

$head = array_slice($gateways, 0, $pos);
$tail = array_slice($gateways, $pos);
return array_merge($head, $mollie_gateways, $tail);
$gateways = array_merge($head, $mollie_gateways, $tail);
return $gateways;
}


/**
* Retrieves and returns an order by id or false if its key is valid
* @param $id
* @param $key
* @param $ignore_key
* @return bool|WC_Order
*/
public function order_get($id, $key)
public function order_get($id, $key, $ignore_key = FALSE)
{
global $wpdb;
$q = $wpdb->get_row("SELECT * FROM `$wpdb->posts` WHERE `post_type` = 'shop_order' AND `id` = '" . (int) $id . "'", 'ARRAY_A');
Expand All @@ -301,7 +308,7 @@ public function order_get($id, $key)
return FALSE;
}
$order = new WC_Order($id);
if (!$order->key_is_valid($key))
if (!$ignore_key && !$order->key_is_valid($key))
{
return FALSE;
}
Expand Down Expand Up @@ -361,9 +368,10 @@ public function set_default_gateway($code = '')
return $code;
}
// If on payment page and 'mpm' is selected, return correct gateway
if ($code === 'mpm' && !empty($this->methods))
$methods = $this->get_methods();
if ($code === 'mpm' && !empty($methods))
{
return current($this->methods)->id;
return current($methods)->id;
}
// Return default value
return $code;
Expand Down

0 comments on commit 7a4eee6

Please sign in to comment.