Authorize.Net Apex Library: Salesforce and Authorize.Net Integration

Saturday, May 28, 2011 by Aslam - The Alexendra
Hi All,
Recently I came across one requirement where end user wants an easy way to pay fixed amount online from Salesforce to third party something like Donate page. In one of my previous post i showed you how you can do that using Paypal. Here is that paypal solution:
http://techsahre.blogspot.com/2011/01/simple-paypal-integration-with.html

I was thinking to implement the same thing but this time end user wanted something simpler easy to use and easy to test solution. Then i found that 'Authorize.Net' is one of the good solution for this type of requirements. Then i created one simple ready to use online payment tool in salesforce using 'Authorize.Net' as payment gateway.



I found a good tutorial here in PHP how to make that here. I used the same idea and rebuild my Apex solution.

You can download the package from this link:
https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t90000000PqIH

Before using the tool, you first need to follow some basic things:

1) For checking/testing the things you need first test accounts. Go to "test account" page on Authorize.Net and create one merchant account (Card Not Present).

2) Change your "login" and "transkey" variables in "AuthorizeDotNet" class with the merchant account's API login id and transaction id.

After that you can simply use VF page "DoPayment" to see how this works.
/apex/DoPayment



On click of submit you will get information about your transaction, if successful it will show you transaction id and success message. Otherwise will show error message.

Check out this easy cool stuff and give me feed backs as always.


Thanks
Aslam Bari

37 comments:

Chirag Mehta said...

Nice handy and good re-usable tool buddy.

Thanks
Chirag

Jim said...

If you want to extend this library with recurring payments and electronic check integration please check out Chargent (paid but free for partners and non-profits) http://tinyurl.com/chargent

Aslam - The Alexendra said...

@jim: your tool is great :)

Anonymous said...

Nice handy one Aslam. One thing i am interested to know is to know integration with other legacy systems. I know that its a big topic, but to put it short: an example that walks through Integration (Both ways with SFDC)....As always your posts are good learning points...

Thanks,
Kumar

Aslam - The Alexendra said...

@kumar: there are couple of tools to integrate between SFDC and your legacy system. Some are:
1) Cast Iron
2) Informatica
3) Talend

If you need is something different then you can use SFDC APIs and integrate using Java/PHP.

Thanks

Anonymous said...

Aslam,

I am looking for some guidance/examples on using SFDC API's with .Net/Java...I am unable to understand outbound messaging whenever we want to sync data between SFDC and legacy systems..
Can you point me in right direction??.

Thanks,
Kumar

Anonymous said...

Aslam,

Would it be easy to extend this process eCheck as well as credit card?

Thanks,
Mike

Mike said...

Aslam,

It was easy to extend this for eCheck as well. You rock!

Thanks again!
Mike

Aslam - The Alexendra said...

@Mike: Have you done for eCheck? If yes, please share the code with others

Anonymous said...

I don't see any of the CIM type transactions in the code?

salesforce monkey said...

Great Post.

PRATTITUDE said...

If I include the hosted Authorize.net page as an iframe in a VF page and try to get response on a salesforce site. It gives me a time out error. Anyone has a solution for this problem?

The url of the site is,
https://suppliercentral-stgqa.secure.force.com/

Anonymous said...

Does it requires Enterprise license? we have Professional but it requires Apex Clases. Does it works in Professional licenses?

Unknown said...

I have already integrate authorized.net with Apex library. For it I have just followed simple step process and now it is ready.

Authorize.net Integration

Anonymous said...

Can we give real time credit card information to process...

Anonymous said...

Aslam,

I clicked the link to download the package. I requires me to log in.

Is the package still available?

Uzair said...

Hi Aslam,

I'm getting the following error msg when submitting test transactions.

System.ListException: List index out of bounds: 3
Class.AuthorizeDotNet.getResponseText: line 160, column 1
Class.DoPaymentHandler.process: line 102, column 1

Earlier I was not getting this error message. Am I doing some thing wrong?

Aslam - The Alexendra said...

@Uzair
On line number 84, there is debug statement
system.debug('#### ' + this.response);
for printing the response of your API call. Please check in debug logs what you are getting. then only i will be able to answer

Uzair said...

Hi Aslam,

Thanks for your quick response.

In debug log I got this message "Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://test.authorize.net/gateway/transact.dll".

Now I have created a Remote Site with the given url i.e, 'https://test.authorize.net/gateway/transact.dll'; Now it is working fine.

Thanks for your time.

Anonymous said...

Hello Aslam
I am new to salesforce and i am given this task to intall your packge but whenever i try to install this package i get the following error kindly help me out, the second thing is where shod i give my api and key??

Waqar

accountcallout.null()
line 5, column 9: Method does not exist or incorrect signature: WebServiceCallout.sendNotification(String, String)
null

Anonymous said...

Hello Aslam
Great work! there is one thing i am confused with, whether it is only applicable for test account or we can use it for premium accounts too...

GINA

Unknown said...

Hi this is imran can i know method for refund the money by using authorized.net

Brian L Bartholomew said...

Hello Aslam,

This tool is awesome! I have integrated doPaymentHandler in another class. I have tried both (1) creating an instance of it:
DoPaymentHandler dph = new DoPaymentHandler();
then assigning the variables
dph.firstname = b_fistName;
...

and (2) bring in the functions and variables into my class.

I call then call the process() function. It process the information but then i don't get any response from Authorize.ned so
public string getResponseText()
{
return this.results[3];
}

returns null.

I have ran the same info through you dopayment page and it works just fine.

Any Ideas???

Brian L Bartholomew said...

sorry it does not return null it return index out of bounds error

Brian L Bartholomew said...

So the issue was that it was never actually making it to that point. so response would be null because it was never set. the problem was that i was trying to make a http request after i had made a dml statement. i reversed the order and now it works.

Anonymous said...

Hi ASLAM ,

Can you please let me know you are using which method of Authorize.net Integration ?

Anonymous said...

Hi Aslam,

I would like to try out your code, but how do I install it onto the sandbox? It seems that it only takes my login to the live site. Thanks in advance!

Unknown said...

I love all the posts, I really enjoyed, I would like more information about this, because it is very nice., Thanks for sharing.
Signature:
download free descargar whatsapp plus and download baixar whatsapp plus online and descargar whatsapp , baixar whatsapp gratis

Unknown said...

The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful
Signature:
Jugar juegos de frozen en lĂ­nea gratis, los nuevos de princesa de Disney juegos frozen - la princesa encantadora y linda. Divertirse frozen!

Unknown said...

Thank you for that information you article
kid games
friv2
unblocked games 77
juego de un show mas

Unknown said...

Hi Aslam,

Is the package uptodate? I tried installing it in my developer org and got error saying Test.isRunningTest() is not valid. Can you share the source code on kumarcagarwal@gmail.com?

Unknown said...

Hi Aslam,

Is the package uptodate? I tried installing it in my developer org and got error saying Test.isRunningTest() is not valid. Can you share the source code on kumarcagarwal@gmail.com?

Unknown said...

I would very much like to agree with the previous commenter! I find this blog really useful for my uni project. I hope to add more useful posts later.
Open Facebook
| Science Kombat
| Science Kombat Game
| Earn to Die
| Tank Trouble

Anonymous said...

Hi, I've been using this Integration for a few years now. We need to integrate now Salesforce to Xero. Do you have any idea about it?

Aslam - The Alexendra said...

Lets connect at aslam.bari@gmail.com for discuss about salesforce to xero

Julie taylor said...

This is great post...
best website development services | affordable seo services

Naveed Mughal said...

I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!
high risk international merchant account

Post a Comment