grails - 使用Grails Stripe插件

标签 grails stripe-payments grails-plugin

我在应用程序中使用Stripe grails plugin,出现以下错误:

Class:groovy.lang.MissingPropertyExceptionMessage:No such property: Stripe for class: com.myApp.app.SubscriptionRequestController

这是我的 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
}

我也收到以下错误,因为我在删除插件时安装了插件,但没有看到它,它是在尝试访问或刷新任何 View 时发生的:
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] 

最佳答案

试试这个:

在您的主布局文件(例如:main.gsp)中,在 body 和头部都添加两个。另外,手动加载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及更高版本不兼容。

关于grails - 使用Grails Stripe插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35164005/

相关文章:

grails - 列是类的排序集时的Groovy表排序

grails - 如何在Grails Controller 中获取原始二进制内容

ruby-on-rails - 如何在rails 7中使用format js?

php - 没有弹出窗口的 Stripe 支付

android - 如何知道 3D Secure for Stripe 是成功还是失败?

grails - NullPointerException:初始化bean失败

grails - 如何在智能12中定义 cucumber 的步骤定义位置

grails - Cereal ,如果值为0.0,则显示空白

grails - 解决获取依赖项的错误:找不到工件,Grails

grails - 如何在集成测试中与其余客户端共享Spring Security session