merchant has disconnected the order from the order manager. if ($order->get_meta('_kom_disconnect')) { return new \WP_Error('order_sync_off', 'Order management is disabled'); } // Check if the order has been paid. if (empty($order->get_date_paid())) { return new \WP_Error('not_paid', 'Order has not been paid.'); } // Changes are only possible if order is an allowed order status. if (!\in_array($order->get_status(), apply_filters('kom_allowed_update_statuses', array('on-hold')), \true)) { return new \WP_Error('not_allowed_status', 'Order is not in allowed status.'); } // Retrieve Klarna order first. $klarna_order = $this->retrieve_klarna_order($order_id); if (is_wp_error($klarna_order)) { $order->add_order_note('Klarna order could not be updated due to an error.'); $order->save(); return new \WP_Error('object_error', 'Klarna order object is of type WP_Error.', $klarna_order); } if (!\in_array($klarna_order->status, array('CANCELLED', 'CAPTURED', 'PART_CAPTURED'), \true)) { $request = new RequestPatchUpdate($this, array('request' => 'update_order_lines', 'order_id' => $order_id, 'klarna_order' => $klarna_order)); $response = $request->request(); if (!is_wp_error($response)) { $order->add_order_note('Klarna order updated.'); $order->save(); } else { $reason = $response->get_error_message(); if (!empty($reason)) { // translators: %s: error message from Klarna. $order_note = \sprintf(__('Could not update Klarna order lines: %s.', 'klarna-order-management'), $reason); } else { $order_note = __('Could not update Klarna order lines. An unknown error occurred.', 'klarna-order-management'); } $order->add_order_note($order_note); $order->save(); return new \WP_Error('unknown_error', 'Response object is of type WP_Error.', $response); } } } return \true; } /** * Captures a Klarna order. * * @param int $order_id Order ID. * @param bool $action If this was triggered by an action. * * @return bool|WP_Error Returns bool true if capture was successful or a WP_Error object if not. */ public function capture_klarna_order($order_id, $action = \false) { $options = $this->settings->get_settings($order_id); $order = wc_get_order($order_id); // If the order was not paid using the plugin that instanced this class, bail. if (!Utility::check_plugin_instance($this->plugin_instance, $order->get_payment_method())) { return; } if (!isset($options['kom_auto_capture']) || 'yes' === $options['kom_auto_capture'] || $action) { // The merchant has disconnected the order from the order manager. if ($order->get_meta('_kom_disconnect')) { return new \WP_Error('order_sync_off', 'Order management is disabled'); } // Check if the order has been paid. if (empty($order->get_date_paid())) { return new \WP_Error('not_paid', 'Order has not been paid.'); } // Not going to do this for non-KP and non-KCO orders. if (!\in_array($order->get_payment_method(), array('klarna_payments', 'kco'), \true)) { return new \WP_Error('not_klarna_order', 'Order does not have klarna_payments or kco payment method.'); } // Do nothing if Klarna order was already captured. if ($order->get_meta('_wc_klarna_capture_id', \true)) { $order->add_order_note('Klarna order has already been captured.'); $order->save(); return new \WP_Error('already_captured', 'Order has already been captured.'); } // Do nothing if we don't have Klarna order ID. if (!$order->get_meta('_wc_klarna_order_id', \true) && !$order->get_transaction_id()) { $order->update_status('on-hold', 'Klarna order ID is missing, Klarna order could not be captured at this time.'); return new \WP_Error('klarna_id_missing', 'Klarna order id is missing for order.'); } // Retrieve Klarna order. $klarna_order = $this->retrieve_klarna_order($order_id); if (is_wp_error($klarna_order)) { $order->update_status('on-hold', 'Klarna order could not be captured due to an error.'); return new \WP_Error('object_error', 'Klarna order object is of type WP_Error.', $klarna_order); } // Check if order is pending review. if ('PENDING' === $klarna_order->fraud_status) { $order->update_status('on-hold', 'Klarna order is pending review and could not be captured at this time.'); return new \WP_Error('pending_fraud_review', 'Order is pending fraud review and cannot be captured.'); } // Check if Klarna order has already been captured. if (\in_array($klarna_order->status, array('CAPTURED'), \true)) { $order->add_order_note('Klarna order has already been captured on ' . $klarna_order->captures[0]->captured_at); $order->update_meta_data('_wc_klarna_capture_id', $klarna_order->captures[0]->capture_id); $order->save(); return new \WP_Error('already_captured', 'Order has already been captured.'); } // Check if Klarna order has already been canceled. if ('CANCELLED' === $klarna_order->status) { $order->add_order_note('Klarna order failed to capture, the order has already been canceled'); $order->save(); return new \WP_Error('klarna_order_cancelled', 'Order is cancelled. Capture failed.'); } // Only send capture request if Klarna order fraud status is accepted. if ('ACCEPTED' !== $klarna_order->fraud_status) { $order->add_order_note('Klarna order could not be captured at this time.'); $order->save(); return new \WP_Error('pending_fraud_review', 'Order is pending fraud review and cannot be captured.'); } else { $request = new RequestPostCapture($this, array('request' => 'capture', 'order_id' => $order_id, 'klarna_order' => $klarna_order)); $response = $request->request(); if (!is_wp_error($response)) { $order->add_order_note('Klarna order captured. Capture amount: ' . $order->get_formatted_order_total('', \false) . '. Capture ID: ' . $response); $order->update_meta_data('_wc_klarna_capture_id', $response); $order->save(); return \true; } else { /* The suggested approach by Klarna is to try again after some time. If that still fails, the merchant should inform the customer, and ask them to either "create a new subscription or add funds to their payment method if they wish to continue." */ if (isset($response->get_error_data()['code']) && 403 === $response->get_error_data()['code'] && 'PAYMENT_METHOD_FAILED' === $response->get_error_code()) { $order->update_status('on-hold', __('Klarna could not charge the customer. Please try again later. If that still fails, the customer may have to create a new subscription or add funds to their payment method if they wish to continue.', 'klarna-order-management')); return new \WP_Error('capture_failed', 'Capture failed. Please try again later.'); } else { $error_message = $response->get_error_message(); if (!\is_array($error_message) && \false !== \strpos($error_message, 'Captured amount is higher than the remaining authorized amount.')) { $error_message = \str_replace('. Capture not possible.', \sprintf(': %s %s.', $klarna_order->remaining_authorized_amount / 100, $klarna_order->purchase_currency), $error_message); } // translators: %s: Error message from Klarna. $order->update_status('on-hold', \sprintf(__('Could not capture Klarna order. %s', 'klarna-order-management'), $error_message)); return new \WP_Error('capture_failed', 'Capture failed.', $error_message); } } if ($order->save()) { return \true; } else { return new \WP_Error('save_error', 'Could not save WooCommerce order object.'); } } } } /** * Refund a Klarna order. * * @param bool $result Refund attempt result. * @param int $order_id WooCommerce order ID. * @param null|string $amount Refund amount, full order amount if null. * @param string $reason Refund reason. * * @return bool|WP_Error Returns bool true if refund was successful or a WP_Error object if not. */ public function refund_klarna_order($result, $order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); // If the order was not paid using the plugin that instanced this class, bail. if (!Utility::check_plugin_instance($this->plugin_instance, $order->get_payment_method())) { return; } // The merchant has disconnected the order from the order manager. if ($order->get_meta('_kom_disconnect')) { return new \WP_Error('order_sync_off', 'Order management is disabled'); } // Not going to do this for non-KP and non-KCO orders. if (!\in_array($order->get_payment_method(), array('klarna_payments', 'kco'), \true)) { return new \WP_Error('not_klarna_order', 'Order does not have klarna_payments or kco payment method.'); } // Do nothing if Klarna order is not captured. if (!$order->get_meta('_wc_klarna_capture_id', \true)) { $order->add_order_note('Klarna order has not been captured and cannot be refunded.'); $order->save(); return new \WP_Error('not_captured', 'Order has not been captured and cannot be refunded.'); } // Retrieve Klarna order first. $klarna_order = $this->retrieve_klarna_order($order_id); if (is_wp_error($klarna_order)) { $order->add_order_note('Could not capture Klarna order. ' . $klarna_order->get_error_message() . '.'); $order->save(); return new \WP_Error('object_error', 'Klarna order object is of type WP_Error.', $klarna_order); } if (\in_array($klarna_order->status, array('CAPTURED', 'PART_CAPTURED'), \true)) { $request = new RequestPostRefund($this, array('order_id' => $order_id, 'refund_amount' => $amount, 'refund_reason' => $reason)); $response = $request->request(); if (!is_wp_error($response)) { $order->add_order_note(wc_price($amount, array('currency' => $order->get_currency())) . ' refunded via Klarna.'); $order->save(); return \true; } else { $order->add_order_note('Could not refund Klarna order. ' . $response->get_error_message() . '.'); $order->save(); return new \WP_Error('unknown_error', 'Response object is of type WP_Error.', $response); } } } /** * Retrieve a Klarna order. * * @param int $order_id WooCommerce order ID. * * @return object $klarna_order Klarna Order. */ public function retrieve_klarna_order($order_id) { $request = new RequestGetOrder($this, array('order_id' => $order_id)); $klarna_order = $request->request(); return $klarna_order; } } 1 - Uncaught Error: Class 'KrokedilKlarnaPaymentsDeps\Krokedil\KlarnaOrderManagement\KlarnaOrderManagement' not found in /home/st20space2tech/public_html/site/wp-content/plugins/klarna-payments-for-woocommerce/klarna-payments-for-woocommerce.php:310 Stack trace: #0 /home/st20space2tech/public_html/site/wp-includes/class-wp-hook.php(341): WC_Klarna_Payments->init('') #1 /home/st20space2tech/public_html/site/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array) #2 /home/st20space2tech/public_html/site/wp-includes/plugin.php(522): WP_Hook->do_action(Array) #3 /home/st20space2tech/public_html/site/wp-settings.php(622): do_action('plugins_loaded') #4 /home/st20space2tech/public_html/site/wp-config.php(92): require_once('/home/st20space...') #5 /home/st20space2tech/public_html/site/wp-load.php(50): require_once('/home/st20space...') #6 /home/st20space2tech/public_html/site/wp-blog-header.php(13): require_once('/home/st20space...') #7 /home/st20space2tech/public_html/site/index.php(17): require('/home/ - /home/st20space2tech/public_html/site/wp-content/plugins/klarna-payments-for-woocommerce/klarna-payments-for-woocommerce.php - 310