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 June 24th, 2009, 05:14 PM
madcaesar madcaesar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 9 madcaesar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 50 sec
Reputation Power: 0
Coupon Discount

Hi all,

Ok I have a form that charges credit cards. However, I would like to add an option to allow people to enter a "code" I send them to get -$20 off their purchase.

Has anyone done something like that, that I could use for guidance? I'm thinking about setting up a table with various codes, and the have CF check if the code is valid to give them the discount, if it is, it invalidates that code after use, so it cannot be used twice.

Anyway, I would like to know if I'm on the right track as to how I want to do this, or if there is a better more efficient way.

Any bits of sample code would be greatly appreciated.

Thanks for our help.

Reply With Quote
  #2  
Old June 24th, 2009, 05:49 PM
Master__Chief Master__Chief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 244 Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 16 m 45 sec
Reputation Power: 33
You are asking for code of which nobody will provide. You should start implementing your logic and ask for help when you get stuck:

http://www.easycfm.com/coldfusion/f...=12&Topic=14383


__________________
www.fuzzysiberians.com

Reply With Quote
  #3  
Old June 24th, 2009, 10:46 PM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,260 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 5 h 39 m 34 sec
Reputation Power: 896
Well you have to store the coupon codes somewhere, so that you can validate them. Which basically means using a database, or using an algorithm of your own choosing that must be met for the coupon to be valid. The database is more reliable. Just generate a set of codes and match the coupon against the database, marking it as used once a customer has used it.

I'm not really sure what kind of "sample code" you want, since what you're doing is specific to your use case. I would think it would be quite straightforward to implement.

Quote:
Originally Posted by madcaesar
Hi all,

Ok I have a form that charges credit cards. However, I would like to add an option to allow people to enter a "code" I send them to get -$20 off their purchase.

Has anyone done something like that, that I could use for guidance? I'm thinking about setting up a table with various codes, and the have CF check if the code is valid to give them the discount, if it is, it invalidates that code after use, so it cannot be used twice.

Anyway, I would like to know if I'm on the right track as to how I want to do this, or if there is a better more efficient way.

Any bits of sample code would be greatly appreciated.

Thanks for our help.

Reply With Quote
  #4  
Old July 2nd, 2009, 11:50 AM
madcaesar madcaesar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 9 madcaesar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 50 sec
Reputation Power: 0
Ok here is what I got. Thoughts?

Code:
<!--- Start Coupon Checker ---> 
<cfif FORM.coupon neq "">     	
<cfquery name="qCoupon" datasource="#APPLICATION.dataSource#" maxrows="1">        
SELECT *          
FROM Coupon         
WHERE Coupon = <cfqueryparam value="#FORM.Coupon#" cfsqltype="cf_sql_char">         
ORDER BY Date DESC         
</cfquery>          		

<cfif qCoupon.recordcount eq 0> 			<cfoutput>
<META HTTP-EQUIV="refresh" content="0;URL=SeminarsList.cfm?error=1&WrongCode=#FORM.Coupon#"></cfoutput>
<cfabort>         
<cfelseif qCoupon.recordcount neq 0> 			
<cfoutput query="qCoupon">             
<cfif Status eq "U">             
<META HTTP-EQUIV="refresh" content="0;URL=SeminarsList.cfm?error=2&WrongCode=#FORM.Coupon#">             
<cfabort>             
<cfelseif Status eq "A"> 				
<cfset FORM.CouponID = #CouponID#>                 
<cfset FORM.CouponUser = #FORM.name#>             	
<cfset FORM.DateUsed = #DateFormat(Now(),'mm/dd/yy')#> 				
<cfset FORM.Status = "U">                 
<cflock type="exclusive" timeout="60">                 
<cfupdate datasource="#APPLICATION.dataSource#" tablename="Coupon" formfields="CouponID,DateUsed,CouponUser,Status">
</cflock>                 
<cfset GiveDiscount = "yes">             
</cfif>             
</cfoutput>        
</cfif>     
</cfif> 
<!--- End Coupon Checker --->

Reply With Quote
  #5  
Old July 2nd, 2009, 12:56 PM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,260 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 5 h 39 m 34 sec
Reputation Power: 896
That will probably work all right, though I wouldn't put the values in the FORM scope since then someone could try posting bad form values and potentially spoof you. It should work just setting them into the VARIABLES scope.

Reply With Quote
  #6  
