Skip to main content
October 15, 2008
Question

LOOP Credit Card Transactions

  • October 15, 2008
  • 8 replies
  • 1877 views
I am needing to know how to CFLOOP multiple transactions with Authorize.net.

When sending a order request to authorize.net, it returns a response - that response is recorded with the order.

I can loop multiple transactions - what I cant figure out, is how to loop multiple transactions and still capture the response and record it to the db then go to the next transaction. When I just do a CFLOOP around the transaction code - it processes each order one after the other, but will not record the response.

Here is the order of events:

1. Db with customer info and order
2. Send customer/order to authorize.net
3. Receive response from authorize.net
4. Record response to customer/order data in Db
5. Next record repeat 2-4

This would be great for re-occurring billing as well!

I hope someone has some insight on this.
This topic has been closed for replies.

8 replies

Legend
October 20, 2008
Based on your last findings, to me the problem appears to be a scoping issue. This is a problem with embedded loops in ColdFusion and if CFHTTP internally uses a loop, the problem may be propagating in this example. There are several ways to solve the issue, the simpliest being to specify the scope: orders.xxx or cfhttp.xxx. Another way to fix it would be to remove the CFHTTP call from your loop and put it in a CFC or external CF tag.

Hope this helps.

Inspiring
October 17, 2008
Hi,

You already explained that without the loop it works, but with the loop it doesn't. To resolve the issue we cannot always come back to this point.

There are two tasks within your loop:
- the http request
- the DB update.
To find out which one of these is the problem, run the code with the dump of the cfhttp.fileContent variable and the cfabort.
If the displayed results are fine then we know the http request is not the problem, and we need to look into the DB part.

If the http request is the problem then you may want to have a look at the timeout attribute.
Since you are using CF8, you can also look into opening a new tread for each autorize.net transaction.

If the application allows it then you may also be able to work asyncronous, that means you have one script that dumps all autorize transactions into the DB, but you have a separate script that is scheduled, and processes these transactions one by one.

"CFABORT is CF 101" is certainly correct, but for "Finding Problems 101" we need some basic information from you.

cheers,
fober
Inspiring
October 17, 2008
cwmcguire wrote:
> The timout is not the problem with the CFHTTP -
> everyone is overlooking the problem.

Did you try it?

> It does not update any record, ...
> Because authorize.net is posting a server response back to that same page, that
> page is not capturing the response before it goes to the next record.

There are other reasons an update might not occur. Some of which have nothing to do with cfhttp. For example if the #id# is invalid, the query might execute but nothing would be updated because no matching records were found.

You have dismissed some of the suggestions, without saying what other tests you have performed and what results led you to this conclusion. Beyond the fact that you say no updates are occurring, how else have you confirmed that the response is not being captured correctly?
October 17, 2008
>>You have dismissed some of the suggestions, without saying what other tests you have performed and what results led you to this conclusion. Beyond the fact that you say no updates are occurring, how else have you confirmed that the response is not being captured correctly?
<<

Because the code works when you take the CFLOOP out of the equation. You put the CFLOOP in place, and no longer does the page take back the server response, it keeps looping thru all the records til its done.
Inspiring
October 17, 2008
> Because the code works when you take the CFLOOP out of the equation. You put
> the CFLOOP in place, and no longer does the page take back the server response,
> it keeps looping thru all the records til its done.

If you take the loop out of the equation, you are likely using different values for both the cfhttp call and the query. So that still does not rule out something as simple as a different or wrong #id#.

1. When you say the transactions are "processed", what does that mean? Are you dumping the cfhttp results within the loop to confirm this, or are you assuming it was successful because no error is thrown?

2. How have you debugged the query - by dumping or logging the "results" within the loop? Does the result structure even exist after the cfquery? If it does check the recordCount, sql, etcetera.

