Can anyone help me. i want to integrate ccavenue in my project i used ccavenue code but i got some error "undefined method `id' for nil:NilClass" at orderID = @transaction.id.to_s.. this is my code.
In 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
In Controller -->
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
end
and action in controller -->
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
I got error in this "undefined method `id' for nil:NilClass" at orderID = @transaction.id.to_s
got help from this link -- http://dealbuddie.tumblr.com/post/56908130601/integrating-ccavenue-with-ruby-on-rails-site
please guide me how can i correct this code..
try this out:
by searching over rubytoolbox 2 gems got listed
2> ccavenue
out of these ccavenue
seems to be good, try using it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.