/** * Get Komoju Args for passing to Komoju hosted page * * @param WC_Order $order * @return array */ protected function get_komoju_args($order, $method) { WC_Gateway_Komoju::log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url); $params = array("transaction[amount]" => $order->get_subtotal() + $order->get_total_shipping(), "transaction[currency]" => get_woocommerce_currency(), "transaction[customer][email]" => $order->billing_email, "transaction[customer][phone]" => $order->billing_phone, "transaction[customer][given_name]" => $order->billing_first_name, "transaction[customer][family_name]" => $order->billing_last_name, "transaction[external_order_num]" => $this->gateway->get_option('invoice_prefix') . $order->get_order_number() . '-' . $this->request_id, "transaction[return_url]" => $this->gateway->get_return_url($order), "transaction[cancel_url]" => $order->get_cancel_order_url_raw(), "transaction[callback_url]" => $this->notify_url, "transaction[tax]" => strlen($order->get_total_tax()) == 0 ? 0 : $order->get_total_tax(), "timestamp" => time()); WC_Gateway_Komoju::log('Raw parametres: ' . print_r($params, true)); $qs_params = array(); foreach ($params as $key => $val) { $qs_params[] = urlencode($key) . '=' . urlencode($val); } sort($qs_params); $query_string = implode('&', $qs_params); $url = $this->Komoju_endpoint . $method . '/new' . '?' . $query_string; $hmac = hash_hmac('sha256', $url, $this->gateway->secretKey); $query_string .= '&hmac=' . $hmac; return $query_string; }
/** * Logging method * @param string $message */ public static function log($message) { if (self::$log_enabled) { if (empty(self::$log)) { self::$log = new WC_Logger(); } self::$log->add('komoju', $message); } }
/** * Get the order from the Komoju 'transaction' variable * * @param array $transaction Data passed back by Komoju * @param string $invoice_prefix set as an option in Komoju plugin dashboard * @return bool|WC_Order object */ protected function get_komoju_order($transaction, $invoice_prefix) { // We have the data in the correct format, so get the order if (is_string($transaction['external_order_num'])) { $order_id = $transaction['external_order_num']; // Nothing was found } else { WC_Gateway_Komoju::log('Error: Order ID (external_order_num) was not found in "transaction".'); return false; } if (!($order = wc_get_order(substr($order_id, strlen($invoice_prefix), -7)))) { WC_Gateway_Komoju::log('Error: Cannot locate order in WC with order_id: .' . $order_id . ' minus prefix: ' . $invoice_prefix); return false; } return $order; }
/** * Handle a refunded order * @param WC_Order $order */ protected function payment_status_refunded($order, $posted) { // Only handle full refunds, not partial WC_Gateway_Komoju::log('Only handling full refund. Controlling that order total equals amount refunded. Does ' . $order->get_total() . ' equals ' . $posted['grand_total'] . ' ?'); if ($order->get_total() == $posted['grand_total']) { // Mark order as refunded $order->update_status('refunded', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['status']))); /*$this->send_ipn_email_notification( sprintf( __( 'Payment for order #%s refunded/reversed', 'woocommerce' ), $order->get_order_number() ), sprintf( __( 'Order #%s has been marked as refunded - Komoju reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] ) );*/ } }