Exemplo n.º 1
0
 /**
  * @throws Mollie_WC_Exception_CouldNotConnectToMollie
  */
 public function getMollieApiStatus()
 {
     try {
         // Is test mode enabled?
         $test_mode = Mollie_WC_Plugin::getSettingsHelper()->isTestModeEnabled();
         $api_helper = Mollie_WC_Plugin::getApiHelper();
         $api_client = $api_helper->getApiClient($test_mode);
         // Try to load Mollie issuers
         $api_client->issuers->all();
     } catch (Mollie_API_Exception $e) {
         throw new Mollie_WC_Exception_CouldNotConnectToMollie($e->getMessage(), 0, $e);
     }
 }
Exemplo n.º 2
0
 /**
  * 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());
     }
 }