Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / General CF Topics / August 2009



Tip: Looking for answers? Try searching our database.

How to install Java SDK into Coldfusion

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DennBen - 14 Aug 2009 13:32 GMT
I have to implement PayPal express checkout functionality in addition
to 2 other pay methods on a coldfusion 8 hosted website. PayPal has a
java sdk available that is supposed to work with coldfusion and house
the core functionality for the API calls. However, I have no
experience with Java and am lost trying to configure the sdk within
coldfusion.

Can anyone assist me with a step by step guide?
DennBen - 14 Aug 2009 14:42 GMT
Well I am a small step further. I placed all the .jar files
in :ColdFusion8\runtime\jre\lib\ext to be configured as additional
java classes that Coldfusion has access to instead of using CFADMIN
which was not working for me at all. Now I get the following error:
Object Instantiation Exception.
An exception occurred while instantiating a Java object. The class
must not be an interface or an abstract class. If the class has a
constructor that accepts an argument, you must call the constructor
explicitly using the init(args) method. Error : ''

Here's the CFC i'm calling:
<cfcomponent displayname="PayPal" hint="PayPal Gateway">
    <cfscript>
        PPInitialize();
    </cfscript>
    <cffunction name="PPInitialize" returntype="void" output="no">
         <cfset ppSignature = "myHardCodedSig">
         <cfscript>
          // Create CF caller object
          pp_caller = CreateObject("java",
"com.paypal.sdk.services.CallerServices");

          // Set API profile
          pp_profile = CreateObject("java",
"com.paypal.sdk.profiles.SignatureAPIProfile");
          pp_profile.setAPIUsername("myHardcodedusername");
          pp_profile.setAPIPassword("myHardCodedPassword");
          pp_profile.setSignature(ppSignature);
          pp_profile.setEnvironment("sandbox"); //live
          pp_caller.setAPIProfile(pp_profile);
         </cfscript>
    </cffunction>

    <cffunction name="SetExpressCheckout" returntype="Struct"
output="no">
        <cfargument name="returnURL" type="string" required="true">
        <cfargument name="cancelURL" type="string" required="true">
        <cfargument name="paymentAmount" type="string" required="true">
        <cfargument name="maxAmount" type="string" required="true">

        <cfscript>
            // Create the request object
            pp_request = CreateObject("java",
"com.paypal.soap.api.SetExpressCheckoutRequestType");

            details =  CreateObject("java",
"com.paypal.soap.api.SetExpressCheckoutRequestDetailsType");

            details.setReturnURL(returnURL);
            details.setCancelURL(CancelURL);

            currencies = CreateObject("java",
"com.paypal.soap.api.CurrencyCodeType");
            orderTotal = CreateObject("java",
"com.paypal.soap.api.BasicAmountType");
            orderTotal.setCurrencyID(currencies.USD);
            orderTotal.set_value(paymentAmount);

            details.setOrderTotal(orderTotal);

            maxAmountTotal = CreateObject("java",
"com.paypal.soap.api.BasicAmountType");
            maxAmountTotal.setCurrencyID(currencies.USD);
            maxAmountTotal.set_value(maxAmount);

            details.setMaxAmount(maxAmountTotal);

            paymentTypes = CreateObject("java",
"com.paypal.soap.api.PaymentActionCodeType");
            details.setPaymentAction(paymentTypes.Sale);

            pp_request.setSetExpressCheckoutRequestDetails(details);
        </cfscript>
        <cfset results = #pp_caller.call("SetExpressCheckout", pp_request)#>
        <cfset responsestruct = structnew()>
        <cfset responsestruct.Token = results.getToken()>
        <cfreturn #responsestruct#>
    </cffunction>
</cfcomponent>

Here is the Coldfusion test page calling the CFC function:

<center><h2>PayPal ExpressCheckout test 2</h2></center>
<CFSET variable.a = "">
<CFSET varible.b = "">

<cfinvoke component="globalShare.components.paypal"
method="SetExpressCheckout" returnvariable="variable.a">
    <cfinvokeargument name="returnURL" value="http://localhost:8500/
taxpaymentsoftware"/>
    <cfinvokeargument name="cancelURL" value="http://google.com"/>
    <cfinvokeargument name="paymentAmount" value="100.00"/>
    <cfinvokeargument name="maxAmount" value="1000.00"/>
</cfinvoke>

<CFDUMP var="#variable.a#"><BR><BR>
Chris Blackwell - 19 Aug 2009 18:24 GMT
the java objects you are creating need to have their constructor
called.  In java this is done automatically when you create an new
instance like

myfoo Foo = new Foo("Hi Chris");

in coldfusion you need to tell CF to call the constructor and get you
a new instance

myfoo = createobject("java", "Foo").init("Hi Chris");

> Well I am a small step further. I placed all the .jar files
> in :ColdFusion8\runtime\jre\lib\ext to be configured as additional
[quoted text clipped - 92 lines]
>
> <CFDUMP var="#variable.a#"><BR><BR>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.