Skip to content

Commit 514706d

Browse files
committed
First commit of PayFlowPro components for ColdFusion.
0 parents  commit 514706d

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

HTTPPayFlowProGateway.cfc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<cfcomponent>
2+
3+
<cffunction name="init" output="no">
4+
<cfargument name="mode">
5+
<cfswitch expression="#arguments.mode#">
6+
<cfcase value="LIVE">
7+
<cfset variables.gatewayURL = "https://payflowpro.verisign.com:443">
8+
</cfcase>
9+
<cfcase value="TEST">
10+
<cfset variables.gatewayURL = "https://pilot-payflowpro.verisign.com:443">
11+
</cfcase>
12+
<cfdefaultcase>
13+
<cfthrow message = "You must specify either LIVE or TEST in the init() method.">
14+
</cfdefaultcase>
15+
</cfswitch>
16+
<cfreturn this>
17+
</cffunction>
18+
19+
<cffunction name = "createTransaction">
20+
<cfreturn createObject("component", "PayFlowProTransaction").init(this)>
21+
</cffunction>
22+
23+
24+
<cffunction name = "chargeCard">
25+
<cfargument name="params">
26+
<cfargument name="transactionID">
27+
28+
<CFHTTP url="#variables.gatewayURL#" method="post" resolveurl="no" timeout="30">
29+
<CFHTTPPARAM type="header" name="X-VPS-REQUEST-ID" value="#arguments.transactionID#">
30+
<CFHTTPPARAM type="header" name="X-VPS-CLIENT-TIMEOUT" value="30">
31+
<CFHTTPPARAM type="body" value="#encodeURLData(arguments.params)#">
32+
</CFHTTP>
33+
34+
<cfreturn parseURLData(CFHTTP.FileContent)>
35+
</cffunction>
36+
37+
<cffunction name = "encodeURLData" output="no">
38+
<cfargument name="params">
39+
<cfset var key = 0>
40+
<cfset var pairs = arrayNew(1)>
41+
<cfloop collection = "#arguments.params#" item = "key">
42+
<cfset arrayAppend(pairs, "#key#=#params[key]#")>
43+
</cfloop>
44+
<cfreturn arrayToList(pairs, "&")>
45+
</cffunction>
46+
47+
<cffunction name = "parseURLData" output="no">
48+
<cfargument name="params">
49+
<cfset var data = StructNew()>
50+
<cfset var key = 0>
51+
<cfloop list="#params#" index="key" delimiters="&">
52+
<cfset data[listFirst(key,'=')] = urlDecode(listRest(key,"="))>
53+
</cfloop>
54+
<cfreturn data>
55+
</cffunction>
56+
57+
</cfcomponent>

PayFlowProTransaction.cfc

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<cfcomponent>
2+
3+
<cffunction name="init" output="no">
4+
<cfargument name="gateway">
5+
<cfset variables.transactionID = CreateUUID()>
6+
<cfset variables.gateway = arguments.gateway>
7+
<cfreturn this>
8+
</cffunction>
9+
10+
<cffunction name = "setAmount" output="no">
11+
<cfargument name="amount">
12+
<cfset variables.amount = arguments.amount>
13+
</cffunction>
14+
15+
<cffunction name = "setVendor" output="no">
16+
<cfargument name="vendor">
17+
<cfset variables.vendor = arguments.vendor>
18+
</cffunction>
19+
20+
<cffunction name = "setUsernameAndPassword" output="no">
21+
<cfargument name="username">
22+
<cfargument name="password">
23+
<cfset variables.username = arguments.username>
24+
<cfset variables.password = arguments.password>
25+
</cffunction>
26+
27+
<cffunction name = "setCardNumber" output="no">
28+
<cfargument name="cardNumber">
29+
<cfset variables.cardNumber = arguments.cardNumber>
30+
</cffunction>
31+
32+
<cffunction name = "setExpirationMonthAndYear" output="no">
33+
<cfargument name="month">
34+
<cfargument name="year">
35+
<cfset variables.expiresMonth = arguments.month>
36+
<cfset variables.expiresYear = arguments.year>
37+
</cffunction>
38+
39+
<cffunction name = "authCode" output="no">
40+
<cfif isDefined("variables.response.authCode")>
41+
<cfreturn variables.response.authCode>
42+
<cfelse>
43+
<cfreturn "">
44+
</cfif>
45+
</cffunction>
46+
47+
<cffunction name = "pnRef" output="no">
48+
<cfif isDefined("variables.response.pnRef")>
49+
<cfreturn variables.response.pnRef>
50+
<cfelse>
51+
<cfreturn "">
52+
</cfif>
53+
</cffunction>
54+
55+
<cffunction name="run" output="no">
56+
<cfset var params = structNew()>
57+
<cfset params.user = variables.username>
58+
<cfset params.pwd = variables.password>
59+
<cfset params.partner = "Verisign">
60+
<cfset params.vendor = variables.vendor>
61+
<cfset params.trxtype = "S">
62+
<cfset params.tender = "C">
63+
<cfset params.amt = variables.amount>
64+
<cfset params.expdate = formatExpirationDate()>
65+
<cfset params.acct = "#variables.cardNumber#">
66+
<cfset params.comment1 = "SBC#dateFormat(now(), 'mmddyy')#">
67+
68+
<cfset variables.response = variables.gateway.chargeCard(params, variables.transactionID)>
69+
70+
</cffunction>
71+
72+
73+
74+
<cffunction name = "formatExpirationDate" output="no">
75+
<cfreturn numberFormat(variables.expiresMonth, "00") & numberFormat(right(variables.expiresYear, 2), "00")>
76+
</cffunction>
77+
78+
79+
80+
<cffunction name = "resultCode" output="no">
81+
<cfif isDefined("variables.response.result")>
82+
<cfreturn variables.response.result>
83+
<cfelse>
84+
<cfreturn -1/>
85+
</cfif>
86+
</cffunction>
87+
88+
<cffunction name = "responseMessage" output="no">
89+
<cfif isDefined("variables.response.respmsg")>
90+
<cfreturn variables.response.respmsg>
91+
<cfelse>
92+
<cfreturn ""/>
93+
</cfif>
94+
</cffunction>
95+
96+
<cffunction name = "approved" output="no">
97+
<cfreturn 0 eq resultCode()>
98+
</cffunction>
99+
100+
</cfcomponent>
101+

readme.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
PayFlowPro Components for Cold Fusion
2+
3+
Simple interface to process credit card transactions via Verisign PayFlowPro. It wraps around the HTTP interface using CFHTTP.
4+
5+
<!--- Change "TEST" to "LIVE" in live code --->
6+
<cfset gateway = createObject("component", "HTTPPayFlowProGateway").init("TEST")>
7+
8+
<cfset transaction = variables.paymentGateway.createTransaction()>
9+
<cfset transaction.setVendor(vendor)>
10+
<cfset transaction.setUsernameAndPassword(username,password )>
11+
<cfset transaction.setCardNumber(card_number)>
12+
<cfset transaction.setExpirationMonthAndYear(expiration_month, expiration_year)>
13+
<cfset transaction.setAmount(amount_to_charge)>
14+
<cfset transaction.run()>
15+
16+
<cfoutput>
17+
Approved? #transaction.approved()#<br>
18+
Result Code: #transaction.resultCode()#<br>
19+
Response Message: #transaction.responseMessage()#
20+
</cfoutput>

0 commit comments

Comments
 (0)