|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! ![]() |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Quote:
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! |
|
#4
|
|||
|
|||
|
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. |
|
#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! |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
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 >.< ![]() |
|
#8
|
|||
|
|||
|
You certainly can, the question would be, why? Is there a reason you need them in the session scope?
|
|
#9
|
|||
|
|||
|
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! |
|
#10
|
|||
|
|||
|
Sure. Just remember to use cflock if you are on CF5 or if you want to avoid any race conditions in CF5 or CFMX.
|
|
#11
|
|||
|
|||
|
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? |
|
#12
|
|||
|
|||
|
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. |
|
#13
|
|||
|
|||
|
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#... |
|
#14
|
|||
|
|||
|
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 |
|
#15
|
|||
|
|||
|
thnx...
another Q, my cftransaction doesnt seem to work properly ---> this is what I get... error in line 322... Quote:
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? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > help with credit card transaction... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
Linear Mode |