...

View Full Version : Ok, pulling my hair out on ccbill postback



sfraise
03-20-2009, 05:13 AM
I'm trying to integrate ccbill with osdate, everything works, form gets prefilled with correct variables, and payments can be successfully made. I just can't get the membership level to get upgraded using the post back system. But here's the weird thing, it worked once, but then never again. I didn't change a thing in the post back form so I'm going crazy trying to figure this thing out.

Here is the ccbill_notify.php code that the variables from ccbill get posted back to:


<?php
if ( !defined( 'SMARTY_DIR' ) ) {
include_once( 'init.php' );
}
//already processed subscription_id, exit
$trnrec=$osDB->getRow('select * from ! where txn_id = ? ', array(TRANSACTIONS_TABLE, $_POST['subscription_id'] ));
if( $trnrec['id'] )
exit;

// amount paid is less than amount expected
$trnrec=$osDB->getRow('select * from ! where invoice_no = ? ', array(TRANSACTIONS_TABLE, $_POST['invoiceid'] ));
if( $_POST['initialPrice'] < $trnrec['amount_paid'] )
{
$params['payment_status'] = 'Error';
}
else {

// deals with both Approval and Denial URLs
if ( isset($_POST['subscription_id']) && strlen($_POST['subscription_id']) > 3 ) {
$params['payment_status'] = 'Completed';
} elseif ( isset($_POST['reasonForDecline']) ) {
$params['payment_status'] = 'Declined';
} else {$params['payment_status'] = 'Error'; }
}

$params['txn_id'] = $_POST['subscription_id'];
$params['valid'] = true;
$params['pay_txn_id'] = $pay_txn_id = $_POST['invoiceid'];
$params['paid_thru'] = 'ccbill';
$params['amount'] = $_POST['initialPrice'];
$params['email'] = $_POST['email'];
$params['vars'] = serialize($_POST);

$level_name = process_payment_info($params);

$levels =$osDB->getRow('select mem.name, trn.payment_status from ! as trn, ! as mem where trn.invoice_no = ? and mem.roleid = trn.to_membership', array(TRANSACTIONS_TABLE, MEMBERSHIP_TABLE, $pay_txn_id) );

$t->assign ( 'level', $levels['name'] .' - Status: '.$levels['payment_status']);

$_SESSION['security'] = '';

hasRight('');

$t->assign('rendered_page', $t->fetch('checkout_process.tpl') );

$t->display( 'index.tpl' );

exit;


Is there anything in here that anyone can see that would prevent the process from working at all? It's writing new lines to the transaction database but it never completes outside of the one single time that it actually worked. Please help.

sfraise
03-22-2009, 07:09 AM
Maybe the problem lies in the functions process_payment_info?
Here's the code for that:


function process_payment_info($params) {

global $osDB;

// get the user information for this transaction

$trnrec=$osDB->getRow('select * from ! where id = ? ', array(TRANSACTIONS_TABLE, $params['pay_txn_id'] ));

$user_id = $trnrec['user_id'];

$user_level = $trnrec['to_membership'];

$levelvars = $osDB->getRow( 'select activedays, name from ! where roleid = ?', array( MEMBERSHIP_TABLE, $user_level ) );

$activedays = $levelvars['activedays'];
$level_name = $levelvars['name'];

if ( $params['valid'] && $trnrec['payment_status'] != 'Completed') {

$osDB->query( 'update ! set payment_email = ?, amount_paid = ?, txn_id = ?, txn_date = ?, payment_vars = ?, payment_status=? where id = ?', array( TRANSACTIONS_TABLE, $params['email'], $params['amount'], $params['txn_id'], date('Y-m-d'), $params['vars'], $params['payment_status'], $params['pay_txn_id'] ) );

// determine when this user's membership was to expire, then extend it by $activedays days

if (trim($params['payment_status']) == 'Completed') {
$curlevel = $osDB->getRow( 'select levelend, level from ! where id = ?', array( USER_TABLE, $user_id ) );

$levelend = $curlevel['levelend'];

if ( $levelend < time() ) {
$levelend = time();
}

// new expiration date for this member

if ($curlevel['level'] != $user_level) {

$levelend = strtotime( "+$activedays day", time() );

} else {

$levelend = strtotime( "+$activedays day", $levelend );

}

$osDB->query( 'UPDATE ! SET level = ?, levelend = ? WHERE id = ?', array( USER_TABLE, $user_level, $levelend, $user_id ) );
}
}

return $level_name;
}


Please if anyone sees why the ccbill_notify.php that gets posted back to after payment is made wouldn't work with the following function please let me know. I'm going crazy on this one.

steelaz
03-22-2009, 08:26 AM
After this line:


$trnrec=$osDB->getRow('select * from ! where id = ? ', array(TRANSACTIONS_TABLE, $params['pay_txn_id'] ));

Try inserting:


echo "<pre>"; var_dump($trnrec); echo "</pre>";

Then run test transaction and paste your results here.

sfraise
03-22-2009, 10:15 AM
I get
array(0) {
}

The problem in doing a var dump or print_r is that even though ccbill posts back to my ccbill_notify.php page, ccbill doesn't redirect you to the approved page on my site. Instead it takes you to their own approved page where there is a link that the customer is supposed to click on to return back to my site after complete.

steelaz
03-22-2009, 01:38 PM
Double check your ccbill configuration:

http://ccbillhelp.ccbill.com/content/approve_denial_prm.htm
http://ccbillhelp.ccbill.com/content/mod_sub_adv_tls.htm

sfraise
03-22-2009, 08:24 PM
Yeah everything is set right in ccbill webamaster admin section.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum