<!--- 
 Filename: ProcessPayment.cfm
 Created by: Nate Weiss (NMW)
 Please Note Creates the <CF_ProcessPayment> Custom Tag
 Purpose: Handles credit card and other transactions
--->


<!--- Tag Parameters --->
<cfparam name="ATTRIBUTES.processor" type="string">
<cfparam name="ATTRIBUTES.orderID" type="numeric">
<cfparam name="ATTRIBUTES.orderAmount" type="numeric">
<cfparam name="ATTRIBUTES.creditCard" type="string">
<cfparam name="ATTRIBUTES.creditExpM" type="string">
<cfparam name="ATTRIBUTES.creditExpY" type="string">
<cfparam name="ATTRIBUTES.returnVariable" type="variableName">
<cfparam name="ATTRIBUTES.creditName" type="string">


<!--- Depending on the PROCESSOR attribute --->
<cfswitch expression="#ATTRIBUTES.processor#">

  <!--- If PROCESSOR="PayflowPro" --->
  <cfcase value="PayflowPro">
    <!--- Force expiration into MM and YY format --->
    <cfset expM = numberFormat(ATTRIBUTES.creditExpM, "00")>
    <cfset expY = numberFormat(right(ATTRIBUTES.creditExpY, 2), "00")>

    <!--- Attempt transaction with Payflow Pro --->
    <cf_VerisignPayflowPro
    certPath="c:\verisign\payflowpro\java\certs"
    serverName="test-payflow.verisign.com"
    payflowPartner="VeriSign"
    payflowVendor="YOUR_INFO_HERE"
    payflowPassword="YOUR_INFO_HERE"
    acct="#ATTRIBUTES.creditCard#"
    expDate="#expM##expY#"
    amt="#numberFormat(ATTRIBUTES.orderAmount, '9.00')#"
    comment1="Orange Whip OrderID: #ATTRIBUTES.orderID#"
    comment2="Customer Name on Card: #ATTRIBUTES.creditName#"
    returnVariable="PayflowResult">
 
    <!--- Values to return to calling template ---> 
    <cfset s = structNew()>
    <!--- Always return IsSuccessful (Boolean) --->
    <cfset s.isSuccessful = PayflowResult.RESULT eq 0>
    <!--- Always return status of transaction --->
    <cfset s.status = PayflowResult.RESPMSG>
    <!--- If Successful, return the Auth Code --->
    <cfif s.isSuccessful>
      <cfset s.authCode = PayflowResult.AUTHCODE>
      <cfset s.orderID = ATTRIBUTES.orderID>
      <cfset s.orderAmount = ATTRIBUTES.orderAmount>
      <!--- If not successful, return the error ---> 
    <cfelse>
      <cfset s.errorCode = PayflowResult.RESULT>
      <cfset s.errorMessage = PayflowResult.RESPMSG>
    </cfif>
    <!--- Return values to calling template --->
    <cfset "Caller.#ATTRIBUTES.returnVariable#" = s> 
 
  </cfcase> 
 
 
  <!--- If PROCESSOR="JustTesting" --->
  <!--- This puts the tag into a "testing" mode --->
  <!--- Where any transaction will always succeed --->
  <cfcase value="JustTesting">
    <!--- Values to return to calling template ---> 
    <cfset s = structNew()>
    <!--- Always return IsSuccessful (Boolean) --->
    <cfset s.isSuccessful = True>
    <!--- Always return status of transaction --->
    <cfset s.status = "success">
    <!--- Return other data, as if transaction succeeded --->
    <cfset s.authCode = "DummyAuthCode">
    <cfset s.orderID = ATTRIBUTES.orderID>
    <cfset s.orderAmount = ATTRIBUTES.orderAmount>

    <!--- Return values to calling template --->
    <cfset "Caller.#ATTRIBUTES.returnVariable#" = s>
  </cfcase>
 

  <!--- If PROCESSOR="CyberCash" --->
  <!--- *** This is now defunct but remains as an example --->
  <cfcase value="CyberCash">
    <!--- Force expiration into MM and YY format --->
    <cfset expM = numberFormat(ATTRIBUTES.creditExpM, "00")>
    <cfset expY = numberFormat(right(ATTRIBUTES.creditExpY, 2), "00")>
 
    <!--- Attempt to process the transaction --->
    <CFX_CYBERCASH
    VERSION="3.2"
    CONFIGFILE="C:\mck-3.3.1-NT\test-mck\conf\merchant_conf"
    MO_ORDER_ID="8767767#ATTRIBUTES.orderID#"
    MO_VERSION="3.3.1"
    MO_PRICE="USD #numberFormat(ATTRIBUTES.orderAmount, '9.00')#"
    CPI_CARD_NUMBER="#ATTRIBUTES.creditCard#"
    CPI_CARD_EXP="#expM#/#expY#"
    CPI_CARD_NAME="#ATTRIBUTES.creditName#"
    OUTPUTPOPQUERY="Charge">
 
    <!--- Values to return to calling template ---> 
    <cfset s = structNew()>
    <!--- Always return IsSuccessful (Boolean) --->
    <cfset s.isSuccessful = charge.STATUS eq "success">
    <!--- Always return status of transaction --->
    <cfset s.status = Charge.STATUS>
    <!--- If Successful, return the Auth Code --->
    <cfif s.isSuccessful>
      <cfset s.authCode = Charge.AUTH_CODE>
      <cfset s.orderID = ATTRIBUTES.orderID>
      <cfset s.orderAmount = ATTRIBUTES.orderAmount>
    <!--- If not successful, return the error ---> 
    <cfelse>
      <cfset s.errorCode = Charge.ERROR_CODE>
      <cfset s.errorMessage = Charge.ERROR_MESSAGE>
    </cfif>
    <!--- Return values to calling template --->
    <cfset "Caller.#ATTRIBUTES.returnVariable#" = s>
  </cfcase>
 
  <!--- If the PROCESSOR attribute is unknown --->
  <cfdefaultcase>
    <cfthrow message="Unknown PROCESSOR attribute.">
  </cfdefaultcase>
</cfswitch>
