我在我的应用程序中使用Stripe grails plugin,我收到以下错误:
Class:groovy.lang.MissingPropertyExceptionMessage:No such property: Stripe for class: com.myApp.app.SubscriptionRequestController
这是我的行动:
def charge(String stripeToken, Double amount) {
Stripe.apiKey = grailsApplication.config.grails.plugins.stripe.secretKey
def amountInCents = (amount * 100) as Integer
def chargeParams = [
'amount': amountInCents,
'currency': 'usd',
'card': stripeToken,
'description': 'customer@sample.org'
]
def status
try {
Charge.create(chargeParams)
status = 'Your purchase was successful.'
} catch(CardException) {
status = 'There was an error processing your credit card.'
}
redirect(action: "confirmation", params: [msg: status])
return
}
自从我删除它后,我也收到了以下错误,我没有看到它,它在尝试访问或刷新任何视图时出现:
java.lang.RuntimeException: It looks like you are missing some calls to the r:layoutResources tag. After rendering your page the following have not been rendered: [head]
答案 0 :(得分:0)
就目前而言,您可能没有导入com.stripe.Stripe
类,这就是您收到该特定消息的原因。
您无需尝试手动将密钥分配给Stripe
类。只需在grails.plugins.stripe.secretKey
中定义Config.groovy
,插件即可处理其余内容,see in the plugin source。
答案 1 :(得分:0)
试试这个:
在你的主布局文件中,例如:main.gsp,在body和head中都有两个额外的。另外,手动加载stripe-v2。无需在web-app / js中添加它,因为插件本身已经拥有它。
<html>
<head>
<g:javascript src="stripe-v2.js" />
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
在config.groovy中添加:
grails.resources.modules = {
stripe {
dependsOn 'jquery'
resource url:'/js/stripe-v2.js', disposition: 'head', exclude:'minify'
}
}
示例gsp(取自文档)但我添加了付款错误,因为源使用它:
<stripe:script formName="payment-form"/>
<g:form controller="checkout" action="charge" method="POST" name="payment-form">
<div class="payment-errors"></div>
<div class="form-row">
<label>Amount (USD)</label>
<input type="text" size="20" autocomplete="off" id="amount" name="amount"/>
</div>
<stripe:creditCardInputs cssClass="form-row"/>
<button type="submit">Submit Payment</button>
</g:form>
我认为插件本身不支持当前Grails Asset Pipeline的实现。我认为它与grails 2.4.3及更高版本不兼容。