Discussion:
How to install Java SDK into Coldfusion
(too old to reply)
DennBen
2009-08-14 12:32:37 UTC
Permalink
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
2009-08-14 13:42:33 UTC
Permalink
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
2009-08-19 17:24:20 UTC
Permalink
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");
Post by DennBen
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
 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 : ''
<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>
<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>
Loading...