/** * Process a refund if supported * @param int $order_id * @param float $amount * @param string $reason * @return bool|wp_error True or false based on success, or a WP_Error object * @since WooCommerce 2.2 */ public function process_refund($order_id, $amount = null, $reason = '') { $order = Mollie_WC_Plugin::getDataHelper()->getWcOrder($order_id); if (!$order) { Mollie_WC_Plugin::debug('process_refund - could not find order ' . $order_id); return false; } try { $payment = Mollie_WC_Plugin::getDataHelper()->getActiveMolliePayment($order_id); if (!$payment) { Mollie_WC_Plugin::debug('process_refund - could not find active Mollie payment for order ' . $order_id); return false; } elseif (!$payment->isPaid()) { Mollie_WC_Plugin::debug('process_refund - could not refund payment ' . $payment->id . ' (not paid). Order ' . $order_id); return false; } Mollie_WC_Plugin::debug('process_refund - create refund - payment: ' . $payment->id . ', order: ' . $order_id . ', amount: ' . $amount . (!empty($reason) ? ', reason: ' . $reason : '')); do_action(Mollie_WC_Plugin::PLUGIN_ID . '_create_refund', $payment, $order); // Is test mode enabled? $test_mode = Mollie_WC_Plugin::getSettingsHelper()->isTestModeEnabled(); // Send refund to Mollie $refund = Mollie_WC_Plugin::getApiHelper()->getApiClient($test_mode)->payments->refund($payment, $amount); Mollie_WC_Plugin::debug('process_refund - refund created - refund: ' . $refund->id . ', payment: ' . $payment->id . ', order: ' . $order_id . ', amount: ' . $amount . (!empty($reason) ? ', reason: ' . $reason : '')); do_action(Mollie_WC_Plugin::PLUGIN_ID . '_refund_created', $refund, $order); $order->add_order_note(sprintf(__('Refunded %s%s (reason: %s) - Payment ID: %s, Refund: %s', 'mollie-payments-for-woocommerce'), get_woocommerce_currency_symbol(), $amount, $reason, $refund->payment->id, $refund->id)); return true; } catch (Exception $e) { return new WP_Error(1, $e->getMessage()); } }
/** * @param bool $test_mode (default: false) * @param string|null $method * @return array|Mollie_API_Object_Issuer[]|Mollie_API_Object_List */ public function getIssuers($test_mode = false, $method = NULL) { $locale = $this->getCurrentLocale(); try { $transient_id = $this->getTransientId('api_issuers_' . ($test_mode ? 'test' : 'live') . "_{$locale}"); if (empty(self::$api_issuers)) { $cached = @unserialize(get_transient($transient_id)); if ($cached && $cached instanceof Mollie_API_Object_List) { self::$api_issuers = $cached; } else { self::$api_issuers = $this->api_helper->getApiClient($test_mode)->issuers->all(); set_transient($transient_id, self::$api_issuers, MINUTE_IN_SECONDS * 5); } } // Filter issuers by method if ($method !== NULL) { $method_issuers = array(); foreach (self::$api_issuers as $issuer) { if ($issuer->method === $method) { $method_issuers[] = $issuer; } } return $method_issuers; } return self::$api_issuers; } catch (Mollie_API_Exception $e) { Mollie_WC_Plugin::debug(__FUNCTION__ . ": Could not load Mollie issuers (" . ($test_mode ? 'test' : 'live') . "): " . $e->getMessage() . ' (' . get_class($e) . ')'); } return array(); }