2013-07-15 40 views
2

我試圖在ColdFusion中使用它們的Java庫實現GoCardless訂閱(根據文檔https://gocardless.com/docs/java/merchant_client_guide#installation-and-setup)。我很新的使用Java與ColdFusion和我收到以下錯誤:找不到方法 - 在ColdFusion中使用GoCardless Java庫

The newSubscriptionUrl method was not found - Either there are no methods with the specified method name and argument types or the newSubscriptionUrl method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

這是產生錯誤的代碼如下:

<cfset GoCardless = createobject("java","gocardless.GoCardless")> 

<cfset GoCardless.environment = GoCardless.Environment.SANDBOX> 

<cfset GoCardless.accountDetails.setAppId("My app ID")> 
<cfset GoCardless.accountDetails.setAppSecret("My app secret")> 
<cfset GoCardless.accountDetails.setAccessToken("My access token")> 
<cfset GoCardless.accountDetails.setMerchantId("My merchant ID")> 

<cfset monthlyAmount = 35> 
<cfset subscription = createobject("java","gocardless.connect.Subscription").init(
GoCardless.accountDetails.getMerchantId(), 
javacast("bigdecimal",monthlyAmount), 
1, 
"month" 
)> 

<cfset GoCardless.connect.newSubscriptionUrl(subscription)> 

我首先想到的是,認購對象是不是正確類型newSubscriptionUrl方法,但我不認爲是這樣,因爲當我傾倒GoCardless.connect它顯示以下內容:

Dump of GoCardless.connect

這表明傳遞給newSubscriptionUrl方法的第一個參數應該是類gocardless.connect.Subscription。

當我傾倒認購對象也表明,這確實是這樣的:

Dump of GoCardless.connect

就像我說我是新來使用Java在ColdFusion,所以我真的不知道什麼可能導致這個問題以及我到目前爲止編寫的代碼是否正確。任何幫助將不勝感激。

謝謝,邁克爾。

+3

上面轉儲中的newSubscriptionUrl()方法簽名顯示它需要四個參數,一個Connection和三個字符串(redirectUri,cancelUri,state)。由於CF代碼不提供它們,你會得到上面的錯誤。 – barnyr

+0

儘管[documentation](https://gocardless.com/docs/java/merchant_client_guide#starting-the-billing-process)中的示例代碼僅顯示一個參數傳遞,我會試試這個:GoCardless.connect .newSubscriptionUrl(訂閱); – Michael

+0

事實上,文檔將其描述爲「附加參數」。 – Michael

回答

1

方法的簽名是這樣的:

newSubscriptionUrl(Subscription, String, String, String) 

然而,你在呼喚它:

newSubscriptionUrl(Subscription) 

因此,錯誤消息。您需要確保按照預期調用方法。

+0

所以我需要提供三個字符串參數,即使文檔表明這些是可選的? – Michael

+0

在Java中沒有這種東西作爲「可選」參數(無論如何都是爲了這種情況)。 CFDUMP向您展示了現實......文檔很可能已過時。 API文檔位於:http://gocardless.github.io/gocardless-java/apidocs/gocardless/connect/Connect.html。 –

+0

非常感謝,我只是嘗試了四個參數,並且這個工作。 – Michael