Esempio n. 1
0
function tinklit_update_status()
{
    global $db;
    require_once 'tinklit/tinklit_lib.php';
    $tinkl_info_sql = "SELECT configuration_value\n                            FROM " . TABLE_CONFIGURATION . "\n                            WHERE configuration_key = 'MODULE_PAYMENT_TINKLIT_CLIENTID'";
    $tinkl_info = $db->execute($tinkl_info_sql);
    $clientid = $tinkl_info->fields['configuration_value'];
    $tinkl_info_sql = "SELECT configuration_value\n                            FROM " . TABLE_CONFIGURATION . "\n                            WHERE configuration_key = 'MODULE_PAYMENT_TINKLIT_TOKEN'";
    $tinkl_info = $db->execute($tinkl_info_sql);
    $tokenid = $tinkl_info->fields['configuration_value'];
    $tinkl_orders_sql = "SELECT guid, order_id FROM " . TABLE_TINKLIT . "\n                            WHERE status = 'pending'\n                            AND time_created > '" . date('Y-m-d h:i:s', date('U') - 15 * 60) . "'";
    //echo $tinkl_orders_sql; exit();
    $tinkl_orders = $db->execute($tinkl_orders_sql);
    while (!$tinkl_orders->EOF) {
        $guid = $tinkl_orders->fields['guid'];
        $options = array('guid' => $tinkl_info->fields['guid']);
        $post = json_encode($options);
        //  create invoice
        //$invoice = tinklitCurl('https://api-staging.tinkl.it/v1/invoices', MODULE_PAYMENT_TINKLIT_CLIENTID, MODULE_PAYMENT_TINKLIT_TOKEN, $post);
        $invoice = tinklitCurl('https://api.tinkl.it/invoices/' . $guid, $clientid, $tokenid);
        //echo $guid;
        //echo '<pre>'; print_r($invoice); echo '</pre>'; //exit();
        if ($invoice['status'] == 'payed') {
            $get_status_sql = "SELECT orders_status FROM " . TABLE_ORDERS . "\n                                WHERE orders_id = '" . $tinkl_orders->fields['order_id'] . "'";
            $get_status = $db->execute($get_status_sql);
            if ($get_status->fields['orders_status'] != '2') {
                $db->Execute("update " . TABLE_ORDERS . "\n                                set orders_status = '2', last_modified = now()\n                                where orders_id = '" . $tinkl_orders->fields['order_id'] . "'");
                $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . "\n                              (orders_id, orders_status_id, date_added, customer_notified, comments)\n                              values ('" . $tinkl_orders->fields['order_id'] . "',\n                              '2',\n                              now(),\n                              '0',\n                              'Order successfully payed')");
                $db->Execute("update " . TABLE_TINKLIT . "\n                                set status = 'payed'\n                                where order_id = '" . $tinkl_orders->fields['order_id'] . "'");
            }
        }
        $tinkl_orders->MoveNext();
    }
}
Esempio n. 2
0
$tinkl_info_sql = "SELECT configuration_value\r\n                        FROM " . TABLE_CONFIGURATION . "\r\n                        WHERE configuration_key = 'MODULE_PAYMENT_TINKLIT_CLIENTID'";
$tinkl_info = $db->execute($tinkl_info_sql);
$clientid = $tinkl_info->fields['configuration_value'];
$tinkl_info_sql = "SELECT configuration_value\r\n                        FROM " . TABLE_CONFIGURATION . "\r\n                        WHERE configuration_key = 'MODULE_PAYMENT_TINKLIT_TOKEN'";
$tinkl_info = $db->execute($tinkl_info_sql);
$tokenid = $tinkl_info->fields['configuration_value'];
$tinkl_orders_sql = "SELECT guid, order_id FROM " . TABLE_TINKLIT . "\r\n                        WHERE status = 'pending'\r\n                        AND time_created BETWEEN '" . date('Y-m-d h:i:s', date('U') - 15 * 60) . "' AND '" . date('Y-m-d h:i:s') . "'";
//echo $tinkl_orders_sql; exit();
$tinkl_orders = $db->execute($tinkl_orders_sql);
while (!$tinkl_orders->EOF) {
    $guid = $tinkl_orders->fields['guid'];
    $options = array('guid' => $tinkl_info->fields['guid']);
    $post = json_encode($options);
    //  create invoice
    //$invoice = tinklitCurl('https://api-staging.tinkl.it/v1/invoices', MODULE_PAYMENT_TINKLIT_CLIENTID, MODULE_PAYMENT_TINKLIT_TOKEN, $post);
    $invoice = tinklitCurl('https://api.tinkl.it/invoices/' . $guid, $clientid, $tokenid);
    echo $guid;
    echo '<pre>';
    print_r($invoice);
    echo '</pre>';
    //exit();
    if ($invoice['status'] == 'payed') {
        $get_status_sql = "SELECT orders_status FROM " . TABLE_ORDERS . "\r\n                            WHERE orders_id = '" . $tinkl_orders->fields['order_id'] . "'";
        $get_status = $db->execute($get_status_sql);
        if ($get_status->fields['orders_status'] != '2') {
            $db->Execute("update " . TABLE_ORDERS . "\r\n                            set orders_status = '2', last_modified = now()\r\n                            where orders_id = '" . $tinkl_orders->fields['order_id'] . "'");
            $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . "\r\n                          (orders_id, orders_status_id, date_added, customer_notified, comments)\r\n                          values ('" . $tinkl_orders->fields['order_id'] . "',\r\n                          '2',\r\n                          now(),\r\n                          '0',\r\n                          'Order successfully payed')");
            $db->Execute("update " . TABLE_TINKLIT . "\r\n                            set status = 'payed'\r\n                            where order_id = '" . $tinkl_orders->fields['order_id'] . "'");
        }
    }
    $tinkl_orders->MoveNext();
