Date:  04/09/2012 08:28:22 AM Msg ID:  004439
From:  Ali Koumaiha Thread:  004431
Subject:  Re: Authorize.Net with FoxWeb
This small class allows FoxPro to submit/process/authorize/charge credit card and eCheck using Authorize.Net AIM integration using POST method. You can get really fancy for recurring bililng, charging,  etc..

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

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

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.

Ofcourse you need to get your own api key etc.. easily, go to authorize.net and register as a developer, and they give you a sandbox and your own api and api key to test.
then in realtime, simple change the api to the real account (and merchant ID)


&& 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

Sent by Martin Martin on 04/09/2012 08:21:02 AM:
Yes I'm !

Where can we all share FoxWeb program? I guess we need a shared library ?

I personatly wrote many many program utility, that I would like to share, if it can help other developpers.

Martin






Sent by Ali Koumaiha on 04/05/2012 01:43:13 PM:
If anyone intrested in a small little PRG class i wrote that integrates FoxPro with Authorize.net (credit card processing / eCheck / ACH) using AIM (advance integration method), let me know.

i will post the small prg class code here.

I use it on the eCommerce part of my client's portal (b2b) and i use it in our ERP desktop VFP application.