/** * Refund order in Klarna system * * @param integer $orderid * @param integer $amount * @param string $reason * * @return bool * @since 2.0.0 */ public function process_refund($orderid, $amount = null, $reason = '') { // Check if order was created using this method if ($this->id == get_post_meta($orderid, '_payment_method', true)) { $order = wc_get_order($orderid); if (!$this->can_refund_order($order)) { if ($this->debug == 'yes') { $this->log->add('klarna', 'Refund Failed: No Klarna invoice ID.'); } $order->add_order_note(__('This order cannot be refunded. Please make sure it is activated.', 'woocommerce-gateway-klarna')); return false; } if ('v2' == get_post_meta($order->id, '_klarna_api', true)) { $country = get_post_meta($orderid, '_billing_country', true); $klarna = new Klarna(); $this->configure_klarna($klarna, $country); $invNo = get_post_meta($order->id, '_klarna_invoice_number', true); $klarna_order = new WC_Gateway_Klarna_Order($order, $klarna); $refund_order = $klarna_order->refund_order($amount, $reason, $invNo); } elseif ('rest' == get_post_meta($order->id, '_klarna_api', true)) { $country = get_post_meta($orderid, '_billing_country', true); /** * Need to send local order to constructor and Klarna order to method */ if ($this->testmode == 'yes') { if ('gb' == strtolower($country)) { $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL; } elseif ('us' == strtolower($country)) { $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_TEST_BASE_URL; } } else { if ('gb' == strtolower($country)) { $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_BASE_URL; } elseif ('us' == strtolower($country)) { $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_BASE_URL; } } if ('gb' == strtolower($country)) { $connector = Klarna\Rest\Transport\Connector::create($this->eid_uk, $this->secret_uk, $klarna_server_url); } elseif ('us' == strtolower($country)) { $connector = Klarna\Rest\Transport\Connector::create($this->eid_us, $this->secret_us, $klarna_server_url); } $klarna_order_id = get_post_meta($orderid, '_klarna_order_id', true); $k_order = new Klarna\Rest\OrderManagement\Order($connector, $klarna_order_id); $k_order->fetch(); $klarna_order = new WC_Gateway_Klarna_Order($order); $refund_order = $klarna_order->refund_order_rest($amount, $reason, $k_order); } if ($refund_order) { return true; } } return false; }
/** * Refund order in Klarna system * * @param integer $orderid * @param integer $amount * @param string $reason * * @return bool * @since 2.0.0 */ public function process_refund($orderid, $amount = null, $reason = '') { // Check if order was created using this method if ($this->id == get_post_meta($orderid, '_payment_method', true)) { $order = wc_get_order($orderid); if (!$this->can_refund_order($order)) { if ($this->debug == 'yes') { $this->log->add('klarna', 'Refund Failed: No Klarna invoice ID.'); } $order->add_order_note(__('This order cannot be refunded. Please make sure it is activated.', 'woocommerce-gateway-klarna')); return false; } $country = get_post_meta($orderid, '_billing_country', true); $klarna = new Klarna(); $this->configure_klarna($klarna, $country); $invNo = get_post_meta($order->id, '_klarna_invoice_number', true); $klarna_order = new WC_Gateway_Klarna_Order($order, $klarna); $refund_order = $klarna_order->refund_order($amount, $reason = '', $invNo); if ($refund_order) { return true; } } return false; }