protected function callEbanxLib() { require_once LC_DIR_MODULES . 'EBANX/EBANX/ebanx-php/src/autoload.php'; $method = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findOneBy(array('service_name' => 'Ebanx')); $test = $method->getSetting('test'); \Ebanx\Config::set(array('integrationKey' => $method->getSetting('integrationkey'), 'testMode' => $method->getSetting('test') == 'true' ? true : false)); }
* All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of EBANX nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require_once Mage::getBaseDir('lib') . '/Ebanx/src/autoload.php'; $ebanxConfig = Mage::getStoreConfig('payment/ebanx'); \Ebanx\Config::set(array('integrationKey' => $ebanxConfig['integration_key'], 'testMode' => intval($ebanxConfig['testing']) == 1, 'directMode' => false));
<?php require '../../../wp-load.php'; $servername = DB_HOST; $username = DB_USER; $password = DB_PASSWORD; $database = DB_NAME; $args = array('status' => '', 'customer_id' => '3', 'customer_note' => 'Cobranca', 'order_id' => 0); $ebanx = new WC_Gateway_Ebanx(); \Ebanx\Config::set(array('integrationKey' => $ebanx->merchant_key, 'testMode' => $ebanx->test_mode, 'directMode' => true)); $data = date('d'); try { $conn = new PDO("mysql:host={$servername};dbname={$database}", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // echo "Connected successfully 2\n"; $sql = "SELECT * FROM ebanx_token WHERE DATE_FORMAT(data,'%d') = {$data}"; //$sql = "SELECT * FROM ebanx_token"; $result = $conn->query($sql); //$result = $result->fetch (PDO::FETCH_ASSOC); while ($data = $result->fetch(PDO::FETCH_ASSOC)) { $args = array('status' => '', 'customer_id' => $data['customer_id'], 'customer_note' => '', 'created_via' => 'EBANX Recurring cron', 'order_id' => 0); $order = new WC_Order($data['order_id']); $streetNumber = isset($order->billing_number) ? $order->billing_number : '1'; $newOrder = wc_create_order($args); update_post_meta($newOrder->id, '_order_total', $order->order_total); $params = array('mode' => 'full', 'operation' => 'request', 'payment' => array('merchant_payment_code' => $newOrder->id, 'order_number' => $newOrder->id, 'amount_total' => $order->order_total, 'currency_code' => $data['currency_code'], 'name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'email' => $order->billing_email, 'birth_date' => $data['birth_date'], 'address' => $order->billing_address_1, 'street_number' => $streetNumber, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zipcode' => $order->billing_postcode, 'country' => $order->billing_country, 'phone_number' => $order->billing_phone, 'payment_type_code' => $data['payment_type_code'], 'document' => $order->billing_cpf, 'creditcard' => array('token' => $data['token']))); $response = \Ebanx\Ebanx::doRequest($params); if (isset($response->status) && $response->status == 'SUCCESS') { if ($response->payment->status == 'CA') { $newOrder->add_order_note('Payment failed.');
/** * Generates the EBANX button link * @return string */ public function generate_ebanx_form($order_id) { global $woocommerce; $servername = DB_HOST; $username = DB_USER; $password = DB_PASSWORD; $database = DB_NAME; // Set EBANX configs \Ebanx\Config::set(array('integrationKey' => $this->merchant_key, 'testMode' => $this->test_mode, 'directMode' => true)); // Loads the current order $order = new WC_Order($order_id); // If is GET, do nothing, otherwise process the request if ($_SERVER['REQUEST_METHOD'] === 'GET') { $this->_renderCheckout($order_id); return; } $order = new WC_Order($order_id); $streetNumber = isset($order->billing_number) ? $order->billing_number : '1'; $paymentMethod = isset($_POST['ebanx']['method']) ? $_POST['ebanx']['method'] : ''; $countryCode = $order->billing_country; // Append timestamp on test mode $orderId = $this->test_mode ? $order_id . time() : $order_id; $params = array('mode' => 'full', 'operation' => 'request', 'payment' => array('merchant_payment_code' => $orderId, 'order_number' => $order_id, 'amount_total' => $order->order_total, 'currency_code' => get_woocommerce_currency(), 'name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'email' => $order->billing_email, 'birth_date' => $this->getBirthdateFromRequest(true), 'address' => $order->billing_address_1, 'street_number' => $streetNumber, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zipcode' => $order->billing_postcode, 'country' => $order->billing_country, 'phone_number' => $order->billing_phone, 'payment_type_code' => $_POST['ebanx']['cc_type'], 'document' => $order->billing_cpf)); $ccExpiration = str_pad($_POST['ebanx']['cc_expiration_month'], 2, '0', STR_PAD_LEFT) . '/' . $_POST['ebanx']['cc_expiration_year']; try { $token = \Ebanx\Ebanx::doToken(['payment_type_code' => $_POST['ebanx']['cc_type'], 'creditcard' => ['card_number' => $_POST['ebanx']['cc_number'], 'card_name' => $_POST['ebanx']['cc_name'], 'card_due_date' => $ccExpiration, 'card_cvv' => $_POST['ebanx']['cc_cvv']]]); } catch (Exception $e) { $_SESSION['ebanxError'] = $e->getMessage(); $this->_renderCheckout($order_id); return; } if ($token->status == "ERROR") { $_SESSION['ebanxError'] = "Erro ao processar pagamento: " . $token->status_message; $this->_renderCheckout($order_id); return; } $customer = wp_get_current_user(); $customer_id = $customer->data->ID; $order_id_from_object = $order->id; $currency_code = $params['payment']['currency_code']; $payment_type_code = $params['payment']['payment_type_code']; $birth_date = $params['payment']['birth_date']; try { $conn = new PDO("mysql:host={$servername};dbname={$database}", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } try { $params['payment']['creditcard'] = array('token' => $token->token); $response = \Ebanx\Ebanx::doRequest($params); if ($response->status == 'SUCCESS') { $sql = "CREATE TABLE IF NOT EXISTS `ebanx_token` (\n `id` INT AUTO_INCREMENT NOT NULL,\n `data` datetime NOT NULL,\n `token` varchar(200),\n `customer_id` varchar(200),\n `order_id` varchar(200),\n `currency_code` varchar(200),\n `birth_date` varchar(200),\n `payment_type_code` varchar(200),\n PRIMARY KEY (`id`)) "; $conn->query($sql); date_default_timezone_set('America/Sao_Paulo'); $month = date('m'); $year = date('Y'); $day = date('d'); if ($day > '28' && $month == '02') { $day = '28'; } else { if ($day == '31') { $day = '01'; } } $date = $year . '-' . $month . '-' . $day; $sql = "INSERT INTO ebanx_token (data, token, customer_id, order_id, currency_code, birth_date, payment_type_code)\n VALUES ('{$date}', '{$token->token}', '{$customer_id}', '{$order_id_from_object}', '{$currency_code}', '{$birth_date}', '{$payment_type_code}')"; $conn->query($sql); // Clear cart $woocommerce->cart->empty_cart(); if ($paymentMethod == 'boleto') { $boletoUrl = $response->payment->boleto_url; $orderUrl = $order->get_checkout_order_received_url($order); $tplDir = dirname(__FILE__) . '/view/'; $template = file_get_contents($tplDir . 'success/boleto.php'); echo eval(' ?>' . $template . '<?php '); } else { if ($paymentMethod == 'pagoefectivo') { $cipUrl = $response->payment->cip_url; $cipCode = $response->payment->cip_code; $orderUrl = $order->get_checkout_order_received_url($order); $tplDir = dirname(__FILE__) . '/view/'; $template = file_get_contents($tplDir . 'success/pagoefectivo.php'); echo eval(' ?>' . $template . '<?php '); } else { if ($paymentMethod == 'tef') { wp_redirect($response->redirect_url); } else { wp_redirect($this->get_return_url($order)); } } } } else { $_SESSION['ebanxError'] = $this->getEbanxErrorMessage($response->status_code, $countryCode); $this->_renderCheckout($order_id); } } catch (Exception $e) { $_SESSION['ebanxError'] = $e->getMessage(); $this->_renderCheckout($order_id); } $conn = null; }