Grails Stripe 插件错误

Grails Stripe plugin error

我正在使用 Stripe plugin for Grails ,Grails version 2.5.1 i can't make any successful transaction i always get There was an error processing your credit card. as shown in the controller , i noticed that Charge method is not defined as shown in the screenshot

我尝试导入 com.stripe.Stripe 但我得到 unable to resolve class 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 = [
    '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
}

试试这个,

在构建配置中添加:

plugins {
 ...
 compile "org.grails.plugins:stripe:2.8"
 ...
}

在你的控制器中:

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
    }
}

在您的主布局文件中:

<html>
    <head>
        <g:javascript src="stripe-v2.js" />
        <r:layoutResources/>
    </head>
    <body>
        <g:layoutBody/>
        <r:layoutResources/>
    </body>
</html>

在您的信用卡表格中查看:

<!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>

在我的案例中,在同一个控制器文件夹中创建另一个视图 checkout/confirmation.gsp

<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>


       <h3>Checkout</h3>
       <p>${msg}</p>

        <p>Data: </p>
        <p>${chargeObject}</p>

    </body>
</html>

运行 grails clean 接着, 运行grails run-app

如果您需要测试示例应用程序,您可以在此处克隆我的应用程序:Sample App

我在 eclipse 中做了 "refresh dependencies",一切正常

问题是关于 Grails 2 的。5.x。该插件不适用于 Grails 3.x.x。我让它工作并发布了一个在线教程。有一个完整的、可用的 Grails 3.2.3 应用程序可供下载。它还实现了购物车。页面是:http://www.databaseapplications.com.au/stripe_payments.jsp