While I cannot prove the response is _not_ the problem, I do not think removing the loop alone is enough to conclusively prove that it _is_ the problem. There are other variables. You can certainly add a simple thread.sleep() call to the page, and see what happens. However, if the response handling is not the problem thread.sleep() will not fix anything.
Inspiring
October 16, 2008
cwmcguire wrote:
> When I just do a CFLOOP around the transaction code - it processes
> each order one after the other, but will not record the response.

Perhaps I am misunderstanding, but it sounds a bit odd that the cfhttp calls themselves are succeeding but nothing happens with the database .. at all. Not even an error?

A) Did you try supplying a timeout. According to the documentation, CF can be made to wait indefinitely with the correct settings

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_09.html

B) Did you log the cfhttp results within the loop to see what is actually happening.

October 16, 2008
The timout is not the problem with the CFHTTP - everyone is overlooking the problem.

The problem is, the server is sending a response back to the same page that is suppose to be looping thru multiple records making multiple transactions.

How could I run a transaction, receive a response, post the response to the table, then go to the next record needed to be processed, and run that transactions, receive a response...etc..etc...

This is the problem....
Inspiring
October 16, 2008
Hi,

to see the server response just output the "cfhttp.fileContent" variable, and cfabort at the end of the loop to keep the display on the screen.

cheers,
fober


<CFQUERY NAME=order>
</CFQUERY>
<CFOUTPUT>
<CFLOOP QUERY=order>
<cfhttp method="POST" url="authorize.net">
<cfhttpparam type="formfield" name="x_last_name" value="#lastname#">
<cfhttpparam type="formfield" name="x_card_num" value="#cardnumber#">
<cfhttpparam type="formfield" name="x_amount" value="#amount#">
<cfhttpparam type="formfield" name="x_card_code" value="#cvv#">
<cfhttpparam type="formfield" name="x_exp_date" value="#exp#">
<cfhttpparam type="formfield" name="x_method" value="CC">
<cfhttpparam type="formfield" value="AUTH_CAPTURE" name="x_type">
</cfhttp>

<hr>
[#cfhttp.fileContent#]

<CFSET code = ListGetAt(api_response,1)>
<CFIF code EQ 1>
<CFSET trans = "approved">
<CFSET transid = ListGetAt(api_response,7)>
<CFSET errortext = ListGetAt(api_response,4)>
</CFIF>
<CFIF code EQ 2>
<CFSET trans = "declined">
<CFSET transid = 0>
<CFSET errortext = ListGetAt(api_response,4)>
</CFIF>
<CFIF code EQ 3>
<CFSET trans = "error">
<CFSET transid = 0>
<CFSET errortext = ListGetAt(api_response,4)>
</CFIF>

<CFQUERY NAME=recordresponse>
UPDATE table
SET transid=#transid#,trans='#trans#',errortext='#errortext#',processdate='#processdate#'
WHERE id=#id#
</CFQUERY>

</CFLOOP>
<cfabort>
</CFOUTPUT>
October 16, 2008
That is not what I am trying to accomplish...CFABORT is CF 101...

I am wanting to record responses to the table for each transaction ran - it is not doing that. It is running each transaction without pausing to record the response with the CFLOOP. I i do each transaction individually, it works fine.

Any solution to this issue?
Inspiring
October 16, 2008
Where does the variable api_response come from?
<CFSET code = ListGetAt(api_response,1)>

Should you not use cfhttp.fileContent instead?
<CFSET code = ListGetAt(cfhttp.fileContent,1)>

cheers,
fober
Participant
October 16, 2008
When you run this, does it update any records at all?
October 16, 2008
It does not update any record, it continues on to the next record and proceeds to charge account thru authorize.net until it has gone thru all records.

Because authorize.net is posting a server response back to that same page, that page is not capturing the response before it goes to the next record.

Is there some way to pause the loop to catch the response from authorize.net, record the response, then move to the next record?

The api_response is coming from this line of code:

<cfset api_response=cfhttp.fileContent>

That was omitted by accident when I posted this thread. Sorry.
October 16, 2008
Anyone have any suggestions...