/** * Refund * * @param type $order_id * @param type $amount * @param type $reason * @return boolean */ public function process_refund($order_id, $amount = NULL, $reason = '') { if (!$amount) { return false; } try { $params = array('amount' => preg_replace("/[^0-9]/", '', number_format($amount, 2)), 'description' => $reason); $token = get_post_meta($order_id, 'token', true); Everypay::setApiKey($this->everypaySecretKey); $refund = Everypay::refundPayment($token, $params); if (!isset($refund['body']['error'])) { $dt = new DateTime("Now"); $timestamp = $dt->format('Y-m-d H:i:s e'); $refToken = $refund['body']['token']; $wc_order = new WC_Order($order_id); $wc_order->add_order_note(__('Everypay Refund completed at-' . $timestamp . '-with Refund Token=' . $refToken, 'woocommerce')); return true; } else { return false; } } catch (\Exception $e) { return false; } }