Grails Stripe插件错误 [英] Grails Stripe plugin error
本文介绍了Grails Stripe插件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
我试图导入 com.stripe.Stripe
但是我得到无法解析类com.stripe.Stripe
。
以下是动作:
def charge(String stripeToken ,Double amount){
//Stripe.apiKey = grailsApplication.config.grails.plugins.stripe.secretKey
def amountInCents =(amount * 100)as Integer
def chargeParams = [
'金额':amountInC
'currency':'usd',
'card':stripeToken,
'description':'customer@sample.org'
]
def status
try {
Charge.create(chargeParams)
status ='您的购买成功。'
} catch(CardException){
status =' '
}
redirect(action:confirmation,params:[msg:status])
return
}
解决方案
试试这个,
在build config中添加:
插件{
...
compile org.grails.plugins:stripe:2.8
...
}
在你的控制器中:
包stripesample
导入com.stripe.model.Charge
import com.stripe.exception.CardException;
$ b $ checkoutController {
def index(){}
$ b def charge(String stripeToken,Double amount){
def amountInCents = (amount * 100)as Integer
def chargeParams = [
'amount':amountInCents,
'currency':'usd',
'card':stripeToken ,
'description':'customer@sample.org'
]
def status
charge chargeStatus
try {
chargeStatus = Charge .create(chargeParams)
println chargeStatus
status ='您的购买成功。'
} catch(CardException){
println status
status ='There was an '
}
渲染视图:确认,模型:[msg:status,chargeObject:chargeStatus]
返回
}
}
在您的主布局文件中:
< html>
< head>
< g:javascript src =stripe-v2.js/>
< r:layoutResources />
< / head>
< body>
< r:layoutResources />
< / body>
< / html>
在您的信用卡表单中查看:
<!DOCTYPE html>
< html>
< head>
< meta name =layoutcontent =main/>
< / head>
< body>
< h3> Checkout< / h3>
< stripe:script formName =payment-form/>
< div class =payment-errors>< / div>
< div class =form-row>
< label>金额(美元)< / label>
< input type =textsize =20autocomplete =offid =amountname =amount/>
< / div>
< stripe:creditCardInputs cssClass =form-row/>
< button type =submit>提交付款< / button>
< / g:表格>
< / div>
< / body>
< / html>
在我的情况checkout / confirmation.gsp中创建另一个视图b
$ b
<!DOCTYPE html>
< html>
< head>
< / head>
< body>
< h3>结帐< / h3>
< p> $ {msg}< / p>
< p>资料:< / p>
< p> $ {chargeObject}< / p>
< / body>
< / html>
运行 grails clean
和然后,
运行 grails run-app
如果您需要测试示例应用程序,我的应用程序在这里:示例应用程序
i'm using
i tried to import com.stripe.Stripe
but i'm getting unable to resolve class com.stripe.Stripe
.
Here is the action:
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
}
解决方案
Try this,
In build config add:
plugins {
...
compile "org.grails.plugins:stripe:2.8"
...
}
In your controller:
package stripesample
import com.stripe.model.Charge
import com.stripe.exception.CardException;
class CheckoutController {
def index() {}
def charge(String stripeToken, Double amount) {
def amountInCents = (amount * 100) as Integer
def chargeParams = [
'amount': amountInCents,
'currency': 'usd',
'card': stripeToken,
'description': 'customer@sample.org'
]
def status
Charge chargeStatus
try {
chargeStatus = Charge.create(chargeParams)
println chargeStatus
status = 'Your purchase was successful.'
} catch(CardException) {
println status
status = 'There was an error processing your credit card.'
}
render view: "confirmation", model:[msg: status,chargeObject:chargeStatus]
return
}
}
In your main layout file:
<html>
<head>
<g:javascript src="stripe-v2.js" />
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
In your credit card form View:
<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main"/>
</head>
<body>
<h3>Checkout</h3>
<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>
</div>
</body>
</html>
Create another view in the same controller folder in my case checkout/confirmation.gsp
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3>Checkout</h3>
<p>${msg}</p>
<p>Data: </p>
<p>${chargeObject}</p>
</body>
</html>
Run grails clean
and then,
Run grails run-app
If you need to test a sample app you can clone my app here: Sample App
这篇关于Grails Stripe插件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文