Skip to content

Commit

Permalink
Split out the database functions and iproved the inclusion of remote …
Browse files Browse the repository at this point in the history
…libs.
  • Loading branch information
Bèr Kessels committed Feb 10, 2010
1 parent 057234b commit 00538e5
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 72 deletions.
89 changes: 17 additions & 72 deletions ideal_payment_api.module
Expand Up @@ -14,15 +14,6 @@
*/

//First load include based on available lib
$lib = ideal_payment_api_get_lib();
$path_module = drupal_get_path('module', 'ideal_payment_api');
if ($lib == 'thinmpi'){
require_once($path_module.'/ideal_payment_api_thinmpi.inc.php');
}
elseif ($lib == 'connector'){
require_once($path_module.'/ideal_payment_api_connector.inc.php');
}

/**
* Implementation of hook_help().
*/
Expand All @@ -39,7 +30,9 @@ function ideal_payment_api_help($section = '') {
/**
* Implementation of hook_cron().
*/
function ideal_payment_api_cron() {
function ideal_payment_api_cron() {
_ideal_payment_api_include_lib();

// @TODO: insert time-based action firing here.
//@TODO: refres-issuers should be called far less often then recheck.
ideal_payment_api_refresh_issuerlist();
Expand All @@ -50,6 +43,9 @@ function ideal_payment_api_cron() {
* Implementation of hook_menu().
*/
function ideal_payment_api_menu($may_cache) {
_ideal_payment_api_include_lib();


$items = array();

if ($may_cache) {
Expand Down Expand Up @@ -407,7 +403,7 @@ function LoadConfiguration() {
/**
* Lookup installed PHP iDEAL lib
*/
function ideal_payment_api_get_lib() {
function _ideal_payment_api_get_lib() {
$path_module = drupal_get_path('module', 'ideal_payment_api');
if (file_exists($path_module.'/lib/ThinMPI.php')) {
$lib = 'thinmpi'; //Rabo + old ING
Expand All @@ -418,69 +414,18 @@ function ideal_payment_api_get_lib() {
return $lib;
}

/**
* Save order
*/
function ideal_payment_api_order_save(&$order) {
$now = time();
$order['order_id'] = db_next_id('ideal_payment_api_orders');
$order['description'] = theme('ideal_payment_api_description', $order);

$inserted = db_query("INSERT INTO {ideal_payment_api_orders} (oid, user_id, description, amount, issuer_id, transaction_id, payment_status, foreign_id, created_at, updated_at) VALUES
(%d, %d,'%s', %d, '%s', '%s', %d, %d, %d, %d)", $order['order_id'], $order['user_id'], $order['description'],$order['amount'], $order['issuer_id'], $order['transaction_id'], $order['payment_status'], $order['foreign_id'], $now, $now);


if ($inserted) {
return TRUE;
}
else {
return FALSE;
}
}

/**
* Update order status
*/
function ideal_payment_api_order_update($order_id, $payment_status, $transaction_id = NULL) {
$status = FALSE;
$now = time();

if (!$transaction_id) {
if (db_query("UPDATE {ideal_payment_api_orders} SET payment_status = %d, transaction_id = '%s', updated_at = %d WHERE oid = %d", $payment_status, $transaction_id, $now, $order_id)) {
$status = TRUE;
}
function _ideal_payment_api_include_lib() {
_ideal_payment_api_get_lib();
$path_module = drupal_get_path('module', 'ideal_payment_api');
if ($lib == 'thinmpi'){
require_once($path_module.'/ideal_payment_api_thinmpi.inc.php');
}
else {
if (db_query("UPDATE {ideal_payment_api_orders} SET payment_status = %d, updated_at = %d WHERE oid = %d", $payment_status, $now, $order_id)) {
$status = TRUE;
}
elseif ($lib == 'connector'){
require_once($path_module.'/ideal_payment_api_connector.inc.php');
}
}

/**
* Delete order
*/
function ideal_payment_api_order_delete($order_id) {
if (db_query("DELETE FROM {ideal_payment_api_orders} WHERE oid = %d", $order_id)) {
return TRUE;
}
else {
return FALSE;
}
}

/**
* Load order
*/
function ideal_payment_api_order_load($order_id) {
$result = db_query("SELECT * FROM {ideal_payment_api_orders} WHERE oid = %d", $order_id);
$order = db_fetch_array($result);
if (is_array($order)) {
return $order;
}
else {
return FALSE;
}

# Include the database lib too.
require_once($path_module.'/ideal_payment_api_db.inc');
}

/**
Expand Down
71 changes: 71 additions & 0 deletions ideal_payment_api_db.inc
@@ -0,0 +1,71 @@
<?php
/**
* @file
* Database functions for ideal_payment API.
* CRUD for orders
*/

/**
* Save order
*/
function ideal_payment_api_order_save(&$order) {
$now = time();
$order['order_id'] = db_next_id('ideal_payment_api_orders');
$order['description'] = theme('ideal_payment_api_description', $order);

$inserted = db_query("INSERT INTO {ideal_payment_api_orders} (oid, user_id, description, amount, issuer_id, transaction_id, payment_status, foreign_id, created_at, updated_at) VALUES
(%d, %d,'%s', %d, '%s', '%s', %d, %d, %d, %d)", $order['order_id'], $order['user_id'], $order['description'],$order['amount'], $order['issuer_id'], $order['transaction_id'], $order['payment_status'], $order['foreign_id'], $now, $now);


if ($inserted) {
return TRUE;
}
else {
return FALSE;
}
}

/**
* Update order status
*/
function ideal_payment_api_order_update($order_id, $payment_status, $transaction_id = NULL) {
$status = FALSE;
$now = time();

if (!$transaction_id) {
if (db_query("UPDATE {ideal_payment_api_orders} SET payment_status = %d, transaction_id = '%s', updated_at = %d WHERE oid = %d", $payment_status, $transaction_id, $now, $order_id)) {
$status = TRUE;
}
}
else {
if (db_query("UPDATE {ideal_payment_api_orders} SET payment_status = %d, updated_at = %d WHERE oid = %d", $payment_status, $now, $order_id)) {
$status = TRUE;
}
}
}

/**
* Delete order
*/
function ideal_payment_api_order_delete($order_id) {
if (db_query("DELETE FROM {ideal_payment_api_orders} WHERE oid = %d", $order_id)) {
return TRUE;
}
else {
return FALSE;
}
}

/**
* Load order
*/
function ideal_payment_api_order_load($order_id) {
$result = db_query("SELECT * FROM {ideal_payment_api_orders} WHERE oid = %d", $order_id);
$order = db_fetch_array($result);
if (is_array($order)) {
return $order;
}
else {
return FALSE;
}
}

0 comments on commit 00538e5

Please sign in to comment.