ActiveMerchantでPaypalのIPNを受取る
ドキュメントに完璧なサンプルがある。
IPNの送り元確認もやってくれる
http://rubydoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/Paypal/Notification
ActiveMerchantでPaypalのExpressCheckoutをするには下記URLが参考になる
Twiwt:Blog / jugyo : Rails3 + Mongoid + ActiveMerchant で Paypal Express Checkout
サンプル
class BackendController < ApplicationController include ActiveMerchant::Billing::Integrations def paypal_ipn notify = Paypal::Notification.new(request.raw_post) order = Order.find(notify.item_id) if notify.acknowledge #ここでIPNの送り元と内容確認をしている begin if notify.complete? and order.total == notify.amount order.status = 'success' shop.ship(order) else logger.error("Failed to verify Paypal's notification, please investigate") end rescue => e order.status = 'failed' raise ensure order.save end end render :nothing end end