Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using AS3 to connect to a payment page

New Here ,
Jan 25, 2012 Jan 25, 2012

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?

TOPICS
ActionScript
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2012 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2012 Jan 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2012 Jan 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2012 Jan 25, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2012 Jan 25, 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2012 Jan 25, 2012

The trace method does return data:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

  <title>Checkout</title>

  <meta http-equiv="Content-Script-Type" content="text/javascript" />

  <link rel="stylesheet" type="text/css" href="content/Checkout.css" />

  <style type="text/css">

      </style>

</head>

<body>

  <form id="form2" method="post" action="" style="display:none">

    <div>

              <center>

      <div class="Page">

        <div style="margin:16px;">

          <div id="divContinue">

            <p>Click Continue if you are not taken to the next page.</p>

            <input type="submit" id="btnSubmit2" value="Continue" />

          </div>

          <div id="divWaiting" style="display:none;">

            <p>Processing...</p>

          </div>

        </div>

      </div>

      </center>

    </div>

  </form>

  <form name="form1" method="post" action="CatalogPayment.aspx" id="form1">

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5NDM2MTU2MzkFgICDA9kFgICAQ8QZGQWAGQCBQ8WAh4HVmlzaWJsZWcWAgIBDxYCHwBnZGQgBjpVZRKr/N+iOoZBbu3o74KoxQ==" />

    <div id="divPnlError">

      <span id="spnErrorMainNotFound">The item you requested is no longer available.</span>

    </div>

  </form>

</body>

</html>

But that's all that happens.

Is this where the

//urlLoader.dataFormat=

Line comes in to play.

I also thought about using a simple 2-click process temporarily:

navigateToURL(new URLRequest("PayPage.html"));

with the authorize.net code pasted into an html page I created and put in the website folder.  Firefox couldn't find it to load.  Anyway, I'm glad you are around, hope Adobe is paying you well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2012 Jan 25, 2012

leave that dataFormat out.  text is the default and that's what's being returned.

actually, that's code for an html page which can be used but there's probably some way to work with that cataloguepayment file inside flash.  that would require learning how to use flash with simplecheckout.

p.s.  adobe doesn't pay me.  i'm a volunteer.  (but they are nice to me.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2012 Jan 25, 2012

That still leaves me and the client without a page that can be used for payments.   So where do I go from here?  This shouldn't be so difficult. (Famous last words).  And I hope Adobe is very nice to you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2012 Jan 25, 2012

Or alternatively,  why won't this work where PayPage.html loads up fine when tested on its own in Dreamweaver but won't work when I try

navigateToURL(new URLRequest("PayPage.html"));

when it's a file at the same level and in the same folder as the .swf file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2012 Jan 25, 2012

you'll have to save that html string to an html file, then you can use navigateToURL() to open it.

you can do that by again using the urlloader class similar to your call to that aspx page, but you'll call a local (to your server) script that will create the html file (on your server).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2012 Jan 25, 2012

I tried loading the text to a blank html file in Dreamweaver and testing it.  The code/text gets me nowhere.   As to the 'you'll call a local (to your server) script that will create the html file (on your server)' comment, all I've got to say is HUH?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2012 Jan 25, 2012

save that html code to a file and name it something.html and open it in your web browser.  is that what you expected to be returned from the aspx file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 26, 2012 Jan 26, 2012

No, it just returns a page with text on it.  

Let's back up here...

The original code was meant to be pasted into an html page and would create a button that when pressed would take you to a payment page. So (I'm assuming), form code created a button,   the https address took you to authorize.net and the id and log-in that was sent via the POST method was what connected the user to the merchant's specific account. 

So I believe what I need to do is create a submit button that posts the  name and id values to the authorize.net site.  As though I were creating an e-mail form for guests to sign up to the site.  So it's a 'navigateToURL' with POST method?  If so, I'm not sure how to extract the name and id information from the original code:

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

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

Nor am I sure how to set up the POST method.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 26, 2012 Jan 26, 2012

So I saw this example:

var variables:URLVariables = new URLVariables();

var varSend:URLRequest = new URLRequest("sendEntry.php");

var varLoader:URLLoader = new URLLoader;

varSend.method = URLRequestMethod.POST;

varSend.data = variables;

stop();  send_btn.addEventListener(MouseEvent.CLICK, sendActions)

function sendActions(event:MouseEvent):void

{ variables.totwHeadline = totwHeadline.text; variables.totwContent = totwContent.text; varLoader.load(varSend); }

But again, I'm not sure how to fold in the variables from the original code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2012 Jan 26, 2012

i already showed how to post to that aspx page and send the LinkId variable in a previous post.  did you use that code?  if yes, show exactly what you used (unless your LinkId value is private in which case you can change it).  actually, that can't be private so show your exact code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 26, 2012 Jan 26, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 29, 2012 Jan 29, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines