×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Authorize.Net PRG Class integration SIM method

Authorize.Net PRG Class integration SIM method

Authorize.Net PRG Class integration SIM method

(OP)
This small class allows FoxPro to submit/process/authorize and CC using Authorize.Net SIM integration using POST method.  You can get really fancy for recurring bililng etc..

I use this online (using FoxWeb) and in my applications.

I use the  wwHTTP, wwUtils, wwAPI from west-wind for the posting.

here is the code:

CODE

&& Using it and testing it
CLEAR
SET PROCEDURE TO wwAPI ADDITIVE
SET PROCEDURE TO wwHTTP ADDITIVE
SET PROCEDURE TO wwUtils ADDITIVE

PUBLIC oCC,oCCHTTP
occHTTP = CREATEOBJECT("WWHTTP")
oCC = CREATEOBJECT("EzCreditCardProcessing")
WITH oCC
    .x_amount         = 1.00
    .x_card_num     = "4007000000027" && Test Credit Card Visa from Authorize.Net
    .x_exp_date        = "0513"
    .x_first_name     ="Ali"
    .x_last_name      = "Koumaiha"

    .x_invoice_num    = "Invoice#"
    .x_description    = "Automated billing thru API"
    lcRet = oCC.Authorize()
    IF NOT EMPTY(.Errormsg)
        ?"Error: " + TRANSFORM(.Errormsg)
        RETURN
    ENDIF     
    ?"code: " + TRANSFORM(.r_response_code)
    ?"Reason: " + .r_response_reason_text
    ?"Auth Code: " + TRANSFORM(.r_auth_code)
    ?"Tran ID: " + TRANSFORM(.r_transaction_id)
ENDWITH
&& End Test


