/** * Process the payment * @param integer $order_id * @return array result & redirect URL */ function process_payment($order_id) { // WooCommerce global global $woocommerce; // Require Triveneto class require 'PgConsTriv.php'; // Get Order Object $order = new WC_Order($order_id); // init PgConsTriv Class for PaymentInit (action Purchase) $pg = new PgConsTriv(ICL_LANGUAGE_CODE, $this->settings); $pg->setAction('Purchase'); // Payment Provider response will be sent to our triveneto_response_interface // Which is defined in 'woocommerce-triveneto-gateway.php' $pg->setResponseURL(get_home_url() . '/?triveneto_response_interface=1'); // Define the goto URL if something goes wrong $pg->setErrorURL($order->get_cancel_order_url()); // Send the message of PaymentInit $amount = $woocommerce->cart->get_cart_total(); $amount = floatval(preg_replace('#[^\\d.]#', '', $amount)); // parse numbers $tracking_id = $order_id; $pg->sendVal_PI($amount, $tracking_id); // Get result of request $hasError = $pg->hasError_PI(); $ID_PI = $pg->getID_PI(); // Check for errors if ($hasError) { $errorCode = $pg->getError_PI(); // Cancel process and redirect to other page: return array('result' => 'error', 'redirect' => $order->get_cancel_order_url()); } // Mark as on-hold (we're awaiting the cheque) $order->update_status('on-hold', __('Awaiting TrivenetoBassilichi payment', 'woocommerce_gateway_tvb')); // Reduce stock levels $order->reduce_order_stock(); // Remove cart $woocommerce->cart->empty_cart(); // Get the payment URL for the customer: $paymentURL = $pg->getPaymentURL_PI(); // Send to payment URL return array('result' => 'success', 'redirect' => $paymentURL); }