Skip to main content
Known Participant
January 25, 2012
Question

Using AS3 to connect to a payment page

  • January 25, 2012
  • 3 replies
  • 3401 views

I'm trying to integrate the code of an 'authorize.net' payment button into a Flash website via actionscript. A button (that worked) was already setup with a navigateToURL command and it worked with another payment company but authorize.net wants form code submitted:

<i><form name="PrePage" method = "post" action =

"https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">

<input type = "hidden" name = "LinkId" value

="00000=00000-0000-abcd-etc" /> <input type = "submit" value

= "Pay Now" /> </form></i>

How do I submit/create the form (if that is what I'm doing) from within the Flash site in AS3?

This topic has been closed for replies.

3 replies

VideoEAuthor
Known Participant
January 27, 2012

Sorry about the delated response KGLAD.  It has been a truly lousy day.   Yes, I did use your code and what was traced back was the html page code I posted.  (I've been told by authorize.net not to post the LinkId #.  I've also been told that there services are only available to an html compatible website.  Real pr_cks.)   

So I used this code of yours:

assign your button an instance name (in the properties panel), if it was placed on-stage in the authoring environment.  eg, submit_btn.  then use:

submit_btn.addEventListener(MouseEvent.CLICK,f);

function f(e:MouseEvent):void{

var urlLoader:URLLoader=new URLLoader();

//urlLoader.dataFormat=depends on the dataformat received from that aspx file.  if text, you can leave this commentd-out.

urlLoader.addEventListener(Event.COMPLETE,completeF);

var urlReq:URLRequest = new URLRequest("https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx");

urlReq.method="POST";

var urlVar:URLVariables=new URLVariables();

urlVar.LinkId="00000=00000-0000-abcd-etc"; // make sure you change this to your unique identifier.

urlReq.data=urlVar;

urlLoader.load(urlReq);

}

function completeF(e:Event):void{

trace(e.target.data);

}

In the output panel  I got the html text I posted above.  If I use that text to create another html page and open it in a browser I get a message "Service not avaiable".   I'm sorry if my ignorance is driving you nuts.

I created an interim solution, creating a seperate html page that has the code pasted in.  It's a 2 click solution but it works-sort of.  If you go to:   http://www.workinglightstudios.com/Norma   you'll see an html page that I created with an 'enter' button that has a few words on the page and in the header for bots to recognize.  Clicking that leads you to what was a working preloader swf, it does work but for some reason the error text and loading animation hangs, but be patient and the site will load up.  I'll fix the preloader tomorrow.  Go to the Contacts page and click the payment button, then click again and voil'a.

Inspiring
January 29, 2012

why dont you use the urlrequest (including post method and vars) with the navigateToUrl method?

kglad
Community Expert
Community Expert
January 25, 2012

var urlLoader:URLLoader=new URLLoader();

//urlLoader.dataFormat=depends on the dataformat received from that aspx file.  if text, you can leave this commentd-out.

urlLoader.addEventListener(Event.COMPLETE,completeF);

var urlReq:URLRequest = new URLRequest("https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx");

urlReq.method="POST";

var urlVar:URLVariables=new URLVariables();

urlVar.LinkId="00000=00000-0000-abcd-etc"; // make sure you change this to your unique identifier.

urlReq.data=urlVar;

urlLoader.load(urlReq);

function completeF(e:Event):void{

trace(e.target.data);

}

VideoEAuthor
Known Participant
January 26, 2012

Here's where I really show my ignorance.  I copied and pasted your script and hooked up my button to your 'completeF' event, which is probably the wrong thing to do.  Anyway, I got this error message:

ReferenceError: Error #1069: Property data not found on fl.controls.Button and there is no default value.

    at MacLeod_FinalDraft_v2_fla::MainTimeline/completeF()

I'm also confused as to  what in the code is actually taking me to the payment page as opposed to loading up a payment button.

kglad
Community Expert
Community Expert
January 26, 2012

assign your button an instance name (in the properties panel), if it was placed on-stage in the authoring environment.  eg, submit_btn.  then use:

submit_btn.addEventListener(MouseEvent.CLICK,f);

function f(e:MouseEvent):void{

var urlLoader:URLLoader=new URLLoader();

//urlLoader.dataFormat=depends on the dataformat received from that aspx file.  if text, you can leave this commentd-out.

urlLoader.addEventListener(Event.COMPLETE,completeF);

var urlReq:URLRequest = new URLRequest("https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx");

urlReq.method="POST";

var urlVar:URLVariables=new URLVariables();

urlVar.LinkId="00000=00000-0000-abcd-etc"; // make sure you change this to your unique identifier.

urlReq.data=urlVar;

urlLoader.load(urlReq);

}

function completeF(e:Event):void{

trace(e.target.data);

}

kglad
Community Expert
Community Expert
January 25, 2012

use the urlloader class to call https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx.  you'll use the urlvariables class to assign data to your urlrequest.

VideoEAuthor
Known Participant
January 25, 2012

kglad, thanks for the reply.  How do I use/code the url variable class to do this?  Think of me as a newbie in over his head (for now).