Esempio n. 3
0
 function after_process()
 {
     global $insert_id, $order, $currencies;
     require_once 'tinklit/tinklit_lib.php';
     // change order status to value selected by merchant
     tep_db_query("update " . TABLE_ORDERS . " set orders_status = " . $this->order_status . " where orders_id = " . intval($insert_id));
     $options = array('price' => $currencies->currencies['EUR']['value'] * $order->info['total'], 'currency' => 'EUR', 'order_id' => $insert_id, 'notification_url' => HTTP_SERVER . DIR_WS_CATALOG . 'tinklit_callback.php', 'redirect_url' => tep_href_link(FILENAME_ACCOUNT, 'tinklit=update_status'));
     //echo '<pre>'; print_r($options); echo '</pre>'; exit();
     $post = json_encode($options);
     //  create invoice
     //$invoice = tinklitCurl('https://api-staging.tinkl.it/v1/invoices', MODULE_PAYMENT_TINKLIT_CLIENTID, MODULE_PAYMENT_TINKLIT_TOKEN, $post);
     $invoice = tinklitCurl('https://api.tinkl.it/v1/invoices', MODULE_PAYMENT_TINKLIT_CLIENTID, MODULE_PAYMENT_TINKLIT_TOKEN, $post);
     //echo '<pre>'; print_r($invoice); echo '</pre>'; exit();
     if (!is_array($invoice) or array_key_exists('error', $invoice)) {
         $this->log('createInvoice error ' . var_export($invoice['error'], true));
         zen_remove_order($insert_id, $restock = true);
         // unfortunately, there's not a good way of telling the customer that it's hosed.  Their cart is still full so they can try again w/ a different payment option.
     } else {
         $insert_sql = "INSERT INTO " . TABLE_TINKLIT . "\n                            (order_id, guid, status, btc_price, invoice_time, payment_confidence, time_created)\n                            VALUES ('" . $invoice['order_id'] . "', '" . $invoice['guid'] . "', '" . $invoice['status'] . "', '" . $invoice['btc_price'] . "', '" . $invoice['invoice_time'] . "', '" . $invoice['payment_confidence'] . "', now())";
         tep_db_query($insert_sql);
         $_SESSION['cart']->reset(true);
         tep_redirect($invoice['url']);
     }
     return false;
 }