cancel
Showing results for 
Search instead for 
Did you mean: 

AIM newbie help with sample code!

Hello! 

 

So I just started getting into payment methods and such and I looked between authorize.net and paypal, and based on the sample code with authorize.net it seems a little easier to me. However, I still have a few questions as I'm new to this industry.

 

I used and tested the sample code from this site http://developer.authorize.net/downloads/samplecode and tested it with PHP. My question is, if I build a page and pass the variables into the values that is required within the sample code, is that good enough to have a payment system? Also, when I tested the sample code, it outputs a list of values. How do I have it so if the credit card is authorized, the page will be sent somewhere else?

 

 

Thanks, hopefully you guys can understand my issue and help me resolve it.

andrewliu
Contributor
1 ACCEPTED SOLUTION

Accepted Solutions

Since you're using PHP,  I might be able to help.

I've never coded in PHP before, so my method might seem a bit strange to those who use it all the time.

 

On the page where I am getting the transaction result data from AuthNet,  I put this at the end of all the code:

$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "<meta http-equiv=refresh content=0;url=http://www.yourdomainname.com/yourdirectory/yourpage.php?responsecode="
	. urlencode($parsedresponse->messages->resultCode)
	. "yourvariable_1="
	. $_POST["yourvariable_1"]
	. "&yourvariable_2="
	. $_POST["yourvariable_2"]
	. ">";
}

 

What that does is create a META Refresh on the page that redirects the browser to the specified URL.

In that URL there is 1 variable that is coming from AuthNet's response, and 2 variables that were passed to the page by my own form.

 

'resultcode' is coming from AuthNet, and we are assuming that the value of that is 'Ok' for this example.

'yourvariable_1' and 'yourvariable_2' were passed through the form on whatever page triggered this transaction page.

 

For example,  if I had passed yourvariable_1 with the value '123' and had passed yourvariable_2 with 'ABC',  when the user was redirected using the META Refresh they would end up at:

 

www.yourdomain.com/yourdirectory/yourfile.php?responsecode=Ok&yourvariable_1=123&yourvariable_2=ABC

 

You just need to change the 'yourvariable' references to whatever you are actually passing (if you are passing anything at all that you need for your own tracking purposes).

 

The line with the $urlencode in it is pulling data that comes back from Authnet.

The lines with $_POST is getting that data from the form that was used to load the page to begin with.

 

You can add/remove more of them as required by your own needs.

 

You can also set whatever page you want as the landing page from the META Refresh..  it doesn't have to be a php page.

 

There is probably some easier way to do this.. or maybe a 'better' way.. but this works for me.

 

 

View solution in original post

WHeisenberg
Regular Contributor
3 REPLIES 3

Since you're using PHP,  I might be able to help.

I've never coded in PHP before, so my method might seem a bit strange to those who use it all the time.

 

On the page where I am getting the transaction result data from AuthNet,  I put this at the end of all the code:

$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "<meta http-equiv=refresh content=0;url=http://www.yourdomainname.com/yourdirectory/yourpage.php?responsecode="
	. urlencode($parsedresponse->messages->resultCode)
	. "yourvariable_1="
	. $_POST["yourvariable_1"]
	. "&yourvariable_2="
	. $_POST["yourvariable_2"]
	. ">";
}

 

What that does is create a META Refresh on the page that redirects the browser to the specified URL.

In that URL there is 1 variable that is coming from AuthNet's response, and 2 variables that were passed to the page by my own form.

 

'resultcode' is coming from AuthNet, and we are assuming that the value of that is 'Ok' for this example.

'yourvariable_1' and 'yourvariable_2' were passed through the form on whatever page triggered this transaction page.

 

For example,  if I had passed yourvariable_1 with the value '123' and had passed yourvariable_2 with 'ABC',  when the user was redirected using the META Refresh they would end up at:

 

www.yourdomain.com/yourdirectory/yourfile.php?responsecode=Ok&yourvariable_1=123&yourvariable_2=ABC

 

You just need to change the 'yourvariable' references to whatever you are actually passing (if you are passing anything at all that you need for your own tracking purposes).

 

The line with the $urlencode in it is pulling data that comes back from Authnet.

The lines with $_POST is getting that data from the form that was used to load the page to begin with.

 

You can add/remove more of them as required by your own needs.

 

You can also set whatever page you want as the landing page from the META Refresh..  it doesn't have to be a php page.

 

There is probably some easier way to do this.. or maybe a 'better' way.. but this works for me.

 

 

WHeisenberg
Regular Contributor

Thank you for taking the time to help me out.

 

I understand how your code works, but I'm trying to understand the implementation. Like where is the $response coming from? The only thing I have in front of me is the sample php from that url. And it goes through a foreach loop getting the values of user's credit card and billling information. I ran through the php and I can verify that it works because I get emails saying that the test card was authorized. 

 

But can you show me how your $response looks like? What variables/values its holding? But also, it looks like you're using object-oriented programming with -> which I'm still a beginner at, and would like to see some information with what is written for messages and resultCode?

 

Thanks for your help, I think these examples will help me greatly!

 

 

Hmmm. Okay I did some more researching and I think I got it figured out!

 

Thanks!