Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Authorize.Net PRG Class integration SIM method 1

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
US
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   = "[URL unfurl="true"]https://secure.authorize.net/gateway/transact.dll"[/URL] && This is the live version
	lcURL   = "[URL unfurl="true"]https://test.authorize.net/gateway/transact.dll"[/URL]	 && 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 		= "[URL unfurl="true"]https://secure.authorize.net/gateway/transact.dll"[/URL] && the live version
		THIS.lcURL 		= "[URL unfurl="true"]https://test.authorize.net/gateway/transact.dll"[/URL]	&& 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
 
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


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

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


Ali Koumaiha
TeknoSoft Inc.
Michigan
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top