Reputation: 53
Below is the example of calling API that I got from Provider, I am facing problem converting this code to coldfusion. Any help will be appriciated
var parameters = new List<RegaloPayBillerFieldWithValue>
{
new RegaloPayBillerFieldWithValue
{
Name = "NPE",
Value = "1234567890"
}
};
var preReceipt = client.RegaloPayPreReceipt(accessId: "2FC60D63-9091-4530-BC08-AF0D5742BBF2", billerPublicId: 3, localAmount: 0, billParameters: parameters);
The part where I am facing the problem is the upper part i.e.
var parameters = new List<RegaloPayBillerFieldWithValue>
{
new RegaloPayBillerFieldWithValue
{
Name = "NPE",
Value = "1234567890"
}
};
Two variables here i.e. Name and value are not being posted correctly.Test url is http://regalocashservice.cloudapp.net:8085/RegaloCashService.svc?wsdl
Upvotes: 2
Views: 114
Reputation: 1003
You could write-
<cfset wsdlurl = "http://regalocashservice.cloudapp.net:8085/RegaloCashService.svc?wsdl">
<cfset parameters = StructNew()>
<cfset RegaloPayBillerField = ArrayNew(1)>
<cfset vars = structNew()>
<cfset ArrayAppend(RegaloPayBillerField, {Name="NPE", Value="1234567890"})>
<cfset StructAppend(parameters, {RegaloPayBillerFieldWithValue = RegaloPayBillerField })>
<cfset vars["billerPublicId"] = 2>
<cfset vars["localAmount"] = 0>
<cfset vars["accessId"] = "2FC60D63-9091-4530-BC08-AF0D5742AAF2">
<cfinvoke webservice="#wsdlurl#" method="RegaloPayPreReceipt" returnVariable="res" argumentcollection="#vars#" >
<cfinvokeargument name="billParameters" value="#parameters#"/>
</cfinvoke>
<cfdump var="#res.getResponseCode()#">
Upvotes: 2
Reputation: 28873
var parameters = new List<RegaloPayBillerFieldWithValue> { new RegaloPayBillerFieldWithValue { Name = "NPE", Value = "1234567890" } };
From the example, and WSDL, it looks like they are just creating an array of structures, which is then passed via a wrapper object ie another structure. I think it should work if you create the array, then wrap it like so:
<cfscript>
// create ArrayOfRegaloPayBillerFieldWithValue wrapper object
parameters = [ {Name="NPE", Value="1234567890"} ];
billParameters = { RegaloPayBillerFieldWithValue=parameters };
// create web service
ws = createObject("webservice", "http://regalocashservice.cloudapp.net:8085/RegaloCashService.svc?wsdl");
// debug
writeDump(ws);
// get result code
result = ws.RegaloPayPreReceipt( "2FC60D63-9091-4530-BC08-AF0D5742AAF2"
, 3 , 0, billParameters );
writeDump(result.getResponseCode());
</cfscript>
Upvotes: 2
Reputation: 186
Note: the code below was tested in CF 11 Dev Edition environment
<cftry>
<cfset parameters = StructNew()>
<cfset StructAppend(parameters, {Name="NPE", Value="1234567890"})>
<cfinvoke webservice="test" method="RegaloPayPreReceipt" returnVariable="res">
<cfinvokeargument name="accessId" value="REAL_ACCESSID_HERE"/>
<cfinvokeargument name="billerPublicId" value="3"/>
<cfinvokeargument name="localAmount" value="0"/>
<cfinvokeargument name="billParameters" value="#parameters#"/>
</cfinvoke>
<cfdump var="#res#">
<cfcatch type="Any">
<cfdump var="#cfcatch.message#">
</cfcatch>
</cftry>
Web Service "test" is mapped to http://regalocashservice.cloudapp.net:8085/RegaloCashService.svc?wsdl in CF Admin Tool. Here is dump of the object returned org.datacontract.schemas._2004._07.domainclasses_dtos_results.RegaloPayPreReceiptResult
Upvotes: 1