This discussion is archived
6 Replies Latest reply: Mar 5, 2013 5:19 PM by scott.wesley RSS

How to execute Javascript from within a PL/SQL Page Process?

Russ C Newbie
Currently Being Moderated
Hello All,
I'm developing a page that calls PayPal's Adaptive Payments API and I've had success in POSTing to PayPal and getting a response with a valid "Paykey" using a PL/SQL page process. I heavily relied on "Integrating Application Express with PayPal Payments Pro" found at http://www.oracle.com/technetwork/developer-tools/apex/integrating-application-express-wit-129259.pdf


Now I need to call PayPal again(from within the same Page Process) in order for my user to approve the payment I just setup.

PayPal's API doc says to execute the following Javascript, but I can't figure out how to call it from within a PL/SQL Page Process...:


function javascriptLaunch()
{
flow_Javascript = new PAYPAL.apps.DGFlow({ expType: "light" });
flow_Javascript.startFlow("https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=<paykey returned earlier>");
}
javascriptLaunch(); -- To auto-execute the function


Note: The "src" in the header is:
<head>
<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
</head>


So if I take the URL in the startFlow (and provide a valid paykey) and put it in my browser URL I get an approval page as expected, but I need to have the approval "pop up" in a lightbox from within a PL/SQL Page Process.

I figure it is something simple, but I need your help.

Thanks,
Russ

Below I have included the entire contents of a local file I created to prove the javascriptLaunch works and is not the problem (of course PayPal give an error in the lightbox since it can't find a paykey of "junk"):

<html>
<head>
<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
</head>

<body>

<script type="text/javascript">
function javascriptLaunch()
{
flow_Javascript = new PAYPAL.apps.DGFlow({ expType: "light" });
flow_Javascript.startFlow("https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=junk");
}
javascriptLaunch();

</script>



</html>
  • 1. Re: How to execute Javascript from within a PL/SQL Page Process?
    matthew_morris Expert
    Currently Being Moderated
    The following thread is regarding calling a dynamic action from PL/SQL. He just wanted a Javascript alert box, but the technique should be applicable to what you need:

    Use Dynamic Actions with pl/sql calling a javascript alert function
  • 2. Re: How to execute Javascript from within a PL/SQL Page Process?
    Russ C Newbie
    Currently Being Moderated
    Perhaps I was not clear... I need call the javaScript from a PL/SQL Page Process, not a dynamic action based on a page item.
    Maybe I just don't understand how to have a dynamic action execute at a page level after a certain Page process.

    Since I can do what I wish with the <html> ... </html> in the prevous post, does anyone know a way to execute that html from PL/SQL that will use the current browser window? I've tried UTL_HTTP and HTP packages, but I'm not having success.

    Thanks ,
    Russ
  • 3. Re: How to execute Javascript from within a PL/SQL Page Process?
    scott.wesley Guru
    Currently Being Moderated
    Why does it need to be executed from the pl/sql process?

    What invokes the process? Is it a button on the page?
    Could that button invoke a dynamic action that fires some javascript, then some plsql, then call your required javascript API?

    Scott
  • 4. Re: How to execute Javascript from within a PL/SQL Page Process?
    Tom Petrus Expert
    Currently Being Moderated
    I think you're going about this in the wrong way. You don't want to run html or javascript from plsql, but you want to run plsql from your html/javascript. It seems that you have a plsql block which gets a paykey, and you want to use that key in a piece of javascript.
    Instead of having your page submit and do processing, you'd rather perform an ajax request from within javascript code to retrieve the paykey from either the plsql block in apex or directly from paypal (since you're POSTing anyway from the plsql block).
    You don't even have to write a lot of javascript. You could just as well use a dynamic action to retrieve the paykey through the database by using a PLSQL block in a true action, followed by a javascript code true action.
  • 5. Re: How to execute Javascript from within a PL/SQL Page Process?
    matthew_morris Expert
    Currently Being Moderated
    Perhaps I was not clear... I need call the javaScript from a PL/SQL Page Process, not a dynamic action based on a page item.
    Maybe I just don't understand how to have a dynamic action execute at a page level after a certain Page process.
    The way I read the thread that I posted the link to, the solution was to create a dynamic action against page Item X. They then used PL/SQL to change that page item, which kicked off the dynamic action to execute the Javascript. I didn't actually try it (and might have read it wrong), but I do understand what you are trying to do. From the description of his thread, he was successful in executing a Javascript function to issue an Alert from within his PL/SQL process. If that method could do that, then presumably the same method could kick off any Javascript function.
  • 6. Re: How to execute Javascript from within a PL/SQL Page Process?
    scott.wesley Guru
    Currently Being Moderated
    Just another thought: one time I defined an item on page zero that "listened" for a change using a DA, which then invoked the notification plugin - displaying the gritter Notification plug-in for a relevant signal.

    So once the DA is triggered, it could then invoke js/plsql or whatever. It might not be relevant for your situation, but was a method that came to mind that may be useful for someone else.

    Scott

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points