We're trying to get IPN working with the Paypal gem (Paypal::Notification). Everything works fine in the sandbox, but against the live site paypal returns INVALID every time for acknowledge.
Here is the code:
def ipn
# Create a notify object we must
notify = Paypal::Notification.new(request.raw_post)
logger.info "ORDER_CREATE:RAW_REQUEST #{request.raw_post}"
# Duplicate the params hash and remove items not in Order object
temp_hash = params.clone
temp_order = Order.new
temp_hash.delete_if{|key, value| !temp_order.attributes.include?(key)}
temp_hash.delete_if{|key, value| key == 'updated_at'}
temp_hash.delete_if{|key, value| key == 'created_at'}
# Create the order object
@order = Order.new(temp_hash)
logger.info "ORDER_CREATE:IPN_REQUESTED: #{@order.inspect}"
# We must make sure this transaction id is not allready completed
if Order.exists?({:txn_id => @order.txn_id,:payer_id => @order.payer_id,:txn_type => @order.txn_type})
logger.info "ORDER_CREATE:EXISTS_IN_DB: #{@order.inspect}"
render :nothing => true
return
end
# Acknowledge and confirm this was a valid notify request
if 1 #notify.acknowledge
logger.info "ORDER_CREATE:ACKNOWLEDGED: #{@order.inspect}"
begin
# successful transaction to add to the db
if notify.complete?
logger.info "ORDER_CREATE:COMPLETED: #{@order.inspect}"
@order.save
logger.info "ORDER_CREATE:SAVED: #{@order.inspect}"
Mailer.deliver_purchase(@order)
else
logger.info "ORDER_CREATE:ERROR1: #{@order.inspect}"
end
rescue => e
logger.info "ORDER_CREATE:ERROR2 (#{e.message}): #{@order.inspect}"
end
else # transaction was not acknowledged
logger.info "ORDER_CREATE:ERROR3: #{@order.inspect} #{notify.inspect}"
end
render :nothing => true
end
Every time the IPN fails with "ERROR3". When i look at the logs and compare the notify object's @raw value the string is identical to request.raw_post. So it should be sending back the identical string.
Any ideas?