Jump to content

auto payment script


tomdchi

Recommended Posts

I am trying to get this scipt to work with the api but something is wrong. It is supposed to loop through and find all unpaid invoices and insert the info into another table. The main problem I am having is that it is inserting the info twice. If I do not include the gateway and invoice functions it only inserts once but then does not record the payment through the api it just inserts into the new table. Any idea how I can fix this?

 

<?php

include ("../dbconnect.php");

include ("../includes/functions.php");

include ("../includes/gatewayfunctions.php");

include ("../includes/invoicefunctions.php");

 

$query = "SELECT inv.userid,

inv.total,

inv.id,

inv.status,

c.firstname,

c.lastname,

c.companyname

FROM tblinvoices inv

INNER JOIN tblclients c

ON c.id=inv.userid

AND inv.status='Unpaid'";

 

$result = mysql_query($query);

 

if (mysql_num_rows($result) == 0)

break;

 

while ($data = mysql_fetch_array($result)) {

$name = $data["firstname"] . " " . $data["lastname"];

$total = $data["total"];

$invoiceid = $data["id"];

$userid = $data["userid"];

$status = $data["status"];

$companyname = $data["companyname"];

 

$query = "SELECT fieldid, value

FROM tblcustomfieldsvalues

WHERE relid='$userid'

AND fieldid IN(3,4)";

 

$result = mysql_query($query);

 

while ($fields = mysql_fetch_array($result))

$rtemp[$data['fieldid']] = $fields['value'];

 

$recbankacctnumber = $data['recbankacctnumber'] = $rtemp[3];

$recbankroutingnumber = $data['recbankroutingnumber'] = $rtemp[4];

 

$sql = "INSERT INTO tblclientpmt(transid,userid,name,routing,checking,";

$sql .= " amount,invoiceid,processed,date,companyname) ";

$sql .= "VALUES('','$userid','$name','$recbankroutingnumber','$recbankacctnumber',";

$sql .= " '$total','$invoiceid',1,now(),'$companyname')";

 

if (!mysql_query($sql))

echo mysql_error();

 

$result = select_query("tblclientpmt", "", array("invoiceid" => $invoiceid));

$payments = mysql_fetch_array($result);

$transid = $payments["transid"];

 

if (!mysql_query($sql))

echo mysql_error();

 

addInvoicePayment($invoiceid, $transid, $amount, "", "rapidach");

}

 

$done = true;

?>

Edited by tomdchi
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated