如何在ruby中实现ccavenue

时间:2014-05-09 11:02:56

标签: ruby-on-rails ruby

任何人都可以帮助我。我想在我的项目中集成ccavenue我使用了ccavenue代码,但是我得到了一些错误"未定义的方法`id'为零:NilClass"在orderID = @ transaction.id.to_s ..这是我的代码。

在application.helper - >

 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

在控制器中 - >

 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

和控制器中的操作 - >

 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

我在这个"未定义的方法`id'中得到错误为零:NilClass"在     orderID = @ transaction.id.to_s

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

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

1 个答案:

答案 0 :(得分:0)

试试这个:

搜索已列出的rubytoolbox 2个宝石

1> active_merchant_ccavenue

2 - ; ccavenue

这些ccavenue似乎很好,尝试使用它。