/** * Used to proccess the payment * * @param int $order_id * @return * */ public function process_payment($order_id) { //give command to open the modal box $token = isset($_POST['everypayToken']) ? $_POST['everypayToken'] : 0; if (!$token) { echo $this->show_button(); exit; } //continue to payment global $error, $current_user, $woocommerce; try { $wc_order = new WC_Order($order_id); $grand_total = $wc_order->order_total; $amount = $this->format_the_amount($grand_total); $description = get_bloginfo('name') . ' / ' . __('Order') . ' #' . $wc_order->get_order_number() . ' - ' . number_format($amount / 100, 2, ',', '.') . '€'; $data = array('description' => $description, 'amount' => $amount, 'payee_email' => $wc_order->billing_email, 'payee_phone' => $wc_order->billing_phone, 'token' => $token, 'max_installments' => $this->everypay_get_installments($amount / 100, $this->everypayMaxInstallments)); // --------------- Enable for debug ------------- /* $error = var_export($data, true); wc_add_notice($error, $notice_type = 'error'); WC()->session->reload_checkout = true; return; */ Everypay::setApiKey($this->everypaySecretKey); $response = Everypay::addPayment($data); if (isset($response['body']['error'])) { $error = $response['body']['error']['message']; $trimmed = trim($this->get_option('everypay_error_message')); if (!empty($trimmed)) { $error = $this->get_option('everypay_error_message'); } wc_add_notice($error, $notice_type = 'error'); WC()->session->reload_checkout = true; } else { //wc_add_notice('Payment success!'); $dt = new DateTime("Now"); $timestamp = $dt->format('Y-m-d H:i:s e'); $token = $response['body']['token']; $wc_order->add_order_note(__('Everypay payment completed at-' . $timestamp . '-with Token ID=' . $token, 'woocommerce')); $wc_order->payment_complete($token); $wc_order->get_order(); add_post_meta($order_id, 'token', $token); WC()->cart->empty_cart(); $responseData = array('result' => 'success', 'redirect' => $this->get_return_url($wc_order)); return $responseData; } } catch (\Exception $e) { $error = $e->getMessage(); $trimmed = trim($this->get_option('everypay_error_message')); if (!empty($trimmed)) { $error = $this->get_option('everypay_error_message'); } wc_add_notice($error, $notice_type = 'error'); WC()->session->reload_checkout = true; } return; }