首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ruby中实现ccavenue

如何在ruby中实现ccavenue
EN

Stack Overflow用户
提问于 2014-05-09 19:02:56
回答 1查看 133关注 0票数 0

有人能帮我吗。我想在我的项目中集成ccavenue我使用了ccavenue代码,但在orderID =@transaction.id.to_s处得到了一些错误"undefined method ` in‘for nil:NilClass“。这是我的代码。

在application.helper中-->

代码语言:javascript
复制
 def verifyChecksum( merchantID,  orderID,  amount,  authDesc,  workingKey,  checksum) 
 String str = merchantID+"|"+orderID+"|"+amount+"|"+authDesc+"|"+workingKey
 String newChecksum = Zlib::adler32(str).to_s
 return (newChecksum.eql?(checksum)) ? true : false
 end

 def getChecksum( merchantID,  orderID,  amount,  redirectUrl,  workingKey)
 String str = merchantID + "|" + orderID + "|" + amount + "|" + redirectUrl + "|" + workingKey;
 return Zlib::adler32(str)
 end

在控制器中-->

代码语言:javascript
复制
 def index


orderID = @transaction.id.to_s

amount = @transaction.total_amount.to_s

redirectURL = "http://www.dealbuddie.com/transactions/"+@transaction.id.to_s+"/ccavenue_redirect"

checksum = getChecksum(CCAVENUE_MERCHANT_ID, orderID, amount, redirectURL, CCAVENUE_WORKING_KEY)

  @ccaRequest = 

  "Merchant_Id="+CCAVENUE_MERCHANT_ID+"&"+

  "Amount="+amount+"&"+

  "Order_Id="+orderID+"&"+

  "Redirect_Url="+redirectURL+"&"+

  "billing_cust_name="+current_user.name+"&"+

  "billing_cust_address="+@transaction.address.street_address+"&"+

  "billing_cust_country="+@transaction.address.country+"&"+

  "billing_cust_tel="+@transaction.address.cell_phone+"&"+

  "billing_cust_email="+current_user.email+"&"+

  "billing_cust_state="+@transaction.address.state+"&"+

  "delivery_cust_name="+current_user.name+"&"+

  "delivery_cust_address="+@transaction.address.street_address+"&"+

  "delivery_cust_country="+@transaction.address.country+"&"+

  "delivery_cust_state="+@transaction.address.state+"&"+

  "delivery_cust_tel="+@transaction.address.cell_phone+"&"+

  "delivery_cust_notes="+"Note"+"&"+

  "billing_cust_city="+@transaction.address.city+"&"+

  "billing_zip_code="+@transaction.address.pincode.to_s+"&"+

  "delivery_cust_city="+@transaction.address.city+"&"+

  "delivery_zip_code="+@transaction.address.pincode.to_s+"&"+

  "Checksum="+checksum.to_s

  Dir.chdir("#{RAILS_ROOT}/public/jars/") do

  @encRequest = %x[java -jar ccavutil.jar #{CCAVENUE_WORKING_KEY} "#{@ccaRequest}" enc]

end

结束

和控制器中的操作-->

代码语言:javascript
复制
 def ccavenue_redirect

@encResponse = params[:encResponse]

@checksum = false

@authDesc = false

@p = nil

@ccaResponse = nil

if (params[:encResponse])

        if @encResponse

    Dir.chdir("#{RAILS_ROOT}/public/jars/") do

           @ccaResponse = %x[java -jar ravi-ccavutil.jar #{CCAVENUE_WORKING_KEY} "#{@encResponse}" dec]

    end

    @p = Rack::Utils.parse_nested_query @ccaResponse

    if (!@p.nil? && @p["Merchant_Id"] && @p["Order_Id"] && @p["Amount"] && @p["AuthDesc"] && @p["Checksum"])

      @checksum = verifyChecksum(@p["Merchant_Id"], @p["Order_Id"], @p["Amount"], @p["AuthDesc"], CCAVENUE_WORKING_KEY, @p["Checksum"])

      @authDesc = @p["AuthDesc"].eql?("Y") ? true : false

    end

  end

  if @checksum && @authDesc 

    transaction = Transaction.find(@p["Order_Id"])

    transaction.payment_confirmed = true

    transaction.save!

    message = current_buyer.user.name + "! Thank you for your order! It will soon be at your doorsteps!" 

    redirect_to root_path, :flash => {:success => message}

  else

    if !@authDesc

      message = current_buyer.user.name + "! Your bank did not authorize the transaction. Please go to Settings > My Orders page, and click on 'Pay Now' button to finish your transaction" 

      redirect_to root_path, :flash => {:error => message}

    else

      message = current_buyer.user.name + "! Oops! There was some error in retrieving your transaction confirmation. Please drop us an email at dealbuddie@dealbuddie.com for order confirmation."

      redirect_to root_path, :flash => {:error => message}

    end

  end

else

  message = current_buyer.user.name + "! Oops! Something went wrong while processing your request. Please go to Settings > My Orders page, and click on 'Pay Now' button to finish your transaction."

  redirect_to root_path, :flash => {:success => message}

end

end

我在orderID = @transaction.id.to_s的这个“未定义的方法‘in’for nil:NilClass”中遇到错误

通过此链接获得帮助-- http://dealbuddie.tumblr.com/post/56908130601/integrating-ccavenue-with-ruby-on-rails-site

请指导我如何更正此代码..

EN

回答 1

Stack Overflow用户

发布于 2014-05-09 19:13:01

试试这个:

通过在rubytoolbox上搜索,列出了2个宝石

1> active_merchant_ccavenue

2> ccavenue

这些ccavenue看起来不错,试着用一下吧。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23562996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档