ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 7th, 2004, 11:04 AM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
help with credit card transaction...

hi,

k, I'm having this problem, I've been thinking for hours with no solution... I have a checkout page, and once it's filled out, I use CFTRANSACTION tag to populate proper fields in the database when all required fields are filled, items requested are available (e.g., when there's one left, and it's not sold to someone else while in the cart), and there are no other errors, and when there is, throw appropriate exceptions... that's all worked out, on my part of the server...

the problem is integrating the payment script... i'm using beanstream, and right now I put it so that when the "process order" button is pressed, and CFTRANSACTION is a success, it will POST to the beanstream's processing server.

BUT as it is now, it will mean if the credit card is declined, or if there's any error during this particular process, it will still record sale to the site's database, subtract quantity from itemcount, and excute every query that's inside the CFTRANSACTION tag...

I tried putting the script inside the CFTRANSACTION tags to no avail.... but it's a php script, of course it's not going to work... >.<

so my question, is there a tag or custom tag that groups not just queries but also other conditions provided and only excutes when all conditions are met, and also rolls back when one of them fails? kinda like CFTRANSACTION tag....

or can some of you help me rewrite this php script (all info in it are examples, hehe) that's been provided to me for cc processing into coldfusion... I just dont have any idea how to attack this... >.<

Code:
<?php
// Initialize curl
$ch = curl_init();
// Get curl to POST
curl_setopt( $ch, CURLOPT_POST, 1 );
// Instruct curl to suppress the output from Online Mart, and to directly
// return the transfer instead. (Output will be stored in $txResult.)
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
// This is the location of the Online Mart payment gateway
curl_setopt( $ch, CURLOPT_URL,
"https://www.beanstream.com/scripts/process_transaction.asp" );
// These are the transaction parameters that we will POST
curl_setopt( $ch, CURLOPT_POSTFIELDS,
"requestType=BACKEND&errorPage=https%3A%2F%2Fwww%2Ebeanstream%2Ecom%2Fsamples%2
Forder_form.asp&merchant_id=109040000&trnCardOwner=Paul+Randal&trnCardNumber=51
00000010001004&trnExpMonth=01&trnExpYear=05&trnOrderNumber=2232&trnAmount=10.00
&ordEmailAddress=prandal@mydomain.net&ordName=Paul+Randal&ordPhoneNumber=999999
9&ordAddress1=1045+Main+Street&ordAddress2=&ordCity=Vancouver&ordProvince=BC&or
dPostalCode=V8R+1J6&ordCountry=CA" );
// Now POST the transaction. $txResult will contain Online Mart's response
$txResult = curl_exec( $ch );
echo "Result:<BR>";
echo $txResult;
curl_close( $ch );
?>


any help is appreciated.
thanks in advance!

Reply With Quote
  #2  
Old September 7th, 2004, 12:06 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Is there any reason why you would not validate the credit card FIRST, and then only do the database actions if the credit card authorization was successful?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old September 7th, 2004, 12:21 PM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Quote:
Originally Posted by kiteless
Is there any reason why you would not validate the credit card FIRST, and then only do the database actions if the credit card authorization was successful?


I thought about that too... but if I process creditcard first, then there may be a case where I charge the credit card holder, and the sale doesnt get recorded when there are errors (like items being sold out during transaction, or any error that might cause cftransaction tag to roll back....

I'm basically looking for a way to write a statement in which both are done as one unit... any idea kiteless?

thnx!

Reply With Quote
  #4  
Old September 7th, 2004, 12:32 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
OK, then I would do it like this:

<cftransaction action="begin>
<cftry>
...do database updates...
...do credit card update...
...if credit card update fails, throw an exception...
<cftransaction action="commit" />
<cfcatch type="any">
<cftransaction action="rollback" />
</cfcatch>
</cftry>

</cftransaction>

That's pseudocode obviously, but with a bit of testing that should work.

Reply With Quote
  #5  
Old September 7th, 2004, 12:50 PM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
hm, so I cftry can be nested within cftransaction? >.< why didnt I think of that *hits head*...

kiteless, I'll try that and get back to you on how it works out... anyhow you wouldnt know how to write that php script in CFML, do you?
that php script POSTS the cc info, then receives response (accepted/declined, etc), which I dont know how to 'catch' ....

any ideas?

anyhow, thnx for the help!

Reply With Quote
  #6  
Old September 7th, 2004, 01:06 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
I'm assuming that if they are posting data then you would want to use CFHTTP. You can post various form fields using CFHTTPPARAM. And you should be able to inspect the response to determine if the card was accepted or declined. If it was declined, just throw an exception with CFTHROW.

I'd imagine it will take some playing to get it to work though. Expect some trial and error.

Reply With Quote
  #7  
Old September 7th, 2004, 01:20 PM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
cool... I actually came across those two tags but livedoc doesnt exactly elaborate in a manner that's easy to comprehend and tell you it's the one you should use for communicating to another server...doing POST and querying datas received... sweeeeeet!

thanks for the help, again, kiteless...

will let you know how this comes out...

while i'm on the subject, do you think it's a proper practice to save form data as session variables then POST them?
I'm in deep waters here, I just want to make sure >.<

Reply With Quote
  #8  
Old September 7th, 2004, 01:46 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
You certainly can, the question would be, why? Is there a reason you need them in the session scope?

Reply With Quote
  #9  
Old September 7th, 2004, 01:52 PM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
my checkout process spans 5 pages...
I figured it would be handy to save them in a separate struct in a session, then use them to insert to database, POST, send confirmation mail, and all of that stuff...

and once those are done, simply erase those session variables...
it should be okay, right?

I'm so clueless!

Reply With Quote
  #10  
Old September 7th, 2004, 02:25 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Sure. Just remember to use cflock if you are on CF5 or if you want to avoid any race conditions in CF5 or CFMX.

Reply With Quote
  #11  
Old September 7th, 2004, 03:20 PM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
thanks for the headsup... but is cflock necessary when each user has their own session variables for all forms?

what's a reasonable cflock timeout length if it is necessary?

Reply With Quote
  #12  
Old September 7th, 2004, 03:44 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Well first, if you have no idea about why and where to lock (which seems to be the case), you might do some reading on this as it is important.

On CF5, yes, you need to lock the session scope no matter what because not doing so can cause memory corruption.

On CFMX memory corruption is not an issue, but you can still have race conditions where two threads attempt to modify the same shared scope data (like the session scope) at the same time.

Generally you only need a 5 or 10 second timeout.

Reply With Quote
  #13  
Old September 8th, 2004, 07:27 AM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
cool...

hey kiteless, once I post using cfhttp, what are they ways to manipulate the response I get back?
you know whatever I get back inside #cfhttp.filecontent#...

Reply With Quote
  #14  
Old September 8th, 2004, 08:39 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Well, it's basically a variable with text in it, so you can do anything you want to it: loop, parse, regex, etc. Don't forget you have a response header as well as a bunch of other information.

http://livedocs.macromedia.com/cold...8.htm#wp1632966

Reply With Quote
  #15  
Old September 8th, 2004, 10:41 AM
EBP2K2 EBP2K2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 48 EBP2K2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
thnx...

another Q, my cftransaction doesnt seem to work properly ---> this is what I get... error in line 322...

Quote:
An exception occurred during the execution of the transaction.
The root cause of this exception was: java.lang.NullPointerException.

320 : <cftransaction action="commit"/>
321 : <cfelse>
322 : <cftransaction action="rollback"/>
323 : </cfif>
324 : </cftransaction>


so it wont rollback... it commits, if everything is in order, but rollback is giving me a headache...

along with other queries, I also have a cfloop statement inside the transaction that contains cfquery... and can that cause a problem?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > help with credit card transaction...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Linear Mode Linear Mode
<