&& Credit Card Processing Class
DEFINE CLASS EzCreditCardProcessing AS CUSTOM
    PROTECTED x_delim_data,x_delim_char

    x_login = ""
    x_tran_key = ""
    *lcURL   = "https://secure.authorize.net/gateway/transact.dll" && This is the live version
    lcURL   = "https://test.authorize.net/gateway/transact.dll"     && Test Account

    * TranType:
    *    AUTH_CAPTURE (DEFAULT),
    *    AUTH_ONLY
    *    CAPTURE_ONLY
    *    CREDIT
    *    VOID
    *    PRIOR_AUTH_CAPTURE
    x_type            = "" && The type of credit card transaction
    x_amount        = 0 && 15 digits no $ signs
    x_card_num        = "" && 13 or 16 digits without spaces
    x_exp_date        = "" && MMYY
    x_trans_id        = "" && required only for CREDIT (Refund) or PRIOR_AUTH_CAPTURE AND VOID
    x_auth_code        = "" && Required only for Capture_Only transactions
    x_invoice_num    = "" && upto 20 chars longs (Merchant assigned invoice number for the transaction)
    x_description    = "" && 255 char max.
    x_first_name    = "" && 50 char max No symbols (first name of billing information)
    x_last_name        = "" && same as first name

    x_delim_data    = "TRUE" && we want a delimited transaction response.
    x_delim_char    = "," && we want comma delimited responses.
    x_encap_char    = ["]
    Errormsg        = ""
    RetVal            = ""
    x_method        = "CC" && by default, we're doing credit card transactions.    

    && if we're doing eCheck
    x_bank_aba_code    = "" && Bank Routing/ABA Code 9 digits
    x_bank_acct_num    = "" && Bank Account number upto 20digits
    x_bank_acct_type= "" && CHECKING/BUSINESSCHECKING/SAVINGS
    x_bank_name        = ""
    x_echeck_type    = "" && WEB..

*** response codes
    r_response_code         = 0     && Type: N  1 Approved, 2 Declined, 3 Error, 4 Held for Error
    r_response_reason_text    = ""    && Type: C    Brief description of the result
    r_auth_code                = ""    && Type: C(6) characThe Auth or approval code
    r_transaction_id        = 0        && Type N     the payment gateway assigned identification number for the trans.
    PROCEDURE INIT

        THIS.SetLogin()
    ENDPROC
    PROCEDURE SetLogin

        this.x_login     = '7f6Kdq9B92kp'  && Test API login
        this.x_tran_key = '7J9t5YXdTu66EX4u' && test API tran_key
        *THIS.lcURL         = "https://secure.authorize.net/gateway/transact.dll" && the live version
        THIS.lcURL         = "https://test.authorize.net/gateway/transact.dll"    && the test account
    ENDPROC

    PROCEDURE ProcessCard
        IF EMPTY(THIS.x_amount)
            THIS.ErroMsg = "Invalid amount entered"
            RETURN .F.
        ENDIF
        IF TYPE("this.x_amount") <> "C"
            this.x_amount= ALLTRIM(TRANSFORM(this.x_amount))
        ENDIF
        IF EMPTY(THIS.x_card_num) AND this.x_method = 'CC'
            THIS.Errormsg = "Invalid Credit Card number entered"
            RETURN .F.
        ENDIF
        IF EMPTY(THIS.x_exp_date) AND this.x_method = 'CC'
            THIS.Errormsg  = "Invalid Expirattion date entered."
            RETURN .F.
        ENDIF
        IF EMPTY(THIS.x_first_name) OR EMPTY(THIS.x_last_name)
            THIS.Errormsg = "You must include First Name and Last Name"
            RETURN .F.
        ENDIF
        IF this.x_method = 'ECHECK ' AND EMPTY(this.x_bank_aba_code)
            This.ErrorMsg = "Empty Bank Routing Number"
            RETURN .f.
        ENDIF
        IF this.x_method = 'ECHECK' AND EMPTY(this.x_bank_acct_num)
            This.ErrorMsg = "Empty Bank Account Number"
            RETURN .f.
        ENDIF
    ENDPROC
    PROCEDURE Authorize
        IF !this.ProcessCard()
            RETURN
        ENDIF
        IF EMPTY(THIS.x_type)
            THIS.x_type = "AUTH_ONLY" && DEFAULT
        ENDIF
        THIS.AddPostKey()
        This.RetVal = occHTTP.HTTPGet(This.lcURL)
        This.ParseResponse()
        RETURN .T.
    ENDPROC
    PROCEDURE Charge
        IF !this.ProcessCard()
            RETURN
        ENDIF
        IF EMPTY(THIS.x_type)
            THIS.x_type = "AUTH_CAPTURE" && DEFAULT
        ENDIF
        THIS.AddPostKey()
        This.RetVal = occHTTP.HTTPGet(This.lcURL)
        This.ParseResponse()
        RETURN .T.
    ENDPROC


    PROCEDURE AddPostKey()
        occHTTP.AddPostKey("x_login", THIS.x_login)
        occHTTP.AddPostKey("x_tran_key", THIS.x_tran_key)
        occHTTP.AddPostKey("x_type", THIS.x_type)
        occHTTP.AddPostKey("x_amount", THIS.x_amount)
        occHTTP.AddPostKey("x_trans_id", THIS.x_trans_id)
        occHTTP.AddPostKey("x_auth_code", THIS.x_auth_code)
        occHTTP.AddPostKey("x_invoice_num", THIS.x_invoice_num)
        occHTTP.AddPostKey("x_description", THIS.x_description)
        occHTTP.AddPostKey("x_first_name", THIS.x_first_name)
        occHTTP.AddPostKey("x_last_name", THIS.x_last_name)
        occHTTP.AddPostKey("x_delim_data", THIS.x_delim_data)
        occHTTP.AddPostKey("x_delim_char", THIS.x_delim_char)
        occHTTP.AddPostKey("x_method",This.x_Method)
        
        IF this.x_method = 'ECHECK' && eCheck.
            occHTTP.AddPostKey("x_bank_aba_code",This.x_bank_aba_code)
            occHTTP.AddPostKey("x_bank_acct_num",This.x_bank_acct_num)    
            occHTTP.AddPostKey("x_bank_acct_type",this.x_bank_acct_type)
            occHTTP.AddPostKey("x_echeck_type",this.x_echeck_type)
        ELSE && credit card
            occHTTP.AddPostKey("x_card_num", THIS.x_card_num)
            occHTTP.AddPostKey("x_exp_date", THIS.x_exp_date)
        ENDIF
    ENDPROC
    PROCEDURE ParseResponse()
        IF EMPTY(This.RetVal)
            RETURN
        ENDIF
        LOCAL lcResponseStr

        lcResponseStr = this.RetVal
        ALINES(laResponse,lcResponseStr,1,",")
        IF ALEN(laResponse) <= 0 && error occured
            RETURN
        ENDIF
        && Testing code for responses.
*        FOR x = 1 TO ALEN(laResponse)
*            ?laResponse[x]
*        ENDFOR
*        WAIT WINDOW 'hit any key...'
*        CLEAR
        && end testing
        this.r_response_code        = laResponse[1]
        this.r_response_reason_text    = laResponse[4]
        this.r_auth_code            = laResponse[5]
        this.r_transaction_id        = laResponse[7]
        RETURN
    ENDPROC
ENDDEFINE

Ali Koumaiha
TeknoSoft Inc.
Michigan

RE: Authorize.Net PRG Class integration SIM method

(OP)
Btw, this class you can use it for Credit Card, and ACH/eCehck
also, you can Authorize only (AUTH_ONLY), And Charge (AUTH_CAPTURE), you can do refund as well. (VOID).

Here are the different transactions you can do with the .x_type property according to authorize.net

http://developer.authorize.net/guides/AIM/Submitting_Transactions/Credit_Card_Transaction_Types.htm

I mainly use AUTH, AUTH_CAPTURE (to charge), and VOID.

just set the .x_type = "AUTH" && Or whatever.
 

Ali Koumaiha
TeknoSoft Inc.
Michigan

RE: Authorize.Net PRG Class integration SIM method

(OP)
Sorry, I think, this is AIM (Advanced Integration Method) and not SIM.
You can get your own API key and login from authorize.net
the one above are my test ones.

Hope someone might find it useful.  
let me know what you think guys!
 

Ali Koumaiha
TeknoSoft Inc.
Michigan

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close