Old July 2nd, 2009, 02:26 PM
madcaesar madcaesar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 9 madcaesar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 50 sec
Reputation Power: 0
what do you mean? They are submitting a form, so I'm taking those values to enter. What else can I take?

Reply With Quote
  #7  
Old July 6th, 2009, 10:55 AM
madcaesar madcaesar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 9 madcaesar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 50 sec
Reputation Power: 0
Help?

Reply With Quote
  #8  
Old July 6th, 2009, 01:23 PM
Master__Chief Master__Chief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 244 Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level)Master__Chief User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 16 m 45 sec
Reputation Power: 33
something like

Code:
<cfset variables.formData = structCopy(form)>


and then refer form vars like:

Code:
<cfqueryparam value="#variables.formData.Coupon#" cfsqltype="cf_sql_char"> 

Reply With Quote
  #9  
Old July 7th, 2009, 12:19 AM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,260 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 5 h 39 m 34 sec
Reputation Power: 896
Exactly.

Reply With Quote
  #10  
Old July 7th, 2009, 08:20 AM
madcaesar madcaesar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 9 madcaesar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 50 sec
Reputation Power: 0
Thank you for our help, however I don't really understand how that helps. I mean how does it help protect my database?

Would you mind giving me a quick explanation, or point me to something to read that explains it.

Thank you in advance.

Reply With Quote
  #11  
Old July 7th, 2009, 10:17 AM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,260 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 5 h 39 m 34 sec
Reputation Power: 896
The form scope is something the user can mess with, because it is submitted by the user. The variables scope is local to the template, so only things you put into it can go into it. So it is generally safer to take the form data, inspect it and scrub it, and then place it into the variables scope.

Reply With Quote
  #12  
Old July 7th, 2009, 11:03 AM
madcaesar madcaesar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 9 madcaesar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 50 sec
Reputation Power: 0
Ok so my code should look like this then?

<!--- Start Coupon Checker --->
<cfset variables.formData = structCopy(form)>
<cfif FORM.coupon neq "">
<cfquery name="qCoupon" datasource="#APPLICATION.dataSource#" maxrows="1">
SELECT *
FROM Coupon
WHERE Coupon = <cfqueryparam value="#variables.formData.Coupon#" cfsqltype="cf_sql_char">
ORDER BY Date DESC
</cfquery>

<cfif qCoupon.recordcount eq 0>
<cfoutput><META HTTP-EQUIV="refresh" content="0;URL=WebinarSeries2009Q3.cfm?error=1&WrongCode=#FORM.Coupon#"></cfoutput>
<cfabort>
<cfelseif qCoupon.recordcount neq 0>
<cfoutput query="qCoupon">
<cfif Status eq "U">
<META HTTP-EQUIV="refresh" content="0;URL=WebinarSeries2009Q3.cfm?error=2&WrongCode=#FORM.Coupon#">
<cfabort>
<cfelseif Status eq "A">
<cfset FORM.CouponID = <cfqueryparam value="#variables.formData.CouponID#" cfsqltype="cf_sql_integer">>
<cfset FORM.CouponUser = <cfqueryparam value="#variables.formData.name#" cfsqltype="cf_sql_char">>
<cfset FORM.DateUsed = <cfqueryparam value="#variables.formData.DateFormat(Now(),'mm/dd/yy')#" cfsqltype="cf_sql_date">>
<cfset FORM.Status = <cfqueryparam value="U" cfsqltype="cf_sql_char">>
<cflock type="exclusive" timeout="60">
<cfupdate datasource="#APPLICATION.dataSource#" tablename="Coupon" formfields="CouponID,DateUsed,CouponUser,Status">
</cflock>
<cfset GiveDiscount = "yes">
</cfif>
</cfoutput>
</cfif>
</cfif>
<!--- End Coupon Checker --->

Reply With Quote
  #13  
Old July 7th, 2009, 02:15 PM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,260 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 5 h 39 m 34 sec
Reputation Power: 896
No. CFQUERYPARAM is used in a CFQUERY tag to create bind variables. If you want to do this, you need to remove the CFUPDATE tag and write your own update statement using SQL and CFQUERY (and CFQUERYPARAM), and then you aren't limited to only using form variables (which CFUPDATE forces you to do).

CFUPDATE is a very old tag that was introduced to help people who couldn't write SQL, but it is not used nowadays for numerous reasons, mainly the lack of control over what happens.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Coupon Discount


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
Stay green...Green IT